fix: merge cases
This commit is contained in:
parent
f75ba69db5
commit
d3152b8dfb
|
@ -1,5 +1,5 @@
|
|||
export function mergeDiffArray(pristine, current) {
|
||||
if (!Array.isArray(pristine)) {
|
||||
export function mergeDiffArray(pristine, current, depth) {
|
||||
if (0 === depth || !Array.isArray(pristine)) {
|
||||
return current;
|
||||
}
|
||||
if (pristine.length !== current.length) {
|
||||
|
@ -13,8 +13,8 @@ export function mergeDiffArray(pristine, current) {
|
|||
return undefined;
|
||||
}
|
||||
|
||||
export function mergeDiffObject(pristine, current) {
|
||||
if ('object' !== typeof pristine) {
|
||||
export function mergeDiffObject(pristine, current, depth) {
|
||||
if (!current || 0 === depth || 'object' !== typeof pristine) {
|
||||
return current;
|
||||
}
|
||||
const diff = {};
|
||||
|
@ -23,7 +23,7 @@ export function mergeDiffObject(pristine, current) {
|
|||
const key = keys[i];
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
const value = mergeDiff(pristine[key], current[key]);
|
||||
if (undefined !== value) {
|
||||
if ('undefined' !== typeof value) {
|
||||
diff[key] = value;
|
||||
}
|
||||
}
|
||||
|
@ -37,12 +37,12 @@ export function mergeDiffPrimitive(pristine, current) {
|
|||
return pristine !== current ? current : undefined;
|
||||
}
|
||||
|
||||
export function mergeDiff(pristine, current) {
|
||||
export function mergeDiff(pristine, current, depth = Infinity) {
|
||||
if (Array.isArray(current)) {
|
||||
return mergeDiffArray(pristine, current);
|
||||
return mergeDiffArray(pristine, current, depth - 1);
|
||||
}
|
||||
if ('object' === typeof current) {
|
||||
return mergeDiffObject(pristine, current);
|
||||
return mergeDiffObject(pristine, current, depth - 1);
|
||||
}
|
||||
return mergeDiffPrimitive(pristine, current);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user