Plugin for reflux/reflux-core that extends PublisherMethods with Promise helpers
Switch branches/tags
Clone or download
devinivy Merge pull request #22 from semikolon/patch-1
code spelling mistake in readme
Latest commit fa0633e Aug 7, 2016


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:

import Reflux from "reflux";
import RefluxPromise from "reflux-promise";

// Uses the user agent's Promise implementation

// Uses Q
import Q from "q";

// Uses bluebird
import bluebird from "bluebird";

Extensions to Asynchronous actions

reflux-promise extends asynchronous actions, i.e.:

// this creates 'load', 'load.completed' and 'load.failed'
var { load } = Reflux.createActions({
    "load": {children: ["completed","failed"]}

A couple of helper methods are available to trigger the completed and failed child actions:

  • promise

  • listenAndPromise

The following are all equivalent:

// Using load above with a promise here called "apiPromise"
load.listen( function(arguments) {

// Can be shortened down to use `promise` like below
load.listen( function(arguments) {
    load.promise( apiPromise(arguments) );

// Furthermore with `listenAndPromise`
load.listenAndPromise( apiPromise );

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` children
var makeGetRequest = Reflux.createAction({ asyncResult: true });

var RequestStore = Reflux.createStore({
    init: function() {
        this.listenTo(makeGetRequest, 'onMakeGetRequest');

    onMakeGetRequest: function(url) {
        // Assume `request` is some HTTP library (e.g. superagent)
        request.get(url, function(err, res) {
            if (err) {
                return makeGetRequest.failed(err);

You could use promises to make the request and either render or serve an error:

makeGetRequest.triggerAsync('/api/something').then(function(body) {
    // Render the response body
}).catch(function(err) {
    // Handle the API error object


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 file.