Skip to content
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

[RRFC] Keeping and reverting to default values for properties #36

Open
1 task done
augustjk opened this issue Jan 18, 2024 · 1 comment
Open
1 task done

[RRFC] Keeping and reverting to default values for properties #36

augustjk opened this issue Jan 18, 2024 · 1 comment

Comments

@augustjk
Copy link

  • I searched for an existing RRFC which might be relevant to my RRFC

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

  • Setting property to undefined
  • Setting property to null (probably not this?)
  • delete el[prop]; (unlikely to happen?)
  • Removing associated attribute
  • If we implement spread, encountering a missing property from a previously rendered spread.

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

@augustjk
Copy link
Author

Having an alternate way of specifying a default value will also allow not reflecting initial property value to attribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant