ds300 / derivablejs

Functional Reactive State for JavaScript and TypeScript
Apache License 2.0
515 stars 23 forks source link

Proposal: Remove transact and transaction #115

Open TrySound opened 6 years ago

TrySound commented 6 years ago

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

ds300 commented 6 years ago

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.

TrySound commented 6 years ago

But what nested transactions allow to do?

ds300 commented 6 years ago
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.