Skip to content
Myr

refactor: avoid unnecessary function wrapper

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Alec Larson · committed by Alec Larson · parent 594d637 · Browse files · 1 file+23 added−24 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+23 added−24 removed

  • other:+23 added−24 removed

1 file+23 added−24 removed

modified:src/patches.js+23 added-24 removed
3 unmodified lines
4 const generatePatchesFn = Array.isArray(state.base)5 ? generateArrayPatches6 : isSet(state.base)7 ? generateSetPatches8 : generatePatchesFromAssigned()8 : generatePatchesFromAssigned910 generatePatchesFn(state, basePath, patches, inversePatches)11}12
65 unmodified lines
78 })79 }80}8182function generatePatchesFromAssigned() {83 return function(state, basePath, patches, inversePatches) {84 const {base, copy} = state85 each(state.assigned, (key, assignedValue) => {86 const origValue = get(base, key)87 const value = get(copy, key)88 const op = !assignedValue89 ? "remove"90 : has(base, key)91 ? "replace"92 : "add"93 if (origValue === value && op === "replace") return94 const path = basePath.concat(key)95 patches.push(op === "remove" ? {op, path} : {op, path, value})96 inversePatches.push(97 op === "add"98 ? {op: "remove", path}99 : op === "remove"100 ? {op: "add", path, value: origValue}101 : {op: "replace", path, value: origValue}102 )103 })104 }82// This is used for both Map objects and normal objects.83function generatePatchesFromAssigned(state, basePath, patches, inversePatches) {84 const {base, copy} = state85 each(state.assigned, (key, assignedValue) => {86 const origValue = get(base, key)87 const value = get(copy, key)88 const op = !assignedValue89 ? "remove"90 : has(base, key)91 ? "replace"92 : "add"93 if (origValue === value && op === "replace") return94 const path = basePath.concat(key)95 patches.push(op === "remove" ? {op, path} : {op, path, value})96 inversePatches.push(97 op === "add"98 ? {op: "remove", path}99 : op === "remove"100 ? {op: "add", path, value: origValue}101 : {op: "replace", path, value: origValue}102 )103 })104}105106function generateSetPatches(state, basePath, patches, inversePatches) {107 let {base, copy} = state
96 unmodified lines