Skip to content

Attrs are never observed unless added with @attr decorator #208

Open
@kristoforsalmin

Description

@kristoforsalmin

Hi folks,

While I was testing the attributes — trying to work my way around #207 — I found another subtle detail. Manually initialized attributes are never observed.

Catalyst's guide provides the following example for vanilla users: https://github.com/github/catalyst/blob/main/docs/_guide/attrs.md#what-about-without-decorators.

Please notice the second argument there defineObservedAttributes(HelloWorldElement, ['foo']) and compare it with the actual function declaration:

export function defineObservedAttributes(classObject: CustomElement): void {

It doesn't expect the second argument (arguments aren't used either).

Now, internally defineObservedAttributes() pulls attribute names from getAttrNames(), which, in turn, pulls them from attrs (WeakMap). The only way to populate attrs is to use @attr decorator:

attrs.get(proto)!.push(key)

Maybe I'm missing something, but it seems like there's no way to specify observed attributes without decorators. In any case, it'd be very nice to clarify that 🙂

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions