-
Notifications
You must be signed in to change notification settings - Fork 159
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
All transitions are now async #19
Conversation
handler.deserialize(handlerInfo.params, providedContext, resolvedContexts) | ||
).then(function(context) { | ||
|
||
contextResolvedImmediately = true; |
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.
this should likely be named contextHasFulfilled
❤️ |
Thanks @machty for this awesome improvement! |
Hi, I've made some major updates to this PR, mostly to define the beforeModel/model/afterModel hooks here (rather than the original plan of preserving while bloating It's still not pull-ready. Here's a TODO:
|
I think this is a step toward loading partial applications <3 |
@rpflorence c señor. |
@machty you are doing god's work |
Here's a nice state of the union API usage gist for how to handler some (presently) challenging async use cases: https://gist.github.com/machty/5647589 Please, everyone who cares about this, have a look and let me know if there's anything about the above gist that looks awkward that could be fixed/improved about this API. We don't need to fit every last thing in Ember Core; this gist is just to outline some ideas about possible approaches. |
I will look at those changes closer more thoroughly tomorrow, but one thing that I wanted to note is that |
@drogus you have to change the App.LoadingRoute = Ember.Route.extend({
renderTemplate: function() {
this.render('loading');
}
}); But this will generate other problem, give a look in that jsfiddle. |
Hi, progress: http://jsbin.com/axarop/2/edit This is the latest router.js as included in Ember. Haven't pushed this code you but you can start trying out the new API. |
@marcioj ah, yes, of course it should be |
Does |
@jamesarosen Nothing's changing about the API in that sense, so, same as before, |
I must have gotten a little confused reading the source. https://github.com/tildeio/router.js/blob/master/lib/router.js#L216-L229 suggests that if On the other hand, https://github.com/tildeio/router.js/blob/master/lib/router.js#L418 shows that |
@jamesarosen welcome to the world of inconsistency that is present router.js. This PR makes it so that both transitionTo and URL transitions will pause for promises and pass the resolved context to |
Hi, made another update. (Excuse the broken build for now, just a minor thing from a rebase). Check out this gist for the latest. |
Is this PR likely to be merged before Ember 1.0 final is released? |
Yes, probably rc6 On Sat, Jun 1, 2013 at 8:35 PM, Joel Moss notifications@github.com
|
confirmed, it will, at least in one form or another. |
OK! I am happy with it. Ready to merge when yall are. Speak now or forever hold your peace. |
👍 |
If I were to use |
@KidkArolis you're totally right, I completely forgot to rewrite the README, will do so soon. But yes this will be in the next version. |
One thing I've noticed so far is that, because it's heavily promisified now, it's hard to know when a 'programmer error' happend somewhere in the handler. I can see the errors if I turn the logging on, but sometimes you don't want to see detailed logging, however you always (in dev) want to see things like To sum up, I might be wrong, but I think this promise heavy code might lead to a lot of silent errors (thinks like undefined functions, type errors, etc.) that Ember developers will stop seeing, which might lead to a lot of frustration, so might be worth investigating. Perhaps it could be as simple as having a flag to |
@KidkArolis this is a problem we are aware and we're working at some better patterns for making things as transparent as possible. In the Ember world, we have a default error handler installed on the root route that spits out an error, but even then the stack is already lost at that point. So, anyway, there's lots of improvements to be made along the lines you're suggesting, but for now the need for some cohesive, consistent, and reliable patterns when it comes to routing outweighs the present difficulties with debugging, which we're pretty certain will become less and less problematic over time. |
One more question, sorry for the noise. At the moment, it's not possible to abort/pause a transition from within an active state which is about to be exited, is that correct? It could be quite easily added by passing the transition into a The usecase is displaying a modal asking the user if he really wants to navigate away from the page, etc. |
Ah! Read your gist and saw the Question though, do you think it should call Also if a handler prevents the transition in |
May I ask, what's the reason for splitting deserialize into beforeModel/model/afterModel? It seems like it would be pretty easy for ember to split out the hooks into whatever it needs. Those 3 methods are not really doing anything different functionally (in some sense). At least in my case, I'm not using the 'model' hook for loading model per say as it's used in Ember, I rather create a State object in there (which is kind of a model), but deserialize sounded .. more abstract, and this model concept leaks a bit of ember into the router. Just something that crossed my mind. |
@KidkArolis Yes, use the Events won't bubble unless you explicitly return It's split into 3 because |
Thanks for the clarifications! This library is amazing, especially the new version with transitions. Using it in a Backbone atm - I'm finding this state machine approach to be a very good way to structure the app, very glad you guys have extracted the router into a microlib. |
@KidkArolis pretty cool. That sounds like a great blog post in the making, please keep us in the loop. |
API: https://gist.github.com/machty/5723945 Examples (might have some examples from previous iterations): https://gist.github.com/machty/5647589
All transitions are now async
o_0) |
This is the Ember side of tildeio/router.js#19 All set, just keep in mind that there is probably more discussion to be had over the `beforeModel` and `afterModel` hook names, which might change before RC6.
Please refer to https://gist.github.com/machty/5723945 for a description of the API