-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[added] Router.AsyncState mixin #125
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
Conversation
what a nice treat to my inbox before going to bed! |
* declare a static `getInitialAsyncState` method that fetches state | ||
* for a component after it mounts. This function is given three | ||
* arguments: 1) the current route params, 2) the current query and | ||
* 3) a function that can be used to set state as it is received. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should probably note here that state will be automatically set to the resolved value, calling setState
is just for additional state related to the async operation.
The separate setState function weirds me out a bit. I wonder if we can get by without it. |
expect(user.state.delayedValue).toEqual('delayed'); | ||
expect(user.state.promisedValue).toEqual('promised'); | ||
done(); | ||
}, 20); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, maybe we should bring in sinon or something else to fake timers (later, this is fine).
@spicyj how else would you handle the streaming use-case? (But yeah, it is a little weird.) |
@rpflorence You wouldn't be able to, but is that common? I can't recall a time I've wanted to do that, and it seems to me that it might be easily confused with |
I have wanted to be able to update the progress of a long xhr call in ember's router and couldn't, and I know @mjackson has this exact need (streaming) in something he's working on. |
If only we had Observable in JS… (https://docs.google.com/file/d/0B4PVbLpUIdzoMDR5dWstRllXblU/edit?pli=1). I don't have any better ideas right now for the streaming use case. |
@spicyj lets just not talk about it much, and if anybody gets a better idea we'll implement it quickly. I'd rather have something weird than nothing at all. I might even do |
@spicyj If it makes you feel any better, the |
Anyway, I anticipate that the most common usage will be to just return a hash. This looks exactly like getInitialAsyncState: function (params, query) {
return {
user: getUser(params.userID)
};
} |
Updated the docs according to @rpflorence feedback and rebased. Let me know if there are any other concerns. |
This is fantastic. Can you smell v1.0? |
:) Please feel free to click the merge button. Yeah, 1.0 is just around the corner! |
[added] Router.AsyncState mixin
This is just a start on the work needed to eventually support server-side rendering (see #57). The other things needed are:
renderRoutesToString(routes, path)
methodRoute
(or aRouteHandler
mixin, see Make Route more extensible #65)Ideally we can merge these pieces one at a time and make a release when they're all ready.