TinyBase logoTinyBase

getMergeableCellDiff

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

getMergeableCellDiff(otherTableRowCellHashes: CellHashes): [thing: {[tableId: Id]: TableStamp<Hashed>}, time?: string]
TypeDescription
otherTableRowCellHashesCellHashes

The CellHashes of another MergeableStore.

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

The new and differing Cell 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 Cell 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', species: 'dog'}}});

console.log(
  store2.getMergeableCellDiff(
    store1.getMergeableCellHashes(
      store2.getMergeableRowDiff(
        store1.getMergeableRowHashes(
          store2.getMergeableTableDiff(
            store1.getMergeableTableHashes(),
          )[1],
        ),
      )[1],
    ),
  ),
);
// ->
[
  {
    pets: [
      {
        fido: [
          {
            color: ['black', 'Nn1JUF-----CnH-J'],
            species: ['dog', 'Nn1JUF----0CnH-J'],
          },
        ],
      },
    ],
  },
];

store1.merge(store2);

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

Since

v5.0.0