setContent
The setContent
method takes an array of two objects and sets the entire data of the Store
.
setContent(content: Content): this
Type | Description | |
---|---|---|
content | Content | An array containing the tabular and keyed-value data of the |
returns | this | A reference to the |
This method will cause listeners to be called for any Table
, Row
, Cell
, Value
, or Id
changes resulting from it.
Any part of the provided objects that are invalid (either according to the Tables
or Values
type, or because it does not match a TablesSchema
or ValuesSchema
associated with the Store
), will be ignored silently.
Assuming that at least some of the provided Tables
object or Values
object is valid, any data that was already present in that part of the Store
will be completely overwritten. If either object is completely invalid, no change will be made to the corresponding part of 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 data of a Store
.
import {createStore} from 'tinybase';
const store = createStore().setContent([
{pets: {fido: {species: 'dog'}}},
{open: true, employees: 3},
]);
console.log(store.getTables());
// -> {pets: {fido: {species: 'dog'}}}
console.log(store.getValues());
// -> {open: true, employees: 3}
This example attempts to set the data of an existing Store
with partly invalid, and then completely invalid objects.
import {createStore} from 'tinybase';
const store = createStore().setContent([
{pets: {fido: {species: 'dog'}}},
{open: true, employees: 3},
]);
store.setContent([{pets: {felix: {species: 'cat', bug: []}}}, '']);
console.log(store.getTables());
// -> {pets: {felix: {species: 'cat'}}}
console.log(store.getValues());
// -> {open: true, employees: 3}
store.setContent([{meaning: 42}]);
console.log(store.getTables());
// -> {pets: {felix: {species: 'cat'}}}
Since
v4.0.0