All files / json-crdt/__bench__/util/execute runTrace.ts

95.65% Statements 22/23
66.66% Branches 2/3
100% Functions 1/1
100% Lines 17/17

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 17 18 19 20 21 22 23 24 25        2x 14x 14x 14x 14x 14x 987642x 987642x 987642x 987642x 1004302x 1004302x 1004302x 1004302x 1004302x 1004302x     14x    
import type {SequentialTrace, SequentialTraceEditor} from '../types';
 
/* tslint:disable no-console */
 
export const runTrace = (trace: SequentialTrace, editor: SequentialTraceEditor) => {
  const txns = trace.txns;
  const txnsLength = txns.length;
  const editorInstance = editor.factory();
  Iif (trace.startContent) editorInstance.ins(0, trace.startContent);
  for (let i = 0; i < txnsLength; i++) {
    const transaction = txns[i];
    const patches = transaction.patches;
    const length = patches.length;
    for (let j = 0; j < length; j++) {
      const patch = patches[j];
      const pos = patch[0];
      const del = patch[1];
      const insert = patch[2];
      if (del) editorInstance.del(pos, del);
      if (insert) editorInstance.ins(pos, insert);
    }
  }
  return editorInstance;
};