TinyBase logoTinyBase

getMergeableValueDiff

The getMergeableValueDiff method returns information about new and differing Value objects of a MergeableStore relative to another.

getMergeableValueDiff(otherValueHashes: ValueHashes): [thing: {[valueId: Id]: ValueStamp<Hashed>}, time?: string]
TypeDescription
otherValueHashesValueHashes

The ValueHashes of another MergeableStore.

returns[thing: {[valueId: Id]: ValueStamp<Hashed>}, time?: string]

The new and differing Value objects of this MergeableStore relative to the other.

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 two MergeableStores, sets some differing data, and then identifies the differences in the Value objects of one versus the other. Once they have been merged, the differences are empty.

import {createMergeableStore} from 'tinybase';

const store1 = createMergeableStore('store1');
store1.setValues({employees: 3});

const store2 = createMergeableStore('store2');
store2.setValues({employees: 4, open: true});

console.log(
  store2.getMergeableValueDiff(store1.getMergeableValueHashes()),
);
// ->
[
  {
    employees: [4, 'Nn1JUF-----CnH-J'],
    open: [true, 'Nn1JUF----0CnH-J'],
  },
];

store1.merge(store2);

console.log(
  store2.getMergeableValueDiff(store1.getMergeableValueHashes()),
);
// -> [{}]

Since

v5.0.0