Query Params as derived data#712
Conversation
Co-authored-by: Alex Raputa <alexraputa@users.noreply.github.com>
Co-authored-by: Alex Raputa <alexraputa@users.noreply.github.com>
Co-authored-by: Jarek Radosz <jradosz@gmail.com>
Co-authored-by: Alex Raputa <alexraputa@users.noreply.github.com>
| export default class ArticlesController extends Controller { | ||
| @service router; | ||
|
|
||
| queryParams = ['category']; |
There was a problem hiding this comment.
I like this direction. Do you consider how query params are declared in scope for this RFC?
There was a problem hiding this comment.
Maybe discussing them is -- as it's def part of the learning story! :)
I also don't think query params should have default values (especially since that state is entangled with the controller).
For the URL to be the source of truth, to access a QP from within a component would require something like this:
get category() {
return this.router.currentRoute.queryParams.category ?? 'default value';
}|
I've quickly read (maybe too quick), but I can't see what happen to the |
the setting doesn't affect the derived data patterns -- here is an example: https://ember-twiddle.com/567b7acf47448cee1f63fcb36e82cd66?openFiles=controllers.articles%5C.js%2C |
…-- the sticky query params example is more applicable to emberjs#715
|
@NullVoxPopuli is this just waiting on core review? |
|
yup |
|
Thanks for spending the time writing this RFC! Given the significant number of concerns around routing, we’re going to be completely revamping the router as part of Polaris. This RFC won’t directly apply to the new router so we’re going to move this PR to FCP to Close. But don’t worry, your work here was not in vain! We will be keeping track of this RFC and others like it to make sure that the concerns it aims to address will be covered in the new router. Your work here does a significant service to us in this regard! |
|
Fwiw, this RFC still serves as a source of (imo) better documentation for managing query params than we have today in the guides. (this was a documentation only RFC) |
|
Latest example I have: https://github.com/NullVoxPopuli/game-of-life/blob/main/app/services/display.ts |
| let { href } = this.args; | ||
| let qps = stickyQPsToQueryString(this.queryParams.forUrl(href)); | ||
|
|
||
| return `${href}?${qps}`; |
There was a problem hiding this comment.
This is mixing the URL APIs and string concatenation.
I'd love to see Ember support the Web standard URL APIs for this.
Something like this would gain the benifits of proper URI encoding.
let url = new URL(this.args.href, 'thismessage:/');
url.search = stickyQPsToQueryString(…);
return url.href;There was a problem hiding this comment.
yeah, the example is out of date -- using URL is very good, and I wrote all this before I started using URL, URLSearchParams, etc.
This is all userland code tho, so folks should feel free to use URL 🎉
Where can I find information about this Polaris plan for routing? |
rendered
This RFC is part of a series of RFCs to lead to the deprecation of controllers entirely. For more about how I imagine that happening, let's talk on Discord / keep the RFCs themselves focused on the topic they're about.
Related RFCs:
Arbitrary Query Params
An Alternative to Controllers