TinyBase logoTinyBase β

applyChanges

The applyChanges method applies a set of Changes to the Store.

applyChanges(changes: Changes): this
TypeDescription
changesChanges

The Changes to apply to the Store.

returnsthis

A reference to the Store.

This method will take a Changes 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 Changes 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.

Prior to v5.0, this method was named setTransactionChanges.

Example

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

import {createStore} from 'tinybase';

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

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

Since

v5.0.0