src/index.js
function triggerPromise() {
        var me = this;
        var args = arguments;

        var canHandlePromise =
            this.children.indexOf("completed") >= 0 &&
            this.children.indexOf("failed") >= 0;

        var createdPromise = new PromiseFactory(function(resolve, reject) {
            // If `listenAndPromise` is listening
            // patch `promise` w/ context-loaded resolve/reject
            if (me.willCallPromise) {
                _.nextTick(function() {
                    var previousPromise = me.promise;
                    me.promise = function (inputPromise) {
                        inputPromise.then(resolve, reject);
                        // Back to your regularly schedule programming.
                        me.promise = previousPromise;
                        return me.promise.apply(me, arguments);
                    };
                    me.trigger.apply(me, args);
                });
                return;
            }

            if (canHandlePromise) {
                var removeSuccess = me.completed.listen(function () {
                    var args = Array.prototype.slice.call(arguments);
                    removeSuccess();
                    removeFailed();
                    resolve(args.length > 1 ? args : args[0]);
                });

                var removeFailed = me.failed.listen(function () {
                    var args = Array.prototype.slice.call(arguments);
                    removeSuccess();
                    removeFailed();
                    reject(args.length > 1 ? args : args[0]);
                });
            }

            _.nextTick(function () {
                me.trigger.apply(me, args);
            });

            if (!canHandlePromise) {
                resolve();
            }
        });

        // Ensure that the promise does trigger "Uncaught (in promise)" errors in console if no error handler is added
        // See: https://github.com/reflux/reflux-promise/issues/4
        createdPromise.catch(function() {});

        return createdPromise;
    }
function triggerPromise() {
        var me = this;
        var args = arguments;

        var canHandlePromise =
            this.children.indexOf("completed") >= 0 &&
            this.children.indexOf("failed") >= 0;

        var createdPromise = new PromiseFactory(function(resolve, reject) {
            // If `listenAndPromise` is listening
            // patch `promise` w/ context-loaded resolve/reject
            if (me.willCallPromise) {
                _.nextTick(function() {
                    var previousPromise = me.promise;
                    me.promise = function (inputPromise) {
                        inputPromise.then(resolve, reject);
                        // Back to your regularly schedule programming.
                        me.promise = previousPromise;
                        return me.promise.apply(me, arguments);
                    };
                    me.trigger.apply(me, args);
                });
                return;
            }

            if (canHandlePromise) {
                var removeSuccess = me.completed.listen(function () {
                    var args = Array.prototype.slice.call(arguments);
                    removeSuccess();
                    removeFailed();
                    resolve(args.length > 1 ? args : args[0]);
                });

                var removeFailed = me.failed.listen(function () {
                    var args = Array.prototype.slice.call(arguments);
                    removeSuccess();
                    removeFailed();
                    reject(args.length > 1 ? args : args[0]);
                });
            }

            _.nextTick(function () {
                me.trigger.apply(me, args);
            });

            if (!canHandlePromise) {
                resolve();
            }
        });

        // Ensure that the promise does trigger "Uncaught (in promise)" errors in console if no error handler is added
        // See: https://github.com/reflux/reflux-promise/issues/4
        createdPromise.catch(function() {});

        return createdPromise;
    }
function triggerPromise ( ) { var me = this ; var args = arguments ; var canHandlePromise = this . children . indexOf ( "completed" ) >= 0 && this . children . indexOf ( "failed" ) >= 0 ; var createdPromise = new PromiseFactory ( function ( resolve , reject ) { // If `listenAndPromise` is listening // patch `promise` w/ context-loaded resolve/reject if ( me . willCallPromise ) { _ . nextTick ( function ( ) { var previousPromise = me . promise ; me . promise = function ( inputPromise ) { inputPromise . then ( resolve , reject ) ; // Back to your regularly schedule programming. me . promise = previousPromise ; return me . promise . apply ( me , arguments ) ; } ; me . trigger . apply ( me , args ) ; } ) ; return ; } if ( canHandlePromise ) { var removeSuccess = me . completed . listen ( function ( ) { var args = Array . prototype . slice . call ( arguments ) ; removeSuccess ( ) ; removeFailed ( ) ; resolve ( args . length > 1 ? args : args [ 0 ] ) ; } ) ; var removeFailed = me . failed . listen ( function ( ) { var args = Array . prototype . slice . call ( arguments ) ; removeSuccess ( ) ; removeFailed ( ) ; reject ( args . length > 1 ? args : args [ 0 ] ) ; } ) ; } _ . nextTick ( function ( ) { me . trigger . apply ( me , args ) ; } ) ; if ( ! canHandlePromise ) { resolve ( ) ; } } ) ; // Ensure that the promise does trigger "Uncaught (in promise)" errors in console if no error handler is added // See: https://github.com/reflux/reflux-promise/issues/4 createdPromise . catch ( function ( ) { } ) ; return createdPromise ; }
Returns a Promise for the triggered action

@return {Promise}
Resolved by completed child action.
Rejected by failed child action.
If listenAndPromise'd, then promise associated to this trigger.
Otherwise, the promise is for next child action completion.
Returns a Promise for the triggered action