TinyBase logoTinyBase

getTransactionChanges

The getTransactionChanges method returns the net meaningful changes that have been made to a Store during a transaction.

getTransactionChanges(): Changes
returnsChanges

A Changes object representing the changes.

This is useful for deciding whether to rollback a transaction, for example. The returned object is only meaningful if the method is called when the Store is in a transaction - such as in a TransactionListener.

Example

This example makes changes to the Store. At the end of the transaction, detail about what changed is enumerated.

import {createStore} from 'tinybase';

const store = createStore()
  .setTables({pets: {fido: {species: 'dog', color: 'brown'}}})
  .setValues({open: true});

store
  .startTransaction()
  .setCell('pets', 'fido', 'color', 'black')
  .setValue('open', false)
  .finishTransaction(() => {
    const [changedCells, changedValues] = store.getTransactionChanges();
    console.log(changedCells);
    console.log(changedValues);
  });
// -> {pets: {fido: {color: 'black'}}}
// -> {open: false}

Since

v5.0.0