-
Notifications
You must be signed in to change notification settings - Fork 12
[RRFC] Keeping and reverting to default values for properties #36
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
Comments
Having an alternate way of specifying a default value will also allow not reflecting initial property value to attribute. |
I think we should do this as soon as we can. It's a frequent customer request. |
This will affect attribute-based styling (example). If user explicitly sets the property to a default value, would that remove the attribute? If not, the .css selector would need to handle both no-attribute and default value attribute case - quite a complication. |
I feel like it's more expected that HTML elements with tied attributes and properties don't spawn attributes on their own, e.g. However, reflecting default property values to attributes has been Lit's behavior so far and we have customers that depend on that behavior. It could be reasonable to keep that behavior as a property option, if we make non-reflection the default behavior. |
Non-initial-reflection will only be the default behavior if you specify the |
Motivation
Currently the common pattern of setting default values for properties to do it in the constructor or class field instantiation. These are really more initial values that we lose after instantiation. Users may actually want some behavior where "unsetting" a property will revert to a default value.
It's possible to manually add this behavior by falling back to some value in
render()
,willUpdate()
, or custom accessors[1] or even attribute converters if we wish to consider removing an attribute as "unsetting" as well.There have also been calls for this behavior for or React wrapper[2] which we could add on at the wrapper level but would also be nice to have it for the underlying Lit element.
We do need to decide what "unsetting" means
undefined
null
(probably not this?)delete el[prop];
(unlikely to happen?)How
Eventually when the only way to declare a property is with standard decorators, I believe we get access to the initial value set on the class field (with auto-accessor). Until then, we would need to add a property option for the default value.
Once we collect the default value, we can add it as a fallback value in an appropriate place like property setter or attribute converter.
References
The text was updated successfully, but these errors were encountered: