setPartialRow
The setPartialRow method takes an object and sets partial data of a single Row in the Store, leaving other Cell values unaffected.
setPartialRow(
tableId: string,
rowId: string,
partialRow: Row,
): this| Type | Description | |
|---|---|---|
tableId | string | |
rowId | string | |
partialRow | Row | The partial data of a single |
| returns | this | A reference to the |
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 Row type, or because, when combined with the current Row data, it does not match a TablesSchema associated with the Store), will be ignored silently.
Assuming that at least some of the provided Row 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 data of a single Row.
import {createStore} from 'tinybase';
const store = createStore().setTables({
pets: {fido: {species: 'dog', color: 'brown'}},
});
store.setPartialRow('pets', 'fido', {color: 'walnut', visits: 1});
console.log(store.getTables());
// -> {pets: {fido: {species: 'dog', color: 'walnut', visits: 1}}}
This example attempts to set some of the data of an existing Store with partly invalid, and then completely invalid, Row objects.
import {createStore} from 'tinybase';
const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
store.setPartialRow('pets', 'fido', {color: 'brown', bug: []});
console.log(store.getTables());
// -> {pets: {fido: {species: 'dog', color: 'brown'}}}
store.setPartialRow('pets', 'fido', 42);
console.log(store.getTables());
// -> {pets: {fido: {species: 'dog', color: 'brown'}}}
Since
v1.0.0