-
Notifications
You must be signed in to change notification settings - Fork 319
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
Proposal: default/fallback values for properties #905
Comments
Isn’t this what the
The above usage only sets the |
Thank you @Westbrook, I personally didn't know about the lit-html directive Everything is in the same component/file with the Apart from the scenario described above, this default directive applies to everything. There may be cases in which you want to reset the property of a component from a parent, and you don't know which is the default value of the child property. Or you just want to reduce verbosity.
All in all, I think this solution can help programmers write simpler code. |
Thanks for the suggestion. We'd like to keep the core library as small as possible so we're not inclined to add this feature right now. However, we're definitely interested in making this kind of customization easier. We're planning some improvements on that front in #911 so we'll close this issue in favor of that one. |
Fixes #905. A couple changes to make customizing property accessors easier. * Adds static methods`setOptionsForProperty(name, options)`, `getOptionsForProperty` and renames `_requestUpdate` to `requestUpdateInternal` and makes it protected. With these changes, users can override `createProperty` and (1) pass in and later retrieve custom property otions, (2) customize how accessors are defined and call `requestUpdateInternal` in the setter to make the property reactive.
Problem
Many of our bugs are related to people believing that the initialization value is a default value.
So they write code, that works. But it is very ugly and repetitive.
Why are so many variables set as
undefined
despite having an initialization value? Because of abstractions. Let's say we have afilters
property with many dynamic filters to be rendered.Any filter property that is undefined will override the initialization value of our
filter
component. The following syntax would be great, but it's not legal.Proposal
We use a patched version of lit-element that allows the following syntax.
Whenever a property would become
undefined
, the value is overridden with the default value.Take a look at branch default_values in my repo.
I've also opened this pull request to discuss implementation details #906
The text was updated successfully, but these errors were encountered: