vana icon indicating copy to clipboard operation
vana copied to clipboard

Change how "bind" works with objects

Open aleclarson opened this issue 6 years ago • 1 comments

Currently, an object lens (created with bind) can only be replaced. Merging and/or drafting must be done with the revise function, which isn't awful, but we could do better.

const foo = o({ bar: { a: 0, b: 0 } })
const barLens = bind(foo, 'bar')

// Merge new values
barLens({ a: 1 })

// Overwrite all values
barLens(() => ({ a: 1, b: 1 }))

// Make edits with a producer
barLens(draft => {
  draft.a++
  draft.b++
})

aleclarson avatar Jun 18 '19 02:06 aleclarson

Object merging was added in v0.5.1 🎉

But producers are not yet supported

aleclarson avatar Jun 22 '19 02:06 aleclarson