Allow multiple calls to App.Router.map#2485
Conversation
There was a problem hiding this comment.
Some quick comments: These lines seem mis-indented, and perhaps you should add a comment why there is a .hasOwnProperty('length') check?
There was a problem hiding this comment.
Oops! It looked perfect in Vim. I can fix that. As for the hasOwnProperty call, its my paranoia in a world without type safety. I like to make sure the this.router_map_callbacks is in fact method compatible with an array.
|
Do you want to use |
|
@joliss Thanks, I just rewound, amended, and force pushed. |
|
Okay, I've added some more comments. I hope you don't mind my nitpicking. It looks almost ready to merge. |
|
FYI, my comments ended up on the commit page at DynamiX-Web-Design@704ad67 o_o |
|
Ah, now you have two commits. Want to squash and repush again? Other than that, looks good to merge to me! 👍 |
|
@joliss yeah, noticed the two commits :( I've literally been trying to figure out how to squash them since I pushed the first time. My gitfu is not strong, but I think it's good to go now Thanks for all your help :) |
|
Here is a gist that does this in userland https://gist.github.com/grep-awesome/5406461 |
|
Cool. Good to merge from my end. 👍 |
There was a problem hiding this comment.
nitpick, but this should probably be indented by 4 spaces.
There was a problem hiding this comment.
Roger that, indenting.
|
Can you explain how |
…imes without the map being overwritten. Allows routes to be added at runtime. One test with multiple cases also added.
|
@machty: when I run this in my head, when I instantiate a new copy of |
|
@grep-awesome @trek The async router PR shouldn't affect this. I'm still a bit torn, but perhaps we should just merge this for now and come up with a better solution now. I understand how this PR works, but it still seems like an avoidable hack. We shouldn't be constructing/destroying/recreating the backbone of every Ember app for an action that should merely augment the router's state, and not just for perf/GC reasons. Not that this is the use case you had an mind for this PR, but this might cause some nasty surprises once someone tries to run a second But I understand that's not the use case of this PR. I guess I'm ok with merging it, since the implications are not far-reaching for this PR and if/when we want to support calling |
|
@machty I'm glad to hear that you are good to merge, however I also agree with your reservations. It is somewhat of a hack, but as you have said, there are some conceptual problems with supporting dynamically loading routes mid-app that are well outside the scope of this request. My goal here was to provide a light touch solution to a need without altering logic at a level that might be foundational to ember's philosophy. |
|
|
There was a problem hiding this comment.
@machty Unless I'm misunderstanding you, I've already changed the behavior here to not discard the Router instance. We are still regenerating the DSL though, is this what you are asking me to defer?
Apologies for the confusion, I'm in #emberjs if a direct chat resolves this more easily
|
Oh crap, I'm a dummy. I think this PR is good to merge :) |
|
this does not rebase cleanly |
|
@stefanpenner I'll squash, rebase, and push around 2100UTC. Thanks! |
|
@stefanpenner I see the conflict and even was able to merge it here: https://gist.github.com/grep-awesome/bffdf7b8b6112cf0aa57, but I have no idea how to make this happen correctly in git for my pull request. Any pointers would be most welcome, otherwise I'll have to dig into git docs and irc tomorrow for help. |
|
@grep-awesome git fetch and a rebase against origin master didn't work? Make sure you are fetching the correct remote repo. If by tomorrow evening you where unable to resolve this I will gladly doit. |
I've found a need to be able to add new routes at runtime (one of my apps allows plugins). Upon looking through docs and API, I couldn't find a way to do this so I went to source and still didn't find anything.
Attached is code that allows you to call
App.Router.mapmultiple times without overwriting the previous behavior.I've written two tests for it because the change is minor. I'm happy to write additional tests or receive guidance from the team.