5 lines
4.2 KiB
JavaScript
5 lines
4.2 KiB
JavaScript
|
/*!
|
||
|
* deep-diff.
|
||
|
* Licensed under the MIT License.
|
||
|
*/
|
||
|
!function(e){"use strict";var t,n,a=[];if(typeof global==="object"&&global){t=global}else if(typeof window!=="undefined"){t=window}else{t={}}n=t.DeepDiff;if(n){a.push(function(){if("undefined"!==typeof n&&t.DeepDiff===p){t.DeepDiff=n;n=e}})}function r(e,t){e.super_=t;e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:false,writable:true,configurable:true}})}function i(e,t){Object.defineProperty(this,"kind",{value:e,enumerable:true});if(t&&t.length){Object.defineProperty(this,"path",{value:t,enumerable:true})}}function f(e,t,n){f.super_.call(this,"E",e);Object.defineProperty(this,"lhs",{value:t,enumerable:true});Object.defineProperty(this,"rhs",{value:n,enumerable:true})}r(f,i);function l(e,t){l.super_.call(this,"N",e);Object.defineProperty(this,"rhs",{value:t,enumerable:true})}r(l,i);function u(e,t){u.super_.call(this,"D",e);Object.defineProperty(this,"lhs",{value:t,enumerable:true})}r(u,i);function s(e,t,n){s.super_.call(this,"A",e);Object.defineProperty(this,"index",{value:t,enumerable:true});Object.defineProperty(this,"item",{value:n,enumerable:true})}r(s,i);function h(e,t,n){var a=e.slice((n||t)+1||e.length);e.length=t<0?e.length+t:t;e.push.apply(e,a);return e}function c(t,n,a,r,i,p,o){i=i||[];var b=i.slice(0);if(typeof p!=="undefined"){if(r&&r(b,p)){return}b.push(p)}var d=typeof t;var k=typeof n;if(d==="undefined"){if(k!=="undefined"){a(new l(b,n))}}else if(k==="undefined"){a(new u(b,t))}else if(d!==k){a(new f(b,t,n))}else if(t instanceof Date&&n instanceof Date&&t-n!==0){a(new f(b,t,n))}else if(d==="object"&&t!==null&&n!==null){o=o||[];if(o.indexOf(t)<0){o.push(t);if(Array.isArray(t)){var v,y=t.length;for(v=0;v<t.length;v++){if(v>=n.length){a(new s(b,v,new u(e,t[v])))}else{c(t[v],n[v],a,r,b,v,o)}}while(v<n.length){a(new s(b,v,new l(e,n[v++])))}}else{var m=Object.keys(t);var g=Object.keys(n);m.forEach(function(i,f){var l=g.indexOf(i);if(l>=0){c(t[i],n[i],a,r,b,i,o);g=h(g,l)}else{c(t[i],e,a,r,b,i,o)}});g.forEach(function(t){c(e,n[t],a,r,b,t,o)})}o.length=o.length-1}}else if(t!==n){if(!(d==="number"&&isNaN(t)&&isNaN(n))){a(new f(b,t,n))}}}function p(t,n,a,r){r=r||[];c(t,n,function(e){if(e){r.push(e)}},a);return r.length?r:e}function o(e,t,n){if(n.path&&n.path.length){var a=e[t],r,i=n.path.length-1;for(r=0;r<i;r++){a=a[n.path[r]]}switch(n.kind){case"A":o(a[n.path[r]],n.index,n.item);break;case"D":delete a[n.path[r]];break;case"E":case"N":a[n.path[r]]=n.rhs;break}}else{switch(n.kind){case"A":o(e[t],n.index,n.item);break;case"D":e=h(e,t);break;case"E":case"N":e[t]=n.rhs;break}}return e}function b(e,t,n){if(e&&t&&n&&n.kind){var a=e,r=-1,i=n.path.length-1;while(++r<i){if(typeof a[n.path[r]]==="undefined"){a[n.path[r]]=typeof n.path[r]==="number"?new Array:{}}a=a[n.path[r]]}switch(n.kind){case"A":o(a[n.path[r]],n.index,n.item);break;case"D":delete a[n.path[r]];break;case"E":case"N":a[n.path[r]]=n.rhs;break}}}function d(e,t,n){if(n.path&&n.path.length){var a=e[t],r,i=n.path.length-1;for(r=0;r<i;r++){a=a[n.path[r]]}switch(n.kind){case"A":d(a[n.path[r]],n.index,n.item);break;case"D":a[n.path[r]]=n.lhs;break;case"E":a[n.path[r]]=n.lhs;break;case"N":delete a[n.path[r]];break}}else{switch(n.kind){case"A":d(e[t],n.index,n.item);break;case"D":e[t]=n.lhs;break;case"E":e[t]=n.lhs;break;case"N":e=h(e,t);break}}return e}function k(e,t,n){if(e&&t&&n&&n.kind){var a=e,r,i;i=n.path.length-1;for(r=0;r<i;r++){if(typeof a[n.path[r]]==="undefined"){a[n.path[r]]={}}a=a[n.path[r]]}switch(n.kind){case"A":d(a[n.path[r]],n.index,n.item);break;case"D":a[n.path[r]]=n.lhs;break;case"E":a[n.path[r]]=n.lhs;break;case"N":delete a[n.path[r]];break}}}function v(e,t,n){if(e&&t){var a=function(a){if(!n||n(e,t,a)){b(e,t,a)}};c(e,t,a)}}Object.defineProperties(p,{diff:{value:p,enumerable:true},observableDiff:{value:c,enumerable:true},applyDiff:{value:v,enumerable:true},applyChange:{value:b,enumerable:true},revertChange:{value:k,enumerable:true},isConflict:{value:function(){return"undefined"!==typeof n},enumerable:true},noConflict:{value:function(){if(a){a.forEach(function(e){e()});a=null}return p},enumerable:true}});if(typeof module!=="unde
|