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

[reative-element] improve support for private reactive properties #4647

Open
1 task done
sorvell opened this issue May 13, 2024 · 1 comment
Open
1 task done

[reative-element] improve support for private reactive properties #4647

sorvell opened this issue May 13, 2024 · 1 comment
Assignees

Comments

@sorvell
Copy link
Member

sorvell commented May 13, 2024

Should this be an RFC?

  • This is not a substantial change

Which package is this a feature request for?

Lit Core (lit / lit-html / lit-element / reactive-element)

Description

This doesn't work today:

@state()
accessor #foo = 5;

This probably would only work with standard decorators, but there are a couple changes we'll need to make it possible.

Currently, requestUpdate depends on being able to lookup the current property value via this[propertyKey] and that isn't possible with a private field.

Alternatives and Workarounds

You can write a manual getter/setter today.

#_foo = 5;
get #foo() {
  return this.#_foo;
}
set #foo(value) {
  const old = this.#foo;
  if (value !== old) {
    this._#foo = value;
    this.requestUpdate('#foo', old);
  }
}
@sorvell sorvell self-assigned this May 13, 2024
@sorvell
Copy link
Member Author

sorvell commented May 17, 2024

It's probably not worth trying to take any action on this until Lit no longer needs to support TypeScript experimental decorators or the legacy JS static properties object. Neither of these can use private identifiers.

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

No branches or pull requests

1 participant