Mailspring/internal_packages/inbox-activity-bar/lib/activity-bar-store.coffee
Ben Gotow dc59b876d3 fix(streaming) Use thread/draft version #'s to prevent bad updates
Summary:
fix(http): Support http for API in addition to https throughout

test(attributes): Additional testing for model attributes

fix(versioning): Use version numbers with drafts as well as threads

Test Plan: Run tests

Reviewers: evan

Reviewed By: evan

Differential Revision: https://review.inboxapp.com/D1194
2015-02-16 17:22:29 -08:00

56 lines
1.5 KiB
CoffeeScript

Reflux = require 'reflux'
{Actions} = require 'inbox-exports'
qs = require 'querystring'
ActivityBarStore = Reflux.createStore
init: ->
@_setStoreDefaults()
@_registerListeners()
########### PUBLIC #####################################################
curlHistory: -> @_curlHistory
expandedSection: -> @_section
longPollState: -> @_longPollState
########### PRIVATE ####################################################
_setStoreDefaults: ->
@_curlHistory = []
@_minified = true
@_longPollState = 'Unknown'
_registerListeners: ->
@listenTo Actions.didMakeAPIRequest, @_onAPIRequest
@listenTo Actions.developerPanelSelectSection, @_onSelectSection
@listenTo Actions.longPollStateChanged, @_onLongPollStateChange
_onSelectSection: (section) ->
@_section = section
@trigger(@)
_onLongPollStateChange: (state) ->
@_longPollState = state
@trigger(@)
_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 =
command: "curl -X #{request.method} #{data} #{url}"
statusCode: response?.statusCode || 0
@_curlHistory.unshift(item)
@trigger(@)
module.exports = ActivityBarStore