feat: Clarify keyed lists behavior

Abierto
#1,351 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
35/100
Tipo de issue
Documentación
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
typescript

Línea de trabajo

Comienza con la página de documentación de Lists de lit-html enlazada y revisa su explicación de Array.prototype.map(), keyed() y repeat(). Aclara el comportamiento documentado y la recomendación para listas reordenadas, incluida la comparación relevante con React y Stencil. Se considera terminado cuando la página hace comprensibles para los recién llegados la distinción y la elección prevista.

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

Descripción

[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 ...>`
Lenguaje dominante
TypeScript
Estrellas
140
Forks
229
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de lit/lit.dev

Todos los issues de lit/lit.dev

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.