TinyBase logoTinyBase

setPartialValues

The setPartialValues method takes an object and sets its Values in the Store, but leaving existing Values unaffected.

setPartialValues(partialValues: Values): this
TypeDescription
partialValuesValues

The Values to be set.

returnsthis

A reference to the Store.

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

Any part of the provided object that is invalid (either according to the Values type, or because, when combined with the current Values data, 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, it will be merged with the data that was already present in the Store. 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 some of the keyed value data in a Store.

import {createStore} from 'tinybase';

const store = createStore().setValues({open: true});
store.setPartialValues({employees: 3});
console.log(store.getValues());
// -> {open: true, employees: 3}

This example attempts to set some of 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.setPartialValues({employees: 3, bug: []});
console.log(store.getValues());
// -> {open: true, employees: 3}

store.setPartialValues(42);
console.log(store.getValues());
// -> {open: true, employees: 3}

Since

v3.0.0