reflux / reflux-promise Goto Github PK
View Code? Open in Web Editor NEWPlugin for reflux/reflux-core that extends PublisherMethods with Promise helpers
License: BSD 3-Clause "New" or "Revised" License
Plugin for reflux/reflux-core that extends PublisherMethods with Promise helpers
License: BSD 3-Clause "New" or "Revised" License
Reading the source code, I can see that including this library overrides reflux-core's triggerAsync
with reflux-promise's triggerPromise
.
However, at least when using window.Promise
, the executor function passed to the Promise constructor executes immediately, before the constructor returns the created object (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
So that means the following code is executing immediately when an action is triggered async:
me.trigger.apply(me, args);
https://github.com/reflux/reflux-promise/blob/master/src/index.js#L55
This is causing issues when upgrading Reflux on my project because I have code that depends on actions executing on the "next tick". For example, calling an action in componentWillMount
, which causes my store to trigger synchronously, but doesn't update the component because Reflux.connect attaches the listener in componentDidMount
.
Reported by @ponelat in reflux/refluxjs#416
When I have a triggerPromise... I only receive the first argument in
then
clause.var someAction = Reflux.createAction({asyncResult: true}); someAction.listen(function(a,b,c) { someAction.completed(a + '-eh', b + '-eh', c + '-eh') }) someAction.triggerPromise(a,b,c) .then(function(d,e,f) { // Assume d,e,f are passed into console.log(d,e,f) // <- Only d is defined }) .catch(function() {})I've looked into the source and I'm not sure why this is assumed to be an array of args?... https://github.com/reflux/reflux-core/blob/master/src/PublisherMethods.js#L159
Could be a bug, or it might be me. I can PR if I get some time, but otherwise help is always appreciated!
Maybe I didn't understand the purpose of this lib, but I think there is something wrong in the way it manages Promises.
When an action is triggered, the returned Promise object should be resolved or *rejected" according to the outcome of the triggered action.
The point is that RefluxPromise completly ignores Promised objects returned by an action handler. Instead, it creates its own Promise which is resolved / rejected whenever the completed
/ failed
methods of the action are called. At anytime.
In otherwords, when an action is called, it does not return a promise of the outcome of this action, but a promise of the outcome of any similar action.
For instance...
I'm using a Reflux store to persist changes on DB using a REST service. If the service fails (for whatever reason), I want to know which action couldn't make it. That's why I wanted to used Promises.
So I would like to do the following:
var actions = {
'change': Reflux.createAction({ asyncResult: true })
};
Reflux.createStore({
listenables: actions,
onChange: function(data) {
return RestPromises.jsonPost('/my_service', data)
},
})
changePromise = actions.change({foo: 'bar'});
But it doesn't work ! changePromise
is not the Promise returned by jsonPost
, but a Promise created by Reflux-Promise which is actually always resolved.
So I had to do the following instead:
var actions = {
'change': Reflux.createAction({ asyncResult: true })
};
Reflux.createStore({
listenables: actions,
onChange: function(data) {
return RestPromises.jsonPost('/my_service', data)
.then(function () {
actions.change.completed();
})
.catch(function (error) {
actions.change.failed(error);
});
},
})
But then, when I trigger the same action 2 times...
changePromise_1 = actions.change({foo: 'good'});
changePromise_2 = actions.change('bad');
... they will get the same outcome, and will be both rejected or resolved ! Obviously this is not a desired behavior.
NPM registry URL: http://registry.npmjs.org/reflux-promise/-/reflux-promise-1.0.2.tgz
The index.js
in this package doesn't contain the changes from commit 6d14b9d which were committed just before the 1.0.2 version bump in commit 6213844.
I recently updated all the packages in a project and now I'm getting a lot of long noisy warnings from Bluebird:
"Warning: a promise was created in a handler but was not returned from it"
at triggerPromise from Object.functor (stack dump meaningless because it's a browserified bundle)
The Bluebird docs state that if you want to do this intentionally without a warning, you have to return a value (such as null) from the parent. Any chance of implementing this behavior? The only option for a consumer is to disable such warnings globally, and for obvious reasons that's undesirable.
In my React app, I set Reflux to use reflux-promise with browser's Promise implementation just before ReactDOM.render
. But still, in my action files, it throws the error:
Uncaught TypeError: ConnectionActions.create.listenAndPromise is not a function
support.jsx
.....
fetchData = () => {
var params = {
'internshipbuffer':this.state.buffer_id
}
supportAction.getMessage(params).then(this.updateData)
}
.....
supportAction.jsx
import Reflux from 'reflux'
import supportResource from '../resources/supportResource'
var actions = Reflux.createActions({
'getMessage': {
children: ['completed', 'failed']
}
});
actions.getMessage.listenAndPromise(supportResource.getMessage(params));
export default actions;
supportResource.jsx
import Api from '../util/api'
var supportResource = {
getMessage(params) {
return Api.get('/internshipbuffer/getChat', params);
}
}
export default supportResource;
I am getting an error in supportAction.jsx :-
params is not defined
How to pass params to the resource ?
If i don't pass params i am getting undefined response
Originally posted by @liady reflux/refluxjs#403 Moved to here since promises have been extracted out of reflux-core and is now in reflux-promise.
Lately I started getting
Uncaught (in promise) some-error
errors in my console whenever an action failed.
I researched a bit and found out that Reflux creates a promise every time an action is triggered, and if the action fails, the promise rejects and there is no one to catch it. I boiled it down to:// create an action with completed/failed children var action = Reflux.createAction({asyncResult:true}); // *** First scenario - throws error *** // // invoke the action action(); // somewhere the action has failed action.failed("some reason"); // throws an error in the console - why?? // *** Second scenario - ok *** // // invoke the action, but with a catch clause action().catch(function(){}); // somewhere the action has failed action.failed("some reason 2"); // this is now ok...Seems like every action trigger creates a promise, and that causes this issue when the action fails. I would imagine this would happen only when calling
action.triggerPromise
explicitly, and not every time.Currently I have to attach a
catch
clause to every action trigger in my code to fix this problem. I want my components to just call the actions, not handle their outcome. Is there a way to avoid it? Am I missing something here?
when i debugged in IE10,got the “window.Promise” undefined error in the following statement
Reflux.use(RefluxPromise(window.Promise))
Due to a change of priorities and busy work days I have to do what most OSS projects do and seek for active maintainers that can bring the project forward and get the ball rolling for more helpful features to be released.
As much as I'd like to put my heart and mind into reflux, there simply is no time for me to do so. However it'd be a shame for me to put this project on indefinite limbo for several reasons:
If you have and like to spend some time working on developing reflux and managing the community on github further, let me know on e-mail (check my profile) and we'll take it from there. Contributors who have done PR in the reflux projects are preferred.
This is not ideal.
I understand it was an irritation when failed actions propagated to the console as errors. But I feel this is worse.
if I have ....
onSomeActionCompleted() {
throw new Error("hello?")
}
execution just stops. No errors appear in the console.
Is there perhaps a way to configure reflux ( or reflux-promise ) to handle the promise in a more explicit manner?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.