(current, previous, path, result)
| 34 | } |
| 35 | |
| 36 | function _diff(current, previous, path, result) { |
| 37 | if (current === previous) return |
| 38 | const rootCurrentType = getType(current) |
| 39 | const rootPreType = getType(previous) |
| 40 | if (rootCurrentType == OBJECTTYPE) { |
| 41 | if (rootPreType != OBJECTTYPE || Object.keys(current).length < Object.keys(previous).length && path !== '') { |
| 42 | setResult(result, path, current) |
| 43 | } else { |
| 44 | for (let key in current) { |
| 45 | const currentValue = current[key] |
| 46 | const preValue = previous[key] |
| 47 | const currentType = getType(currentValue) |
| 48 | const preType = getType(preValue) |
| 49 | if (currentType != ARRAYTYPE && currentType != OBJECTTYPE) { |
| 50 | if (currentValue !== previous[key]) { |
| 51 | setResult(result, concatPathAndKey(path, key), currentValue) |
| 52 | } |
| 53 | } else if (currentType == ARRAYTYPE) { |
| 54 | if (preType != ARRAYTYPE) { |
| 55 | setResult(result, concatPathAndKey(path, key), currentValue) |
| 56 | } else { |
| 57 | if (currentValue.length < preValue.length) { |
| 58 | setResult(result, concatPathAndKey(path, key), currentValue) |
| 59 | } else { |
| 60 | currentValue.forEach((item, index) => { |
| 61 | _diff(item, preValue[index], concatPathAndKey(path, key) + '[' + index + ']', result) |
| 62 | }) |
| 63 | } |
| 64 | } |
| 65 | } else if (currentType == OBJECTTYPE) { |
| 66 | if (preType != OBJECTTYPE || Object.keys(currentValue).length < Object.keys(preValue).length) { |
| 67 | setResult(result, concatPathAndKey(path, key), currentValue) |
| 68 | } else { |
| 69 | for (let subKey in currentValue) { |
| 70 | const realPath = concatPathAndKey(path, key) + (subKey.includes('.') ? `["${subKey}"]` : `.${subKey}`) |
| 71 | _diff(currentValue[subKey], preValue[subKey], realPath, result) |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | } else if (rootCurrentType == ARRAYTYPE) { |
| 78 | if (rootPreType != ARRAYTYPE) { |
| 79 | setResult(result, path, current) |
| 80 | } else { |
| 81 | if (current.length < previous.length) { |
| 82 | setResult(result, path, current) |
| 83 | } else { |
| 84 | current.forEach((item, index) => { |
| 85 | _diff(item, previous[index], path + '[' + index + ']', result) |
| 86 | }) |
| 87 | } |
| 88 | } |
| 89 | } else { |
| 90 | setResult(result, path, current) |
| 91 | } |
| 92 | } |
| 93 |
no test coverage detected