este.Dispatcher
Isomorphic Facebook Flux like dispatcher with promises support. Made with Este.js.
Features
- Promises move dispatcher to the next level. All app sync/async actions and errors can be orchestrated across all app layers easily.
- App errors can be reported via provided
onError
hook. - Isomorphic, Bower and Node.js versions included.
- Bower version for production is super small, only 2.7 kB (gzipped). Yes, Closure Compiler.
Install
For Bower.
bower install steida/este-dispatcher --save
For Node.js.
npm install este-dispatcher --save
Usage
For Bower.
// Dev
<script src="bower_components/este-dispatcher/dispatcher.js"></script>
// Production
<script src="bower_components/este-dispatcher/dispatcher.min.js"></script>
For Node.js.
var Dispatcher = require('este-dispatcher');
API
register
/**
@param {Function} callback
@return {number} ID of registered callback.
*/
register(callback)
unregister
/**
@param {number} id ID of registered callback.
*/
unregister(id)
onError
/**
For error reporting.
@param {string} action
@param {*} reason
*/
onError(action, reason)
dispatch
/**
@param {string} action
@param {Object=} payload Data for action.
@return {!goog.Promise}
*/
dispatch(action, payload)
waitFor
/**
@param {Array.<number>} ids Callbacks IDs.
@return {!goog.Promise}
*/
waitFor(ids)