reflux / reflux-core

A simple core library for uni-directional dataflow application architecture inspired by ReactJS Flux
BSD 3-Clause "New" or "Revised" License
48 stars 19 forks source link

Refux will not use promises when the browser doesn't support them even when externally supplied. #3

Closed VanTanev closed 9 years ago

VanTanev commented 9 years ago

Hey, currently _.environment.hasPromise is used to determine if Reflux should trigger an action as a promise, or as an async (ref). This however only depends on an initial check of the environment done here: https://github.com/reflux/reflux-core/blob/b291e3dbf897dd61cbc90fdfb377d46f6a6e5a2c/src/utils.js#L27

This means that even if we provided another promise implementation to Reflux through Reflux.setPromise(require('bluebird')), Reflux would not trigger promises, because we cannot influence the _.environment.hasPromise variable.

We need to either be able to influence this variable, or it needs to be automatically set to true when an external promise lib is set in https://github.com/reflux/reflux-core/blob/b291e3dbf897dd61cbc90fdfb377d46f6a6e5a2c/src/index.js#L74-L88

spoike commented 9 years ago

Sorry about this. A workaround is that the variable should be available at Reflux.utils.environment.hasPromise.

abraxas commented 9 years ago

This workaround doesn't seem to work for me in node.js on some OS's. Feels like at least anything with "setPromise" explicitly used (as in the docs) should work, even if it's failing to detect promises in other ways.

I did find a workaround that works, but it's terribly evil.

 global.Promise = require('bluebird')

at the very beginning of my app worked, even where

Reflux.utils.environment.hasPromise = true

failed when run on every line.

spoike commented 9 years ago

Yes @abraxas, you need to polyfill Promises in NodeJS (i.e. in server-side). This is because Node does not have Promises implemented yet IIRC.