All files / json-crdt-diff index.ts

100% Statements 11/11
100% Branches 1/1
100% Functions 2/2
100% Lines 8/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15    170x   170x 4x 4x 4x     170x 3x 3x    
import type {Patch} from '../json-crdt-patch';
import type {NodeApi} from '../json-crdt/model';
import {JsonCrdtDiff} from './JsonCrdtDiff';
 
export const diff = (src: NodeApi<any>, dst: unknown): Patch => {
  const diff = new JsonCrdtDiff(src.api.model);
  const patch = diff.diff(src.node, dst);
  return patch;
};
 
export const merge = (src: NodeApi<any>, dst: unknown): void => {
  const patch = diff(src, dst);
  if (patch.ops.length) src.api.model.applyPatch(patch);
};