ember-href-to
ember-href-to copied to clipboard
[WIP] Preserve queryParams
So far I've proven that this is doable by using the -routing service and observing changes in the state of that service.
Questions to be answered:
- That service is not yet public. Ask the oracle (@rwjblue) wether or not this is a terrible practice
- Measure performance penalty. If this brings this addon in the like of performance with a regular
{{link-to}}that would defeat the purpose of using it.
@GavinJoyce May I take some advice on how to measure the perf of this change? I imagine that setting an observer won't affect performance that much (although all helpers will recompute when qps change while now it doesn't, but that is a bug to me)
@cibernox I just manually copy some code into a custom benchmark in a throwaway ember-performance branch and compare the results. I'm happy to do this later this evening if you want?
Thanks for doing this, this is a nasty bug and it's great that it'll be fixed
@GavinJoyce That would be great. That said, don't merge it yet. I need to test more edge cases.
- Transition from
/foo/bar?one=1&two=2with{{href-to 'foo.qux'}}, whereoneis a qp that belongs tofooandtwois a qp that belongs tobarbut not toqux. Expected:one=1is preserved,two=2dissapears. - Transition from
/foo/bar?one=1&two=2with{{href-to 'foo.qux'}}, whereoneis a qp that belongs tofooandtwois a qp that belongs tobarandqux. Expected: Both remain. - Transition from
/foo/bar?one=1&two=2with{{href-to 'foo.qux'}}, whereoneandtwoare qps that belongs tofoo. Expected: Both remain. - Transition from
/foo/bar?one=1&two=2with{{href-to 'foo.qux'}}, whereoneandtwoare qps that belongs tobarandqux. Expected: Unsure. - Transition from
/foo/bar?one=1&two=2with{{href-to 'another'}}, whereoneandtwoare qps that belongs tofooandanother. Expected: None is preserved (I think).
@cibernox I didn't manage to get benchmark data, I was planning to modify https://github.com/GavinJoyce/ember-performance/pull/1 but ember-performance has changed significantly since then.
onQpsChange: Em.observer('_routing.currentState', function() {
this.recompute();
}),
This seems like it will be expensive on any route transition, every href-to will recompute. I wonder can we only recompute if a query param has changed? Or, perhaps we could skip the recompute if there are no query params?
I've been able to create a couple more complex scenarios that still fail. Over the weekend I'll try to figure out how to better do this.
I've also seen on the core notes that they agreed to proceed with your url-for RFC, so I might ping someone to give some guidance on this.
I was experimenting with this because I need it on my own project. Few observations:
- observer on
_routing.currentStatefires even thoughrouterJsState.fullQueryParamsdid not change. I've fixed it with my proxyroutingservice that abstractscurrentQueryParamsaway. fullQueryParamssometimes contained old value so I'm usingrouterJsState.queryParamsinstead. Not sure what's the difference between those two.- It only makes sense to preserve query params that belong to parent route handlers of the route being passed to href-to.
- I'd maybe rather opt-in into this feature on every {{href-to}} than have it on by default because of performance penalty on route switching. On my (highly specific) use case this performance penalty is significant.
Is it worth investigating this with the new public router service?
@scalvert I believe it's not. I mean, its probably worth pursuing, but the approach would be totally different from different. Tests seem valuable tho