Skip to content

feat(atoms): improve proxies, esp sets with mutate shorthand#331

Open
bowheart wants to merge 1 commit intomasterfrom
josh/set-mutate-improvements
Open

feat(atoms): improve proxies, esp sets with mutate shorthand#331
bowheart wants to merge 1 commit intomasterfrom
josh/set-mutate-improvements

Conversation

@bowheart
Copy link
Collaborator

Description

When a signal contains a JS Set, normal mutation operations work on it, e.g.:

const signal = ecosystem.signal(new Set(['foo']))

signal.mutate(draft => {
  draft.add('bar')
  draft.delete('foo')
})

But .mutate's shorthand forms are unable to perform these operations:

signal.mutate(new Set(['bar'])) // should remove 'foo' and add 'bar'
signal.mutate(draft => new Set(['bar'])) // same

It isn't straightforward that this isn't supported. We can support this. So now we do.

While I was in there, I also added these changes:

  • Prevent adding transactions for every unchanged value passed to the .mutate shorthands. This highly optimizes spread operations - e.g.

    signal.mutate(state => [...state, 'newItem'])
    // this now has pretty much the exact same behavior as:
    signal.mutate(state => {
      state.push('newItem')
    })
  • Prevent recursing deeper when object refs match

  • Adjust types to accept an array pluck shorthand:

    const signal = ecosystem.signal(['foo', 'bar'])
    signal.mutate({ 1: 'baz' }) // changes the item at index 1 ('bar') to 'baz'

    This worked previously, but the types didn't reflect it. Now they do.

@tamasKon tamasKon closed this Jan 15, 2026
@tamasKon tamasKon reopened this Jan 15, 2026
@bowheart bowheart force-pushed the josh/set-mutate-improvements branch from 13839aa to 6f7ac8c Compare February 13, 2026 00:28
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.

2 participants

Comments