-
Notifications
You must be signed in to change notification settings - Fork 329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
listenAndPromise doesn't return data? #352
Comments
Can't really help you with this one here, it's likely not even a Reflux usage issue. Please refer to help channels for this topic: For questions please use the following communication channels:
Please only use the issue tracker for bugs and feature requests only. |
I've asked the question on StackOverflow here. I don't really get why this issue was closed. How is what I've described not a bug? |
because you have code errors. (You're not doing anything with the promise.) |
Yeah I don't know what you mean by 'You're not doing anything with the promise'. It's being returned from listenAndPromise as documented in the ReadMe.
Which is what I'm doing here. The 'completed' listener fires with
The following works as expected. The 'completed' listener is called with the loaded data:
My understanding of the docs is that the two snippets above should give the same result but they don't. |
Maybe a bug? |
My fetch function looks something like this: fetch(id, params) {
let method = 'GET';
let url = getUrl(id, params);
return sync(url, {method, body: params})
.then(Actions.fetch.completed)
.catch(Actions.fetch.failed);
}, This calls I ended up just calling // in store
Actions.fetch().then((resp) => { ... }) // works
this.fetch().then((resp) => { ... }) // doesn't (resp is undefined) |
If it's any help I can get
So it seems reflux doesn't work with Qwest's promise implementation when used with |
I've looked into this, and despite my initial thoughts that caused me to close this, I've now determined that this is actually not a bug, because I'm not sure it can be fixed. This is actually a design flaw that is creating a race condition. I started to answer @willdady's SO question, and realized that my answer was actually a "non-answer", so I thought I'd bring it back to this issue. ExplanationIn the example given I think that's what @willdady intended, but I think where the "flaw" comes in, is how the async action handler works for the reflux completed child action shortcut. The shortcut will call the completed handler The problem is that the reference of
Since In this case, the It's all very "inception"-ish, and I recommend some sort of adult beverage to ease the brain pain when you walk through this. @willdady I'm sorry I didn't give this question the respect it deserved on the first go-around. @spoike I have some thoughts on this, and I think they directly relate to our most recent roadmap discussion. I think the shortcuts will wind up being deprecated, and the listen/promise might be handled slightly differently. Going to tag this as 0.3.0. |
If I'm reading this correctly, I believe I'm having the same issue in a different place. As of Here's my code... // ClipActions.js
const ClipActions = Reflux.createActions({
load: {asyncResult: true}
});
ClipActions.load.listenAndPromise(recordId =>
request.get(`/records/${recordId}/clips`)
.type('application/json')
.then(res => res.body)
.catch(err => {
AlertActions.error(err.message, err.res.text);
throw err;
})
);
// ClipActions_test.js
it('should load clips', () => {
let response = [{}, {}];
let request = API
.get(`/records/5/clips`)
.reply(200, response);
return ClipActions.load(5)
.then(data => {
expect(data).to.deep.equal(response);
request.done();
});
}); With With
|
@spoike here's that explanation I was searching for. (see my comment above) |
I've been meaning to move this issue to reflux-promise, since reflux and reflux-core doesn't have the promises in it's API any longer. |
The problem I described though, has nothing to do with promises, it has to do with reflux-core and the design of action handlers. |
@H3Chief I was mostly referring to @jfairley's comment and the actual facing issue which is a bug that should be adressed in reflux-promise. The child actions issue should be worked on as well, and if that means changing the Reflux interface a bit, then that is okay with me as long as we follow semantic versioning for breaking changes. |
FYI, we recently upgraded to reflux-core:0.3.0 and reflux-promise:1.0.1, and actions again return promises. This is true for To illustrate (snipped down for brevity): actions: PlayerActions.updateClip.listen(detail => {
try {
// ... do stuff
PlayerActions.updateClip.completed();
} catch (err) {
PlayerActions.updateClip.failed(err);
}
});
PlayerActions.checkHls.listenAndPromise(srcPath => request.get(srcPath).then(res => res.body)); tests it('should ...', () => {
return PlayerActions.updateClip({ ... })
.then(res => {
expect( ... ).to.equal( ... );
});
});
it('should ...', () => {
return PlayerActions.checkHls('http://...')
.then(res => {
expect(res).to.deep.equal({ ... });
});
}); |
Any official word on this? My impression is that this works, but it's unclear given the changelogs, etc. |
I'm just a little confused about using promises with reflux. I'm using qwest to query my endpoint as shown below, the onGetResourceCompleted handler fires as expected but data is undefined. Why is that?
I can see the data loads correctly by looking at dev tools as well as calling qwest in isolation by simply doing:
The text was updated successfully, but these errors were encountered: