TinyBase logoTinyBase

setTables

The setTables method takes an object and sets the entire tabular data of the Store.

setTables(tables: Tables): Store
TypeDescription
tablesTables

The data of the Store to be set.

returnsStore

This method will cause listeners to be called for any Table, Row, Cell, or Id changes resulting from it.

Any part of the provided object that is invalid (either according to the Tables type, or because it does not match a TablesSchema associated with the Store), will be ignored silently.

Assuming that at least some of the provided Tables object is valid, any data that was already present in the Store will be completely overwritten. If the object is completely invalid, no change will be made to the Store.

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

Examples

This example sets the tabular data of a Store.

const store = createStore().setTables({
  pets: {fido: {species: 'dog'}},
  species: {dog: {price: 5}},
});
console.log(store.getTables());
// -> {pets: {fido: {species: 'dog'}}, species: {dog: {price: 5}}}

This example attempts to set the tabular data of an existing Store with partly invalid, and then completely invalid, Tables objects.

const store = createStore().setTables({pets: {fido: {species: 'dog'}}});

store.setTables({pets: {felix: {species: 'cat', bug: []}}});
console.log(store.getTables());
// -> {pets: {felix: {species: 'cat'}}}

store.setTables({meaning: 42});
console.log(store.getTables());
// -> {pets: {felix: {species: 'cat'}}}