-
Notifications
You must be signed in to change notification settings - Fork 76
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
Fetch object and async operations #131
Comments
hey, this is an interesting case. Fetch results & when are designed for handling rendering state in components and the various states it's in. So right now this is what you'd have to write var listener = AuthStore.addChangeListener(getCredentials);
getCredentials();
function getCredentials() {
var credentials = AuthStore.getCredentials();
if (!credentials.pending) {
listener.dispose();
}
if (credentials.failed) {
transition.redirect('/login');
} else if (credentials.done) {
handler();
}
} That said I'm wondering if there's a case for turning fetch results into promises for the times when you want state outside of stores var credentials = AuthStore.getCredentials().toPromise();
credentals.then(function () {
}).catch(function (error) {
}); |
TBH
In regards to rendering in a component, make It's frustrating to have promises through the entire stack until I get to actually receiving my data from the store and then losing all advantages of asynchronous operations while still having to deal with a psuedo-promise. |
Then again it would probably make more sense to have the promise be the method rather than changing fetch behavior to prevent breaking changes. With promise functionality you'd be able to use marty's conveneient api features throughout the entire app instead of just renderig components 👍 |
I'd advise against dealing with asynchronicity in your component, they make your components overly complicated & difficult to test. Was main reason behind the fetch API |
I agree with you on keeping asynchronicity out of components, I hadn't thought that through completely. Thanks for starting work on this already too! 👍 Is there anything I can do to help? RE: 9119b47 Have you considered building the promise into |
Nothing right now thanks but looking for people to test v0.9 when its ready (week or two). I don't want to encourage people to stick callbacks into their components so would like to keep fetch result's and promises separate for now |
This is now in the v0.9 branch |
How am I supposed to handle scenarios where part of my app needs a Promise but I want to use data in my stores?
Example:
During react-router's transition hook I want to determine if my user has credentials set (like in my last issue). The
fetch
object seems to me to be synchronous and usingwhen
only gets me the first status returned -- which is alwayspending
.This always returns
pending
. I can't use a promise like in the example from react-router's docs.Furthermore if in a React component I only care about rendering once fetch is done I still have to write out all the handlers for
when
. Is this the only way to deal withfetch
or am I missing something?The text was updated successfully, but these errors were encountered: