feat: Clarify keyed lists behavior

Đang mở
#1,351 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

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

Hướng nghiên cứu

Bắt đầu với trang tài liệu Lists của lit-html được liên kết và xem lại phần thảo luận về Array.prototype.map(), keyed() và repeat(). Làm rõ hành vi được tài liệu mô tả và khuyến nghị dành cho các danh sách được sắp xếp lại, bao gồm cả phần so sánh liên quan với React và Stencil. Công việc được xem là hoàn tất khi trang này giúp người mới dễ dàng hiểu được sự khác biệt và lựa chọn dự kiến.

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

Mô tả

[Regarding the page on lit-html Lists]

Coming from React and Stencil, I have been using this pattern in Lit:

myList.map(item=>
  keyed(item.key, html`...`)
)

(which is similar to myList.map(item=><item key={item.key} ...> you would do in React and Stencil)

After reading Lit's source code, I realized that this is actually wrong and inefficient as it will not move the DOM nodes in response to myList items changing order, and instead re-create the DOM elements from scratch

  1. It might be just me, but explicitly calling out the above as wrong in the docs may be a good idea for transplants from other frameworks, and mentioning that repeat() should be used instead
    • for new user this is a bit confusing - i.e why does map() directive exists at all when Array.prototype.map does the job, and with less overhead? though a few other Lit directives like ifDefined() and when() are kind of needless API bloat too
  2. Or better, would be nice if lit-html adds support for the above pattern and treats it equivalent to calling repeat() (which, I can understand may be undesirable as it would require you to always bundle repeat() even if not used).
    • As a workaround, for now I augmented my JSX->lit-html transformer to automatically convert code like myList.map(item=><item key={item.key} ...> into repeat(myList,item=>item.key,item=>html`<item ...>`
Ngôn ngữ chính
TypeScript
Star
140
Fork
229
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của lit/lit.dev

Tất cả issue của lit/lit.dev

Issue tương tự

Thêm issue về TypeScript

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.