Skip to content

Instantly share code, notes, and snippets.

@ishiduca
Created March 27, 2015 09:52
Show Gist options
  • Save ishiduca/f86ffe863eef8bfaba99 to your computer and use it in GitHub Desktop.
Save ishiduca/f86ffe863eef8bfaba99 to your computer and use it in GitHub Desktop.
flux dispatcher
'use strict'
var dispatcher = module.exports = new (require('flux').Dispatcher)
var dispatch = dispatcher.dispatch
var register = dispatcher.register
dispatcher.dispatch = function (actionType, value) {
var payload = {actionType: actionType}
if ('undefined' !== typeof value) payload.value = value
return dispatch.apply(this, [payload])
}
dispatcher.register = function (f) {
return register.apply(this, [function (payload) {
return f(payload.actionType, payload.value)
}])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment