-
-
Notifications
You must be signed in to change notification settings - Fork 405
Deprecate <LinkTo> Component Positional Arguments
#698
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,178 @@ | ||
| --- | ||
| Stage: Accepted | ||
| Start Date: 2021-01-05 | ||
| Release Date: Unreleased | ||
| Release Versions: | ||
| ember-source: vX.Y.Z | ||
| ember-data: vX.Y.Z | ||
| Relevant Team(s): Ember.js | ||
| RFC PR: https://github.com/emberjs/rfcs/pull/698 | ||
| --- | ||
|
|
||
| <!--- | ||
| Directions for above: | ||
|
|
||
| Stage: Leave as is | ||
| Start Date: Fill in with today's date, YYYY-MM-DD | ||
| Release Date: Leave as is | ||
| Release Versions: Leave as is | ||
| Relevant Team(s): Fill this in with the [team(s)](README.md#relevant-teams) to which this RFC applies | ||
| RFC PR: Fill this in with the URL for the Proposal RFC PR | ||
| --> | ||
|
|
||
| # Deprecate <LinkTo> Component Positional Arguments | ||
|
|
||
| ## Summary | ||
|
|
||
| We propose to deprecate invoking the `<LinkTo>` component with positional | ||
| arguments, in favor of the equivalent named arguments introduced in | ||
| [RFC #459](0459-angle-bracket-built-in-components.md). We also propose to | ||
| deprecate the `(query-params)` helper, which is only needed when invoking the | ||
| `<LinkTo>` component with positional arguments. | ||
|
|
||
| ## Motivation | ||
|
|
||
| In modern Ember, the idiomatic way to invoke most components is to use the | ||
| [angle bracket syntax](0311-angle-bracket-invocation.md) along with the named | ||
| arguments `@` syntax. On the other hand, curly invocations are now reserved for | ||
| "helper-like" and "control-flow" components. | ||
|
|
||
| The `<LinkTo>` built-in component started life as a "helper" in the early days | ||
| of Ember, even before an official components API was created. Over time, it | ||
| became clear that `<LinkTo>` is better classified as a component than a helper | ||
| in modern Ember, and the learning materials have been updated accordingly. | ||
|
|
||
| This historical origin meant that `<LinkTo>` was designed to accept positional | ||
| arguments exclusively, as was common with most helpers at the time. The angle | ||
| bracket syntax, on the other hand, accepts named arguments exclusively. | ||
|
|
||
| Another downside to the positional arguments syntax was it required the use of | ||
| the `(query-params)` helper to distinguish query params from model arguments. | ||
|
|
||
| Finally, the meaning of the positional arugments also changes slightly when the | ||
| component is invoked with or without a block, which made things needlessly | ||
| confusing. | ||
|
|
||
| To address these issues, [RFC #459](0459-angle-bracket-built-in-components.md) | ||
| introduced explicit equivalent names for the positional arguments that were | ||
| accepted by the `<LinkTo>` component. This allowed it to be invoked with the | ||
| same angle bracket syntax and avoided the other confusions mentioned above. | ||
|
|
||
| These features were made available since v3.10 and are the idomatic thing to do | ||
| in modern Ember codebase. | ||
|
|
||
| Given that the feature are now available on all currently-supported Ember | ||
| versions and the community had adequate time to make the transition, this would | ||
| be a good time to deprecate the obsolete features to reduce confusion as well | ||
| as implementation complexity. | ||
|
|
||
| In particular, some of the obsolete features required capabilities not usually | ||
| available to other components, such as knowing whether a block was passed or | ||
| not and relies on "AST transforms" to normalize some of the differences. These | ||
| implementation strategies introduces unnecessary complexity in the internals | ||
| that sometimes causes bugs or other surprising behaviors. | ||
|
|
||
| ## Transition Path | ||
|
|
||
| ```hbs | ||
| Deprecated: | ||
|
|
||
| {{link-to "About Us" "about"}} | ||
| ~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| Invoking the `<LinkTo>` component with positional arguments is deprecated. | ||
| Instead, please use the equivalent named arguments (`@route`) and pass a | ||
| block for the link's content. | ||
|
|
||
| <LinkTo @route="about">About Us</LinkTo> | ||
| ``` | ||
|
|
||
| ```hbs | ||
| Deprecated: | ||
|
|
||
| {{#link-to "about"}}About Us{{/link-to}} | ||
| ~~~~~~~ | ||
|
|
||
| Invoking the `<LinkTo>` component with positional arguments is deprecated. | ||
| Instead, please use the equivalent named arguments (`@route`). | ||
|
|
||
| Replacement: | ||
|
|
||
| <LinkTo @route="about">About Us</LinkTo> | ||
| ``` | ||
|
|
||
|
|
||
| ```hbs | ||
| Deprecated: | ||
|
|
||
| {{#link-to "post" @post}}Read {{@post.title}}...{{/link-to}} | ||
| ~~~~~~~~~~~~ | ||
|
|
||
| Invoking the `<LinkTo>` component with positional arguments is deprecated. | ||
| Instead, please use the equivalent named arguments (`@route`, `@model`). | ||
|
|
||
| Replacement: | ||
|
|
||
| <LinkTo @route="post" @model={{@post}}>Read {{@post.title}}...</LinkTo> | ||
| ``` | ||
|
|
||
| ```hbs | ||
| Deprecated: | ||
|
|
||
| {{#link-to "post.comment" @comment.post @comment}} | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| Comment by {{@comment.author.name}} on {{@comment.date}} | ||
| {{/link-to}} | ||
|
|
||
| Invoking the `<LinkTo>` component with positional arguments is deprecated. | ||
| Instead, please use the equivalent named arguments (`@route`, `@models`). | ||
|
|
||
| Replacement: | ||
|
|
||
| <LinkTo @route="post.comment" @models={{array post comment}}> | ||
| Comment by {{comment.author.name}} on {{comment.date}} | ||
| </LinkTo> | ||
| ``` | ||
|
|
||
| ```hbs | ||
| Deprecated: | ||
|
|
||
| {{#link-to "posts" (query-params direction="desc" showArchived=false)}} | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| Recent Posts | ||
| {{/link-to}} | ||
|
|
||
| Invoking the `<LinkTo>` component with positional arguments is deprecated. | ||
| Instead, please use the equivalent named arguments (`@route`, `@query`) and the | ||
| `hash` helper. | ||
|
|
||
| Replacement: | ||
|
|
||
| <LinkTo @route="posts" @query={{hash direction="desc" showArchived=false}}> | ||
| Recent Posts | ||
| </LinkTo> | ||
| ``` | ||
|
|
||
| These migrations can be automated using the [angle brackets codemod](https://github.com/ember-codemods/ember-angle-brackets-codemod). | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is great! |
||
|
|
||
| ## How We Teach This | ||
|
|
||
| The Octane learning materials have already been updated to use the latest | ||
| idioms, so no changes are necessary. The API documentation should be updated | ||
| to mark the obsolete features and the `(query-params)` helper as deprecated. | ||
|
|
||
| A deprecation guide will need to be written using the same examples from the | ||
| [Transition Path](#transition-path) section. The guide should also promote the | ||
| use of the codemod to automate the migration. | ||
|
|
||
| ## Drawbacks | ||
|
|
||
| None. | ||
|
|
||
| ## Alternatives | ||
|
|
||
| None. | ||
|
|
||
| ## Unresolved questions | ||
|
|
||
| None. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back 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.
https://guides.emberjs.com/release/routing/linking-between-routes/#toc_the-linkto--component
Do we want to reference any links for future readers or are they at risk to change?
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 including the link here so people reviewing the PR can find them. That said, there are also other places, such as the tutorial. This is meant to include all of these so I don't think we need to link from the RFC text itself.