Attrs initialization without `@attr` decorator
還沒有人認領這個 Issue。
評估
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 新手友好度
- 35/100
- Issue 類型
- 缺陷
- 描述清晰度
- 基本清楚
- 活躍度
- 停滯
- 技術堆疊
- typescript
- 領域
- frontend
研究方向
先閱讀初始化 guard 附近的 src/attr.ts,以及 controller 包裝 connectedCallback() 的 src/core.ts。使用 initializeAttrs(this, ['open']) 和 data-open="false" 重現 InfoMessage 範例。當不使用 @attr 進行手動初始化時能夠套用屬性值,而不是讓 open 保持為 true,即表示完成。
由索引模型根據 Issue 內容生成。
描述
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
<script>
class InfoMessage extends HTMLElement {
open = true
connectedCallback() {
initializeAttrs(this, ['open'])
}
}
controller(InfoMessage)
</script>
<info-message data-open="false"></info-message>
controller(InfoMessage)wraps originalconnectedCallback()and calls:
https://github.com/github/catalyst/blob/a8fb3ba59a4ac258d0fe64a50ecd3b6997f5f016/src/core.ts#L14
InfoMessageis marked asinitialized(attrs.ts):
https://github.com/github/catalyst/blob/a8fb3ba59a4ac258d0fe64a50ecd3b6997f5f016/src/attr.ts#L40
- The original
connectedCallback()is executed, butinitializeAttrs()would hit that early-return condition. this.openis stuck in its default state (true) 😔
- 主要語言
- TypeScript
- 星號
- 1.4k
- 分支
- 61
- 平均合併
- 1 天 15 小時
- 30 天內合併 PR
- 8
環境準備
在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
github/catalyst 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 78/100
-
難度 3/5 1-2 天 新手友好度 62/100
-
難度 5/5 一週以上 新手友好度 20/100
-
難度 5/5 一週以上 新手友好度 25/100
-
難度 3/5 1-2 天 新手友好度 42/100
相似的 Issue
-
normalizePropName strips `#` characters from Figma property names instead of only the `#id` suffix未關閉
難度 2/5 1-3 小時 新手友好度 72/100
figma/code-connect#419 ·
-
bug
難度 2/5 1-3 小時 新手友好度 70/100
jeanibarz/knowledge-base-mcp-server#1268 ·
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 78/100
Koenkk/zigbee-herdsman-converters#13820 ·
維護者通常 2 天內回覆
-
A live recovery copy treats a large whole number and text with the same digits as the same value未關閉bug sharing & sync
難度 2/5 1-3 小時 新手友好度 64/100
維護者通常 1 天內回覆
-
[prefer-expect-resolves] autofix leaves a stray ")" when the awaited expression is parenthesized未關閉
難度 2/5 1-3 小時 新手友好度 78/100
jest-community/eslint-plugin-jest#2052 ·