feat(atoms): replace arrays instead of deep merging in mutate shorthand#358
Merged
feat(atoms): replace arrays instead of deep merging in mutate shorthand#358
Conversation
8544ea4 to
cef302d
Compare
Arrays in the `.mutate` shorthand now fully replace instead of deep
merging by index. The previous behavior was surprising - e.g.
`signal.mutate({ arr: [1, 2] })` on `[10, 20, 30]` would produce
`[1, 2, 30]`. Now it produces `[1, 2]`. Use the callback form for
index-level updates: `signal.mutate(s => { s.arr[2] = 30 })`.
Also fixes pre-existing type errors by loosening `AtomApiGenerics`
Signal constraint from `Signal` to `AnySignal`, and consolidates
`RecursivePartialWithArrayPlucking` into `RecursivePartial` (with an
array guard added to both core and atoms).
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
cef302d to
0007df1
Compare
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.
Summary
.mutateshorthand now fully replace instead of deep merging by index. The previous behavior was surprising — e.g.signal.mutate({ arr: [1, 2] })on state{ arr: [10, 20, 30] }produced{ arr: [1, 2, 30] }. Now it produces{ arr: [1, 2] }. The callback form still supports index-level updates:signal.mutate(s => { s.arr[2] = 30 })AtomInstance,AtomTemplate,AtomTemplateBase,atom.ts, andion.tsby loosening theAtomApiGenericsSignal constraint from bareSignaltoAnySignal(Signal<any>)RecursivePartialWithArrayPluckingintoRecursivePartial— adds an array guard toRecursivePartialin both@zedux/coreand@zedux/atomsso arrays are treated as leaf values instead of having their methods made optionalThis reverts the array pluck shorthand introduced in v2.0.0-rc.13 from #331 6 days ago, so I'm not too concerned about it breaking stuff. Now that
.mutateshorthands can overwrite values with different value types (e.g. objects replacing arrays and vice versa), the pluck shorthand is strange. It's better to use normal mutation in the callback form for updating individual array elements anyway.Test plan
tsc --noEmitpasses with zero errors for the atoms package🤖 Generated with Claude Code