derivablejs icon indicating copy to clipboard operation
derivablejs copied to clipboard

Proposal: Remove transact and transaction

Open TrySound opened this issue 8 years ago • 3 comments

Now we have a lot of ways to do transaction. I'd like to figure out is there a use case in transact/transaction functions over atomic/atomically?

/cc @ds300 @andreypopp

TrySound avatar Dec 08 '17 13:12 TrySound

Sorry for the delay in getting to this. transact and transaction allow doing nested transactions. I'm not sure that's a use case that anyone cares about though, so feel free to merge this.

ds300 avatar Dec 11 '17 10:12 ds300

But what nested transactions allow to do?

TrySound avatar Dec 11 '17 10:12 TrySound

const x = atom('root')

transact(() => {
  x.set('in top transaction')
  try {
    transact(() => {
      x.set('in bottom transaction')
      throw new Error('whoops')
    })
  } catch (_) {}
  x.get() === 'in top transaction' // true
})

With atomically, .get() would still be in bottom transaction, since atomically doesn't create a new transaction context.

ds300 avatar Dec 11 '17 10:12 ds300