-
Notifications
You must be signed in to change notification settings - Fork 12
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
Currying Links ? #669
Comments
I think overall this is a great and useful suggestion. I can definitely see myself wanting to use such a feature in some situations. Thank you. But I fear the proposed mechanics won't work reliably: Issues with Models / Dynamic Segments
While the latter is a valid Additionally, there may be routes accepting more than one model, e.g. Naïve SolutionOne option is to naïvely append models from left to right: {{#let (link "user.address" "buschtoens") as |baseLink|}}
{{#let (link baseLink "home") as |finalLink|}}
<a href={{finalLink.url}}>Home</a>
{{/let}}
{{#let (link baseLink "work") as |finalLink|}}
<a href={{finalLink.url}}>Work</a>
{{/let}}
{{/let}} In this case But what if you need Issues with Query ParamsFor query params it's not as bad, because they are named instead of positional. However, that introduces a second problem: Wrapping invocations may unintentionally override query params that were set in the base invocation. This can lead to bugs. But in a different scenario, this behavior may be desirable. Intermittent SolutionI think we need to bikeshed this a bit more and consider various use cases. For the time being, you could easily achieve this with a custom (inline) helper. It even gives you maximum control over how arguments are applied. import { helper } from '@ember/helper';
import { inject as service, Registry as Services } from '@ember/service';
import Component from '@glimmer/component';
export default class MyComponent extends Component {
@service('link-manager')
private declare linkManager: Services['link-manager'];
readonly buildDetailsLink = helper((id: string) => this.createUILink({
route: 'go-to-details',
models: [id]
});
} <MyPage @detailsLink={{this.buildDetailsLink}} /> <a href={{get (@detailsLink this.model.id) "url"}}>...</a> Using import { inject as service, Registry as Services } from '@ember/service';
import Component from '@glimmer/component';
export default class MyComponent extends Component {
@service('link-manager')
private declare linkManager: Services['link-manager'];
buildDetailsLink(id: string) {
return this.createUILink({
route: 'go-to-details',
models: [id]
});
}
} Potential
|
Aaaah, thanks for highlighting that currying cannot always work. It was just my initial case in which it worked. However, really like the idea for the factory method (esp. with ember-functions-as-helper-polyfill). Let's do this 💪 |
So, let's say this setup:
As routes are the connectivity layer - they have knowledge about route names but at route level the information about what parameters to be put in are not directly present.
FWIW is to curry links. Ie. the route passes in the link/name of the route and the component curries it with the parameters. I assume something like this code:
Now, this example looks like as if it is enough to pass in the route name, but also on route level you shall be able to pass generic parameters in as well, so within the component it is only to "finalize" the link.
thoughts?
The text was updated successfully, but these errors were encountered: