setDefaultContent
The setDefaultContent
method sets initial content of a MergeableStore
.
setDefaultContent(content: Content): MergeableStore
Type | Description | |
---|---|---|
content | Content | An array containing the tabular and keyed-value data to be set. |
returns | MergeableStore | A reference to the |
This differs from the setMergeableContent
method in that all of the metadata is initialized with a empty HLC timestamp - meaning that any changes applied to it will 'win', yet ensuring that at least default, initial data exists.
The method is generally intended to be used internally within TinyBase itself and the return type is assumed to be opaque to applications that use it.
Example
This example creates a new MergeableStore
with default data, and demonstrates that it is overwritten with another MergeableStore
's data on merge, even if the other MergeableStore
was provisioned earlier.
import {createMergeableStore} from 'tinybase';
const store1 = createMergeableStore('store1');
store1.setValues({employees: 3});
const store2 = createMergeableStore('store2');
store2.setDefaultContent([{}, {employees: 4}]);
console.log(store2.getMergeableContent());
// -> [[{}, "", 0], [{"employees": [4, "", 2414055963]}, "", 3035768673]]
store2.merge(store1);
console.log(store2.getContent());
// -> [{}, {employees: 3}]
Since
v5.0.0