github / github/catalyst

Attrs initialization without `@attr` decorator

未关闭
#207 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
@attr
主要语言
TypeScript
星标
1.4k
派生
59
平均合并
22 小时 12 分钟
30 天内合并 PR
5

描述

Hi there 😄

After upgrading from v1.1.4 to v1.3.2, I noticed that my attributes were no longer shadowed by `initializeAttrs()`. I started digging and stumbled upon this piece of logic introduced in #191:

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

It prevents `initializeAttrs()` from doing anything the second time around, thus skipping the manual initialization of attributes. Also, it seems like this change was one of the main things addressed by the above-mentioned PR.

So, what would be the correct way now to initialize the attributes without the `@attr` decorator?

Thanks!

---

**Example**

```html

class InfoMessage extends HTMLElement {
open = true

connectedCallback() {
initializeAttrs(this, ['open'])
}
}

controller(InfoMessage)

```

1. `controller(InfoMessage)` wraps original `connectedCallback()` and calls:

https://github.com/github/catalyst/blob/a8fb3ba59a4ac258d0fe64a50ecd3b6997f5f016/src/core.ts#L14

2. `InfoMessage` is marked as `initialized` (`attrs.ts`):

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

3. The original `connectedCallback()` is executed, but `initializeAttrs()` would hit that early-return condition.
4. `this.open` is stuck in its default state (`true`) 😔

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。