reflux / refluxjs

A simple library for uni-directional dataflow application architecture with React extensions inspired by Flux
BSD 3-Clause "New" or "Revised" License
5.36k stars 330 forks source link

triggerPromise fails when in node < 0.12 aka when you don't have native promises #412

Closed bpeters closed 9 years ago

bpeters commented 9 years ago

Currently triggerPromise won't return a promise because the check for promises in reflux-core relies on having a native promise.

if (environment.hasPromise) {
    exports.Promise = Promise;
    exports.createPromise = function (resolver) {
        return new exports.Promise(resolver);
    };
} else {
    exports.Promise = null;
    exports.createPromise = function () {};
}

I tried to set the Promise library before calling actions: Reflux.setPromise(require('RSVP'));

However, when Reflux is instantiated the createPromise is set and can't be changed, which triggerPromise relies on.

I was able to patch it by setting createPromise specifically.

var Reflux = require('reflux');
var RSVP = require('RSVP');

Reflux.utils.createPromise = function (resolver) {
  return new RSVP.Promise(resolver);
};

It works but seems like monkey-patching. I can submit a PR that updates createPromise when setPromise is called and add some tests.

Thanks!

spoike commented 9 years ago

Yes, this is an issue with reflux-core.

Related issues: reflux/reflux-core#3 and reflux/reflux-core#6

Please do submit a patch when you can. My time is a bit limited unfortunately for these fixes at the moment, so I'll be thankful for anything.

LongLiveCHIEF commented 9 years ago

Likewise. I won't be able to get back on the hose until early October.

bpeters commented 9 years ago

@spoike @LongLiveCHIEF Okay, will do!

spoike commented 9 years ago

Promises have been moved to the reflux/reflux-promise project.