TinyBase logoTinyBase β

getMergeableRowDiff

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

getMergeableRowDiff(otherTableRowHashes: RowHashes): [newRows: [thing: {[tableId: Id]: TableStamp<Hashed>}, time?: string], differingRowHashes: RowHashes]
TypeDescription
otherTableRowHashesRowHashes

The RowHashes of another MergeableStore.

returns[newRows: [thing: {[tableId: Id]: TableStamp<Hashed>}, time?: string], differingRowHashes: RowHashes]

A pair of objects describing the new and differing Row 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 Row objects of one versus the other. Once they have been merged, the differences are empty.

import {createMergeableStore} from 'tinybase';

const store1 = createMergeableStore('store1');
store1.setTables({pets: {fido: {color: 'brown'}}});

const store2 = createMergeableStore('store2');
store2.setTables({pets: {fido: {color: 'black'}, felix: {color: 'tan'}}});

console.log(
  store2.getMergeableRowDiff(
    store1.getMergeableRowHashes(
      store2.getMergeableTableDiff(store1.getMergeableTableHashes())[1],
    ),
  ),
);
// ->
[
  [{pets: [{felix: [{color: ['tan', 'Nn1JUF----0CnH-J']}]}]}],
  {pets: {fido: 1038491054}},
];

store1.merge(store2);

console.log(
  store2.getMergeableRowDiff(
    store1.getMergeableRowHashes(
      store2.getMergeableTableDiff(store1.getMergeableTableHashes())[1],
    ),
  ),
);
// -> [[{}], {}]

Since

v5.0.0