Skip to content

docs(state): clarify observable() input is the underlying data#59

Open
sgup wants to merge 1 commit intoLegendApp:mainfrom
sgup:docs/observable-reset-gotcha
Open

docs(state): clarify observable() input is the underlying data#59
sgup wants to merge 1 commit intoLegendApp:mainfrom
sgup:docs/observable-reset-gotcha

Conversation

@sgup
Copy link
Copy Markdown

@sgup sgup commented Apr 27, 2026

Adds a third sub-section under "Observables are mutable" on the Observable page, explaining that the value passed to observable() is not cloned — it becomes the underlying data and is mutated in place as fields are updated.

The existing section #1 covers the symptom ("set it back onto the observable, that just sets it to itself") but doesn't connect it back to the original input. The new sub-section calls out the most common pitfall — reusing a shared initialState constant as a reset target — and shows the factory pattern as the fix.

Refs LegendApp/legend-state#647 — when investigating that issue I audited my own codebase and found 8 stores with silently broken reset functions from this exact pattern.

No structural changes to the page — just a new sub-section appended to the existing list.


Disclosure: written together with Claude (Anthropic). Verified locally.

Adds a third sub-section under "Observables are mutable" explaining that
the value passed to observable() is not cloned — it becomes the
underlying data and is mutated in place as fields are updated.

Calls out the most common gotcha (reusing a shared initialState constant
as a reset target — the constant becomes structurally equal to the
current state, so set() is a no-op via deep-equality) and shows the
factory pattern as the fix.

Refs LegendApp/legend-state#647 — when investigating that issue I
audited my own codebase and found 8 stores with silently broken reset
functions from this exact pattern.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant