All files / json-crdt-diff index.ts

100% Statements 12/12
66.66% Branches 2/3
100% Functions 2/2
100% Lines 9/9

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 16    174x   174x 12x 12x 12x     174x 11x 11x 11x    
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 | undefined => {
  const diff = new JsonCrdtDiff(src.api.model);
  const patch = diff.diff(src.node, dst);
  return patch.ops.length ? patch : void 0;
};
 
export const merge = (src: NodeApi<any>, dst: unknown): Patch | undefined => {
  const patch = diff(src, dst);
  if (patch) src.api.model.applyPatch(patch);
  return patch;
};