github / github/catalyst

Attrs are never observed unless added with `@attr` decorator

Abierto
#208 1 comentario 0 reacciones 0 asignados Ver en GitHub
@attr
Lenguaje dominante
TypeScript
Estrellas
1.4k
Forks
59
Merge medio
22 h 12 min
PR fusionados (30 d)
5

Descripción

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:

https://github.com/github/catalyst/blob/a8fb3ba59a4ac258d0fe64a50ecd3b6997f5f016/src/attr.ts#L99

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:

https://github.com/github/catalyst/blob/a8fb3ba59a4ac258d0fe64a50ecd3b6997f5f016/src/attr.ts#L15

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!

Guía de contribución

Abrir la guía de contribución

Línea de trabajo

Start with src/attr.ts, especially defineObservedAttributes() and getAttrNames(), then compare their behavior with the vanilla example in docs/_guide/attrs.md. Confirm whether manually initialized attributes can be observed without @attr; done means the implementation and guide agree on how observed attributes are specified.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
typescript
Área
frontend, web-dev
Tipo de issue
Error
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.