Skip to content

fix(atoms): replace top-level array state directly in signal.mutate#367

Open
bowheart wants to merge 1 commit intomasterfrom
josh/mutate-top-level-array
Open

fix(atoms): replace top-level array state directly in signal.mutate#367
bowheart wants to merge 1 commit intomasterfrom
josh/mutate-top-level-array

Conversation

@bowheart
Copy link
Copy Markdown
Collaborator

Summary

  • signal.mutate(arr) now replaces the entire array instead of recursing into it and deep merging elements, matching the behavior of inner array replacements like signal.mutate({ innerArr })
  • Emits a single { k: [], v } transaction for top-level array replacements, which composes correctly through MappedSignal key prefixing ({ k: [] }{ k: ['arr'] })
  • Handles all three array replacement paths: direct value, function return value, and null/undefined old state

Test plan

  • Updated existing test expectations for new transaction format
  • Added test: top-level array replacement generates { k: [], v } transaction
  • Added test: function-form returning an array generates a single transaction
  • Added test: MappedSignal correctly prefixes array replacement transaction with inner key
  • Updated snapshot for array operations
  • All 75 tests passing

🤖 Generated with Claude Code

Previously, `signal.mutate(arr)` would recurse into the array and deep
merge its elements, unlike inner arrays which were replaced directly.
Now top-level arrays are replaced with a single `{ k: [], v }` transaction
that composes correctly through MappedSignal key prefixing.

Co-Authored-By: Claude Opus 4.6 (1M context) <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