reflux-promise1.0.4 • Public • Published
Plugin for reflux-core to use Promises.
Here are the API docs for reflux-promise.
You can currently install the package as an npm package.
The following command installs
reflux-promise as an npm package:
npm install reflux-promise
To install promise functionality do the following in your application's bootstrapper:
;;// Uses the user agent's Promise implementationReflux;// Uses Q;Reflux;// Uses bluebird;Reflux
Extensions to Asynchronous actions
reflux-promise extends asynchronous actions, i.e.:
// this creates 'load', 'load.completed' and 'load.failed'var load = Reflux;
A couple of helper methods are available to trigger the
failed child actions:
The following are all equivalent:
// Using load above with a promise here called "apiPromise"load;// Can be shortened down to use `promise` like belowload;// Furthermore with `listenAndPromise`load;
Asynchronous actions as Promises
PublisherMethods#triggerAsync is modified so that asynchronous actions can be used as promises. The following example is for server-side rendering when you must await the successful (or failed) completion of an action before rendering. Suppose you had an action,
makeGetRequest, and a store,
RequestStore, to make an API request:
// Create async action with `completed` & `failed` childrenvar makeGetRequest = Reflux;var RequestStore = Reflux;
You could use promises to make the request and either render or serve an error:
List of contributors is available on Github.
This project is licensed under BSD 3-Clause License. Copyright (c) 2014, Mikael Brassman.
For more information about the license for this particular project read the LICENSE.md file.