TinyBase logoTinyBase

MergeableStore

The MergeableStore type represents a Store that carries with it sufficient metadata to be able to be merged with another MergeableStore with deterministic results.

This is the key data type used when you need TinyBase data to be cleanly synchronized or merged with data elsewhere on the system, or on another system. It acts as a Conflict-Free Replicated Data Type (CRDT) which allows deterministic disambiguation of how changes to different instances should be merged.

Please be aware that a lot of the methods exposed by this interface are used internally within TinyBase itself (in particular the Synchronizer framework). They're documented here, but mostly for interest, and it is generally assumed that they won't be called directly by applications.

As an application developer, it's more likely that you will continue to use the main Store methods for reading, writing, and listening to data, and rely on Synchronizer instances to keep the data in step with other places.

One possible exceptions is the merge method, which can be used to simply merge two co-located MergeableStore instances together.

Example

This example shows very simple usage of the MergeableStore: whereby two are created, updated with different data, and then merged with one another.

import {createMergeableStore} from 'tinybase';

const localStore1 = createMergeableStore();
const localStore2 = createMergeableStore();

localStore1.setCell('pets', 'fido', 'color', 'brown');
localStore2.setCell('pets', 'felix', 'color', 'black');

localStore1.merge(localStore2);

console.log(localStore1.getContent());
// -> [{pets: {felix: {color: 'black'}, fido: {color: 'brown'}}}, {}]

console.log(localStore2.getContent());
// -> [{pets: {felix: {color: 'black'}, fido: {color: 'brown'}}}, {}]

Since

v5.0.0

Getter methods

Setter methods

Listener methods

Iterator methods

Syncing methods

Transaction methods

Deleter methods

Development methods