Skip to content

Changing top level dynamic segments while preserving others - #39

Closed
kellyselden wants to merge 1 commit into
emberjs:masterfrom
kellyselden:transition-to-any-dynamic-segment
Closed

kellyselden wants to merge 1 commit into
emberjs:masterfrom
kellyselden:transition-to-any-dynamic-segment

Conversation

@kellyselden

Copy link
Copy Markdown
Member

RFC

@davewasmer

Copy link
Copy Markdown
Contributor

Would changing a top level dynamic segment cause all the child routes to refire their model hooks, as if you had directly transitioned to that leaf route?

@kellyselden

Copy link
Copy Markdown
Member Author

I'm not sure. Perhaps if possible not refire the model hooks of unchanged segments. I'm not familiar with the complexities of the router.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line should probably be something like this.transitionTo('locale.product.item', {, right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right. Although I would assume a resource reset after locale. How about this.transitionTo('product.item', {?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I think i was thinking that this was a nav component action that would be handled by the locale or application route. So in that case, currentRouteName was assumed to be always calculated.

The following example this.transitionTo('item', { was "I want to look at this same item in a different product's context", so the route would be static.

@ef4

ef4 commented Jun 7, 2015

Copy link
Copy Markdown
Contributor

This was reviewed by the core team today.

When the child routes are data-dependent on the parent route, this new option creates a footgun. It is incorrect to try to swap the parent route's value without rerunning all the children.

When the child routes are not data-dependent on the parent route, we consider it a bug that any expensive rerendering is done, and we think Glimmer plus the ongoing routable component work should address those bugs.

We agree that there is still a need for a public API that makes it easier to transition to the existing URL with only one segment changed, and would welcome suggestions for that API. Most likely it should go on the routing service.

@SaladFork

Copy link
Copy Markdown

We agree that there is still a need for a public API that makes it easier to transition to the existing URL with only one segment changed, and would welcome suggestions for that API. Most likely it should go on the routing service.

@ef4: A suggestion to that effect:

Today through Ember.Route#paramsFor a route can get at the parameters of any route (including itself). What if this or a similar mechanism could be used for changing a parameter too?

One idea for implementation: the current paramsFor returns a POJO whose keys are dynamic segment names merged with query parameter names. What if instead of returning a POJO, an Ember.Object was returned instead to facilitate data binding / observation.

Example usage:

this.paramsFor('locale').set('locale', 'en-gb');
this.paramsFor('products').set('product_id', 2);

This approach averts the concern @igorT raised in the issue by requiring the route name be specified in addition to, but separately from, the segment/parameter name.

Drawbacks:

  • Not obvious from seeing a .set that it will result in a transition.
  • Potentially no longer being able to assume you can read values off the returned value (which was a POJO, now Ember.Object) without using Ember.get.

(edited to remove statement about Ember.Route#paramsFor being private, as it no longer is)

@dschmidt

dschmidt commented Jul 3, 2015

Copy link
Copy Markdown
Contributor

Can't Route.serialize() be used for swapping out parameters? It could be called after the model resolved or Route.reserialize() could be manually triggered similar to how recompute() works in the new Helper API.

That's a very natural approach to correcting typos in urls - e.g. wrong casing of usernames - this would even work automatically.
It would also be very easy to swap out parameters on every level with this - it just needs an action that changes a property on a model on the right level and then calls reserialize() (or an observer that does it automatically when the property changes).

The downside is that you can't generate a proper link to a different locale, just something that triggers an action...

@wagenet

wagenet commented Jul 23, 2022

Copy link
Copy Markdown
Member

Given the seven(!) years of inactivity on this issue I think it's fair to close it. The last relevant state was the core teams conclusion:

We agree that there is still a need for a public API that makes it easier to transition to the existing URL with only one segment changed, and would welcome suggestions for that API. Most likely it should go on the routing service.

If someone wants to make an RFC for this specific part then I believe that would still be welcome.

@wagenet wagenet closed this Jul 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants