mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-12 12:40:08 +08:00
3ba6c7c59a
Summary: Debounce changes out of the DatabaseStore to prevent lots of calls to persistModel from flooding the app Tasks must always call super so they get IDs The task queue shouldn't save every time it adds/removes a task - there could be hundreds ActivityBar package is actually surprisingly slow, re-rendering needlessly setState in MultiselectList sometimes renders immediately. Don't do this, because sometimes we're rendering twice back to back Remove dead references Never allow duplicate tags in the tags array Don't archive threads that already have the archive tag (it doesn't do anything bad, but why bother creating tasks?) Update DB specs Test Plan: Run tests Reviewers: evan Reviewed By: evan Differential Revision: https://review.inboxapp.com/D1506
90 lines
2.4 KiB
CoffeeScript
90 lines
2.4 KiB
CoffeeScript
Reflux = require 'reflux'
|
|
{Actions} = require 'inbox-exports'
|
|
qs = require 'querystring'
|
|
_ = require 'underscore-plus'
|
|
|
|
curlItemId = 0
|
|
|
|
ActivityBarStore = Reflux.createStore
|
|
init: ->
|
|
@_setStoreDefaults()
|
|
@_registerListeners()
|
|
|
|
|
|
########### PUBLIC #####################################################
|
|
|
|
curlHistory: -> @_curlHistory
|
|
|
|
longPollState: -> @_longPollState
|
|
|
|
longPollHistory: -> @_longPollHistory
|
|
|
|
visible: -> @_visible
|
|
|
|
########### PRIVATE ####################################################
|
|
|
|
triggerThrottled: ->
|
|
@_triggerThrottled ?= _.throttle(@trigger, 100)
|
|
@_triggerThrottled()
|
|
|
|
_setStoreDefaults: ->
|
|
@_curlHistory = []
|
|
@_longPollHistory = []
|
|
@_longPollState = 'Unknown'
|
|
@_visible = atom.inDevMode()
|
|
|
|
_registerListeners: ->
|
|
@listenTo Actions.didMakeAPIRequest, @_onAPIRequest
|
|
@listenTo Actions.longPollReceivedRawDeltas, @_onLongPollDeltas
|
|
@listenTo Actions.longPollStateChanged, @_onLongPollStateChange
|
|
@listenTo Actions.clearDeveloperConsole, @_onClear
|
|
@listenTo Actions.showDeveloperConsole, @_onShow
|
|
@listenTo Actions.logout, @_onClear
|
|
|
|
_onShow: ->
|
|
@_visible = true
|
|
@trigger(@)
|
|
|
|
_onClear: ->
|
|
@_curlHistory = []
|
|
@_longPollHistory = []
|
|
@trigger(@)
|
|
|
|
_onLongPollDeltas: (deltas) ->
|
|
# Add a local timestamp to deltas so we can display it
|
|
now = new Date()
|
|
delta.timestamp = now for delta in deltas
|
|
|
|
# Incoming deltas are [oldest...newest]. Append them to the beginning
|
|
# of our internal history which is [newest...oldest]
|
|
@_longPollHistory.unshift(deltas.reverse()...)
|
|
if @_longPollHistory.length > 1000
|
|
@_longPollHistory.splice(1000, @_longPollHistory.length - 1000)
|
|
@triggerThrottled(@)
|
|
|
|
_onLongPollStateChange: (state) ->
|
|
@_longPollState = state
|
|
@triggerThrottled(@)
|
|
|
|
_onAPIRequest: ({request, response}) ->
|
|
url = request.url
|
|
if request.auth
|
|
url = url.replace('://', "://#{request.auth.user}:#{request.auth.pass}@")
|
|
if request.qs
|
|
url += "?#{qs.stringify(request.qs)}"
|
|
postBody = ""
|
|
postBody = JSON.stringify(request.body).replace(/'/g, '\\u0027') if request.body
|
|
data = ""
|
|
data = "-d '#{postBody}'" unless request.method == 'GET'
|
|
|
|
item =
|
|
id: curlItemId
|
|
command: "curl -X #{request.method} #{data} #{url}"
|
|
statusCode: response?.statusCode || 0
|
|
|
|
@_curlHistory.unshift(item)
|
|
curlItemId += 1
|
|
|
|
@triggerThrottled(@)
|
|
|
|
module.exports = ActivityBarStore
|