-
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
feat: Keep (Parent Route) Query Parameters #749
base: main
Are you sure you want to change the base?
Conversation
|
I think in order to make it more predictable:
link.url => the mode will choose which The mode can't change because if the getter for url consume tracked state because for example you change from known to tracked-known the link, it will now foreever be autotracked because tracked state was consumed |
I'm not sure if I fully understand what you are doing 🙈 but from what I grasp is to make a link that changes its query params, based on some tracked properties. If so, that's what resources are for, no? Here is an example: import { resource, resourceFactory } from 'ember-resources';
import { Link, link } from 'ember-link';
const LinkWithMode = resourceFactory((link, mode) => {
return resource(({ owner }) => {
Object.defineProperty(link, 'url', {
get() {
switch (mode) {
// your logic here
}
}
}
return link;
});
});
<template>
{{#let (LinkWithMode (link "...") "your-mode") as |link|}}
<a href={{link.url}}>...</a>
{{/let}}
</template> Overwriting the What might be an alternative idea is to use a link builder as in #669 - or a combination of that: import { resource, resourceFactory } from 'ember-resources';
import { Link, link } from 'ember-link';
const LinkWithMode = resourceFactory((buildLink, params, mode) => {
return resource(({ owner }) => {
const router = owner.lookup('service:router');
// find qp from parent
switch (mode) {
// filter qp here and modify params (or make new ones)
}
return buildLink(params);
});
});
<template>
{{#let (LinkWithMode (link "...") "your-mode") as |link|}}
<a href={{link.url}}>...</a>
{{/let}}
</template> // Update: I've only ever seen the linked issue afterwards @buschtoens any idea to make it part of |
Sorry @gossi for the missing context, the issue described by buschtoens might better solve your questions #476 We need the
I like the resource and composition approach and it could work too, but IMHO I think the primitive itself should be able to and normal getters could do it. Also theres a demo on the dummy app. Thanks for reviewing, I gladly to implement changes or rewrites |
I found the context later 🙈 I'm never using QPs, because they are deadly to me, so I avoid them 😂 I see the original issue is by @buschtoens itself. We were chatting on how to evolve ember-link into v3. As we want to remove I don't wanna make a say whether this should be part of ember-link or userland, I'll leave this to @buschtoens as he was knows the history of this package and it was his original idea. I can say, if this will go into ember-link, I'm trying to fix CI over at #761 and this would be targeting v3, configured under |
As Jan didn't respond here. The idea is this:
|
Perfect @gossi we are already using it in prod, I will find some time this weekend to rebase, polish and add tests, I do think it's probably best if it's an internal thing. My only doubts are around the private apis it uses. But I think(?) they are safe for now. |
Which APIs are you using? Might make sense to check their stability and consider making them public and adding your idea to the contributions section of the guides |
This PR implements #476
Still needs tests, but wanted to get an opinion, thanks.