| 12 | } |
| 13 | |
| 14 | function syncKeys(current, previous) { |
| 15 | if (current === previous) return |
| 16 | const rootCurrentType = getType(current) |
| 17 | const rootPreType = getType(previous) |
| 18 | if (rootCurrentType == OBJECTTYPE && rootPreType == OBJECTTYPE) { |
| 19 | for (let key in previous) { |
| 20 | const currentValue = current[key] |
| 21 | if (currentValue === undefined) { |
| 22 | current[key] = null |
| 23 | } else { |
| 24 | syncKeys(currentValue, previous[key]) |
| 25 | } |
| 26 | } |
| 27 | } else if (rootCurrentType == ARRAYTYPE && rootPreType == ARRAYTYPE) { |
| 28 | if (current.length >= previous.length) { |
| 29 | previous.forEach((item, index) => { |
| 30 | syncKeys(current[index], item) |
| 31 | }) |
| 32 | } |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | function _diff(current, previous, path, result) { |
| 37 | if (current === previous) return |