docs(state): clarify observable() input is the underlying data#59
Open
sgup wants to merge 1 commit intoLegendApp:mainfrom
Open
docs(state): clarify observable() input is the underlying data#59sgup wants to merge 1 commit intoLegendApp:mainfrom
sgup wants to merge 1 commit intoLegendApp:mainfrom
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
initialStateconstant 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.