setRow
The setRow
method takes an object and sets the entire data of a single Row
in the Store
.
setRow(
tableId: string,
rowId: string,
row: Row,
): this
Type | Description | |
---|---|---|
tableId | string | |
rowId | string | |
row | Row | The 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 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, any data that was already present in the Store
for that Row
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 data of a single Row
.
import {createStore} from 'tinybase';
const store = createStore().setRow('pets', 'fido', {species: 'dog'});
console.log(store.getTables());
// -> {pets: {fido: {species: 'dog'}}}
This example attempts to set 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.setRow('pets', 'fido', {color: 'brown', bug: []});
console.log(store.getTables());
// -> {pets: {fido: {color: 'brown'}}}
store.setRow('pets', 'fido', 42);
console.log(store.getTables());
// -> {pets: {fido: {color: 'brown'}}}
Since
v1.0.0