Skip to content

Latest commit

 

History

History
26 lines (25 loc) · 672 Bytes

DIFFINGALGORITHM.md

File metadata and controls

26 lines (25 loc) · 672 Bytes

If order matters

const maxLen = Math.max(lhs.length, rhs.length);
for (let i = 0; i < maxLen; i++) {
  const rnode: any = rhs[i];
  const lnode: any = lhs[i];
  if (!rnode) {
    // removed
    properties.value[lnode.prop] = null;
    propsChanged = true;
  } else if (!lnode) {
    // created
    properties.value[rnode.prop] = rnode.value;
    propsChanged = true;
  } else if (lnode.prop !== rnode.prop) {
    // deleted & created
    properties.value[lnode.prop] = null;
    properties.value[rnode.prop] = rnode.value;
  } else if (lnode.value !== rnode.value) {
    // updated
    properties.value[rnode.prop] = rnode.value;
    propsChanged = true;
  }
}