Skip to content


Choose a tag to compare
@jamesgpearce jamesgpearce released this 05 Jun 17:26
· 848 commits to main since this release

This release lets you add a listener to the start of a transaction, and detect that a set of changes are about to be made to a Store.

To use this, call the addStartTransactionListener method on your Store. The listener you add can itself mutate the data in the Store.

From this release onwards, listeners added with the existing addWillFinishTransactionListener method are also able to mutate data. Transactions added with the existing addDidFinishTransactionListener method cannot mutate data.

const store = createStore();

const startListenerId = store.addStartTransactionListener(() => {
  console.log('Start transaction');
  // Can mutate data

const willFinishListenerId = store.addWillFinishTransactionListener(() => {
  console.log('Will finish transaction');
  // Can mutate data

const didFinishListenerId = store.addDidFinishTransactionListener(() => {
  console.log('Did finish transaction');
  // Cannot mutate data

store.setTable('pets', {fido: {species: 'dog'}});
// -> 'Start transaction'
// -> {}
// -> 'Will finish transaction'
// -> {pets: {fido: {species: 'dog'}}}
// -> 'Did finish transaction'
// -> {pets: {fido: {species: 'dog'}}}


This release also fixes a bug where using the explicit startTransaction method inside another listener could create infinite recursion.