lit / lit/lit.dev

Add article about mutating data & public properties

Open
#819 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
142
Forks
230
PR merge metrics
No merged PRs in 30d

Description

Per a team discussion, we could add an article that discusses the challenges of passing around mutable objects & arrays to components.

For example, if your component has a public property that takes an array, your component could mutate the array, and the user would not know.

An alternative pattern would be to have separate input/output properties, for example, where the component makes an internal copy from the input property. Mutates the internal copy, and when the user approves changes, copies the internal version to the output property and fires an event.

@justinfagnani also noted the need to clone the copy to the appropriate depth, and maybe override `hasChanged` to check changes from the outside against the internal copy.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the examples and alternative pattern described in the issue; no file or test is named. Done means publishing an article that explains mutation risks for arrays and public properties, input/output patterns, cloning to the appropriate depth, and possibly using hasChanged for external comparisons.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.