TinyBase logoTinyBase

setValues

The setValues method takes an object and sets all the Values in the Store.

setValues(values: Values): this
TypeDescription
valuesValues

The Values object to be set.

returnsthis

A reference to the Store.

This method will cause listeners to be called for any Value or Id changes resulting from it.

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

Assuming that at least some of the provided Values object is valid, any data that was already present in the Store for that Values 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 Values of a Store.

import {createStore} from 'tinybase';

const store = createStore().setValues({open: true, employees: 3});
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, Values objects.

import {createStore} from 'tinybase';

const store = createStore().setValues({open: true});

store.setValues({employees: 3, bug: []});
console.log(store.getValues());
// -> {employees: 3}

store.setValues(42);
console.log(store.getValues());
// -> {employees: 3}

Since

v3.0.0