TinyBase logoTinyBase

setTransactionChanges

The setTransactionChanges method applies a set of TransactionChanges to the Store.

setTransactionChanges(transactionChanges: TransactionChanges): Store
TypeDescription
transactionChangesTransactionChanges

The TransactionChanges to apply to the Store.

returnsStore

A reference to the Store.

This method will take a TransactionChanges object (which is available at the end of a transaction) and apply it to a Store. The most likely need to do this is to take the changes made during the transaction of one Store, and apply it to the content of another Store - such as when persisting and synchronizing data.

Any part of the provided TransactionChanges object are invalid (either because of its type, or because it does not match the schemas associated with the Store) will be ignored silently.

The method returns a reference to the Store so that subsequent operations can be chained in a fluent style.

Example

This example applies a TransactionChanges object that sets a Cell and removes a Value.

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

store.setTransactionChanges([
  {pets: {fido: {color: 'black'}}},
  {open: null},
]);
console.log(store.getTables());
// -> {pets: {fido: {species: 'dog', color: 'black'}}}
console.log(store.getValues());
// -> {}

Since

v4.0.0