github / github/catalyst

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

Đang mở
#208 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
@attr
Ngôn ngữ chính
TypeScript
Star
1.4k
Fork
59
Merge trung bình
22 giờ 12 phút
Pull request đã merge (30 ngày)
5

Mô tả

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!

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
typescript
Lĩnh vực
frontend, web-dev
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.