-
-
Notifications
You must be signed in to change notification settings - Fork 408
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
Router link component and routing helpers #339
Router link component and routing helpers #339
Conversation
FWIW, this is what ember-router-helpers was aiming to implement (though I did a very poor job on the README so who would ever know 😝 ). |
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.
Thanks for putting the RFC together! I personally think that we should separate adding named arguments to link-to
from adding the other router based helpers.
Also, the Router Service RFC specifically mentions a number of the helpers you have proposed...
text/0000-router-link-and-helpers.md
Outdated
Inspiration for helpers implementation could come from https://github.com/BBVAEngineering/ember-route-helpers | ||
|
||
Components to be implemented: | ||
- `Link` |
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.
I believe that we can be more iterative here, and add the following named arguments to the existing link-to
:
- route (the route to link to)
- models (an array of model / primitive ids / etc)
This would make transforming existing {{link-to}}
usages very easy, and still largely satisfy (what I thought) was the main concern: desire to use the newer angle bracket invocation style.
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.
desire to use the newer angle bracket invocation style was my original concern. but I couldn't come with up with named argument for link-to
that didn't feel awkward, or implicitly imply functionality that might not be there, such as would be the case with {{link-to route=''}}
(what else could we link to?)
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.
Ha! I was actually thinking exactly the opposite. <Link
seems like it should manage all links, not just ones within the routing structure.
Also, I think there is value in iterating forward within the component we all know / love / hate / etc. Adding a couple of named arguments to {{link-to}}
seems like it would unlock using angle bracket invocation and be a fairly small change/tweak to the internal code.
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.
lol, guess the only way forward is with the smallest amount of changes. I'm totes good with named args in linked to. :)
less change = less potential for confusion
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.
I would be 👍for making LinkTo
work with named attrs and even named models.
I actually looked at this when I was first playing with components.
With a router.js (ignore that the route inheritance wouldn't really make sense
this.route('profile', { path: '/:userId' }, function() {
this.route('friend', { path: '/friend/:friendId' })
})
My ideal LinkTo
invocation would be
<LinkTo @routeName="profile.friend" @models={{hash userId=model.user.id friendId=friend.id}}>Some Test</LinkTo>
I think this could actually be done completely backwards compatible while allowing positional params too (with deprecation later).
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.
ooo, @rtablada I like that
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.
The names are a bit different and I would need to ask someone a bit more knowledgeable with the router to make named @model
hash work but here's a proof of concept of the changes needed to make params or named attributes work:
rtablada/link-to-params@5236ac5
The links I tested this with are:
<LinkTo @params={{array "foo" 1 2}}>Positional Params</LinkTo>
<LinkTo @targetRouteName="foo" @models={{array 1 2}}>Named Params</LinkTo>
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, we'd probably want to alias targetRouteName
to something shorter for the public api, yeah?
I'm glad what you have is so simple though!
I think naming it |
I would rather see |
So, how about this: Phase 1:
Phase 2:
Question: RouterLink vs Link? (personally, I favor Phase 3:
|
@NullVoxPopuli I haven't read the full RFC yet (I will). One issue that immediately comes to mind is this discussion: #275 This addon is related to the aforementioned RFC: (perhaps the content of those two links can be helpful in some what, when iterating on this proposal) |
@NullVoxPopuli @params might leak internal component implementation and I don’t think we could use that attribute name for a long time as Ember component uses @params for positional params. Maybe I’m missing something but after adding named args, why would we need to make a completely different component with different attribute names? Seems counter intuitive? At best renaming to the Router namespace. |
I really like idea of a My comment is more of an open question—could we use this as an opportunity to also address the beginner bear trap of passing a model versus an id ie whether or not the model hook gets fired on the route? I feel like this might be a good moment to see if there is a way to reduce the potential confusion, though I don't feel confident proposing a solution myself. |
I think if the params/model argument has a hash, it could help? having only positional args really confused me when I was first learning ember. I think being able to specify id or model by convention might be the way to go: <Link @to='posts.edit' @params={{hash user=userModel postId=4}}>
Edit {{userModel.name}}'s 4th post
</Link> I know @rtablada said |
Definitely. I think that using the convention of Whether or not that would completely resolve the issue I don't know, but my feeling is that it would be a big help in clarifying the two different use cases. |
I wonder if there's anything we can borrow from |
If we can do
why can't we do
the |
If that works out, since |
@gossi first this is ember internal so it could use private API. But I think its even possible with public API.
However then we need a way to pass it to the
while this could be useful as public API it could kept private and only used by the could it maybe also be a good idea to expose a And one last thing, maybe it should be specified what should happen if the user does |
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.
Some higher-level thoughts!
text/0000-router-link-and-helpers.md
Outdated
|
||
## Detailed design | ||
|
||
#### tl;dr: |
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.
You went from an H2 to an H4 here.
I would suggest dropping this title, however, and writing a small intro explaining your rationale regarding splitting the work into phases, and why each specific phase.
text/0000-router-link-and-helpers.md
Outdated
|
||
## Motivation | ||
|
||
Currently, on ember#canary, the Angle Bracket Invocation feature doesn't support positional arguments. For clarity, and with some inspiration from react-router, It may be beneficial for Ember to include a `Link` component, similar to the existing `LinkTo` (`link-to`), but with only named arguments. This will help with clarity of intent, and also allow for easier transitioning from other communities who already have named-argument links. |
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.
Positional arguments are not planned for angle bracket invocations, I suggest updating this sentence to remove any "but in the future it might" implicit suggestion.
text/0000-router-link-and-helpers.md
Outdated
|
||
The goal of `Link` and the route helpers is to provide a flexible way of routing from the template while providing a sample component with sensible defaults. This would achieve the exact same functionality as `LinkTo`, so `LinkTo` would no longer be needed and could eventually be removed. | ||
|
||
It's possible we could write a codemod to auto-convert everyone's non-angle-bracket invocation of `{{#link-to ...` to the new angle bracket component: `Link` |
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 feels more of an open question than a detailed design, due to the uncertainty of the proposal.
text/0000-router-link-and-helpers.md
Outdated
|
||
We'll want to make it very clear that the traditional `LinkTo` technique of linking will still be available, but will eventually be deprecated. | ||
|
||
The documentation and guides would need to be incrementally upgraded to inform people about the new linking strategy -- but becaus the old way would still work, having some docs say `LinkTo` instead of `Link` wouldn't be the worst thing. |
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.
Typo in "becaus"
text/0000-router-link-and-helpers.md
Outdated
|
||
There are two alternatives: | ||
|
||
1. Do nothing: |
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.
I'm thinking we should skip including this, because that is the alternative for every RFC, and the body of the RFC is an active argumentation against doing nothing.
Why bother adding the named params to link-to, if we're immediately afterwards going to add a new component to supersede it? It seems like unnecessary work - just introduce the new component and deprecate the old one. |
@courajs I'd be a fan of this. If other people are, I'll remove those relevant parts of the RFC. :) |
Updated. Also started some work over here: adopted-ember-addons/ember-router-helpers#46 |
Things that seem to be missing:
|
@buschtoens thanks for bringing those up! Those lend themselves nicely to named arguments :) |
text/0000-router-link-and-helpers.md
Outdated
|
||
The goal of `Link` and the route helpers is to provide a flexible way of routing from the template while providing a sample component with sensible defaults. This would achieve the exact same functionality as `LinkTo`, so `LinkTo` would no longer be needed and could eventually be removed. | ||
**Deprecation** `link-to` aka `link-to` |
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.
that doesn't make sense anymore
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.
I edited too quickly. lol
I saw, you changed some of the |
@gossi I think that makes sense -- I'll revert to is-route-active :) |
@buschtoens (I'll add |
@buschtoens, @gossi: updated |
Just to clarify any misunderstanding: I think we also need a |
thanks @luxferresum I'll get that added! :) The goal of this RFC is to have equivalent capabilities from |
I made <Link
@route="some.route"
@models={{array 123}}
@query={{hash foo="bar"}}
as |l|>
<a
href={{l.href}}
class={{if l.isActive "is-active"}}
{{on "click" l.transitionTo}}
>
Click me
</a>
</Link> |
examples: | ||
|
||
```hbs | ||
<button {{action (transition to='posts.edit' postId=post.id)}} /> |
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 is an accessibility red flag to me, links should be links. While the transition
helper probably has value in other places I'd like to see an example that doesn't just turn a button into a styled link.
Superseded by (at the time of writing) to-be-implemented functionality described by https://github.com/emberjs/rfcs/blob/master/text/0391-router-helpers.md#event-dispatcher which would be much more ergonomic |
my first RFC!
rendered