-
-
Notifications
You must be signed in to change notification settings - Fork 408
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
Query Params as derived data #712
Query Params as derived data #712
Conversation
Co-authored-by: Alex Raputa <[email protected]>
Co-authored-by: Alex Raputa <[email protected]>
Co-authored-by: Jarek Radosz <[email protected]>
Co-authored-by: Alex Raputa <[email protected]>
export default class ArticlesController extends Controller { | ||
@service router; | ||
|
||
queryParams = ['category']; |
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.
I like this direction. Do you consider how query params are declared in scope for this RFC?
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.
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';
}
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.
related: #715
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 🎉
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