object-observer
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -6,6 +6,2 @@ const proxiesToTargetsMap = new Map(), | ||
export { | ||
Observable | ||
} | ||
export default Observable; | ||
@@ -27,3 +23,3 @@ | ||
result = function proxiedPop() { | ||
let poppedIndex, popResult, tmpTarget, changes; | ||
let poppedIndex, popResult, tmpTarget; | ||
poppedIndex = target.length - 1; | ||
@@ -35,4 +31,3 @@ popResult = Reflect.apply(target[key], target, arguments); | ||
} | ||
changes = [new DeleteChange(observed.path.concat(poppedIndex), tmpTarget || popResult)]; | ||
observable.notify(changes); | ||
observable.notify([new DeleteChange(observed.path.concat(poppedIndex), tmpTarget || popResult)]); | ||
return tmpTarget || popResult; | ||
@@ -58,3 +53,3 @@ }; | ||
result = function proxiedShift() { | ||
let shiftResult, changes, tmpTarget; | ||
let shiftResult, tmpTarget; | ||
shiftResult = Reflect.apply(target[key], target, arguments); | ||
@@ -78,4 +73,3 @@ tmpTarget = proxiesToTargetsMap.get(shiftResult); | ||
} | ||
changes = [new DeleteChange(observed.path.concat(0), tmpTarget || shiftResult)]; | ||
observable.notify(changes); | ||
observable.notify([new DeleteChange(observed.path.concat(0), tmpTarget || shiftResult)]); | ||
return tmpTarget || shiftResult; | ||
@@ -112,3 +106,3 @@ }; | ||
result = function proxiedReverse() { | ||
let changes, tmpObserved; | ||
let tmpObserved; | ||
Reflect.apply(target[key], target, arguments); | ||
@@ -126,4 +120,3 @@ for (let i = 0, l = target.length, item; i < l; i++) { | ||
} | ||
changes = [new ReverseChange()]; | ||
observable.notify(changes); | ||
observable.notify([new ReverseChange()]); | ||
return this; | ||
@@ -133,3 +126,3 @@ }; | ||
result = function proxiedSort() { | ||
let changes, tmpObserved; | ||
let tmpObserved; | ||
Reflect.apply(target[key], target, arguments); | ||
@@ -147,4 +140,3 @@ for (let i = 0, l = target.length, item; i < l; i++) { | ||
} | ||
changes = [new ShuffleChange()]; | ||
observable.notify(changes); | ||
observable.notify([new ShuffleChange()]); | ||
return this; | ||
@@ -265,8 +257,5 @@ }; | ||
if (observable.hasListeners) { | ||
let path = observed.path.concat(key), | ||
changes = [oldValuePresent ? new UpdateChange(path, value, oldTarget || oldValue) : new InsertChange(path, value)]; | ||
if (!observed.preventCallbacks) { | ||
observable.notify(changes); | ||
} | ||
if (observable.hasListeners() && !observed.preventCallbacks) { | ||
let path = observed.path.concat(key); | ||
observable.notify([oldValuePresent ? new UpdateChange(path, value, oldTarget || oldValue) : new InsertChange(path, value)]); | ||
} | ||
@@ -292,8 +281,5 @@ } | ||
if (observable.hasListeners) { | ||
let path = observed.path.concat(key), | ||
changes = [new DeleteChange(path, oldTarget || oldValue)]; | ||
if (!observed.preventCallbacks) { | ||
observable.notify(changes); | ||
} | ||
if (observable.hasListeners() && !observed.preventCallbacks) { | ||
let path = observed.path.concat(key); | ||
observable.notify([new DeleteChange(path, oldTarget || oldValue)]); | ||
} | ||
@@ -300,0 +286,0 @@ } |
@@ -1,1 +0,1 @@ | ||
const proxiesToTargetsMap=new Map,targetsToObserved=new Map,observedToObservable=new Map,nonObservables=["Date","Blob","Number","String","Boolean","Error","SyntaxError","TypeError","URIError","Function","Promise","RegExp"];export{Observable};export default Observable;function copyShallow(e){return Array.isArray(e)?e.slice():Object.assign({},e)}function isNonObservable(e){return nonObservables.indexOf(e.constructor.name)>=0}function proxiedArrayGet(e,t){let r,o=targetsToObserved.get(e),n=observedToObservable.get(o.root);return r="pop"===t?function(){let r,s,a,l;return r=e.length-1,s=Reflect.apply(e[t],e,arguments),(a=proxiesToTargetsMap.get(s))&&targetsToObserved.get(a).revoke(),l=[new DeleteChange(o.path.concat(r),a||s)],n.notify(l),a||s}:"push"===t?function(){let r,s,a,l=[];r=Array.from(arguments),a=e.length;for(let e,t=0,n=r.length;t<n;t++)(e=r[t])&&"object"==typeof e&&(r[t]=new Observed(e,a+t,o).proxy),l.push(new InsertChange(o.path.concat(a+t),e));return s=Reflect.apply(e[t],e,r),n.notify(l),s}:"shift"===t?function(){let r,s,a;r=Reflect.apply(e[t],e,arguments),(a=proxiesToTargetsMap.get(r))&&targetsToObserved.get(a).revoke();for(let t,r,o=0,n=e.length;o<n;o++)(t=e[o])&&"object"==typeof t&&((r=targetsToObserved.get(proxiesToTargetsMap.get(t)))?r.ownKey=o:console.error("unexpectedly failed to resolve proxy -> target -> observed"));return s=[new DeleteChange(o.path.concat(0),a||r)],n.notify(s),a||r}:"unshift"===t?function(){let r,s,a,l=[];(r=Array.from(arguments)).forEach(function(e,t){e&&"object"==typeof e&&(r[t]=new Observed(e,t,o).proxy)}),s=Reflect.apply(e[t],e,r);for(let t,r=0,o=e.length;r<o;r++)(t=e[r])&&"object"==typeof t&&((a=targetsToObserved.get(proxiesToTargetsMap.get(t)))?a.ownKey=r:console.error("failed to resolve proxy -> target -> observed"));for(let t=0,n=r.length;t<n;t++)l.push(new InsertChange(o.path.concat(t),e[t]));return n.notify(l),s}:"reverse"===t?function(){let r,o;Reflect.apply(e[t],e,arguments);for(let t,r=0,n=e.length;r<n;r++)(t=e[r])&&"object"==typeof t&&((o=targetsToObserved.get(proxiesToTargetsMap.get(t)))?o.ownKey=r:console.error("failed to resolve proxy -> target -> observed"));return r=[new ReverseChange],n.notify(r),this}:"sort"===t?function(){let r,o;Reflect.apply(e[t],e,arguments);for(let t,r=0,n=e.length;r<n;r++)(t=e[r])&&"object"==typeof t&&((o=targetsToObserved.get(proxiesToTargetsMap.get(t)))?o.ownKey=r:console.error("failed to resolve proxy -> target -> observed"));return r=[new ShuffleChange],n.notify(r),this}:"fill"===t?function(){let r,s,a,l=[],p=arguments.length,i=e.length;r=p<2?0:arguments[1]<0?i+arguments[1]:arguments[1],s=p<3?i:arguments[2]<0?i+arguments[2]:arguments[2],a=e.slice(),Reflect.apply(e[t],e,arguments);for(let t,n,p=r;p<s;p++)(t=e[p])&&"object"==typeof t&&(e[p]=new Observed(t,p,o).proxy),a.hasOwnProperty(p)?((n=proxiesToTargetsMap.get(a[p]))&&targetsToObserved.get(n).revoke(),l.push(new UpdateChange(o.path.concat(p),e[p],n||a[p]))):l.push(new InsertChange(o.path.concat(p),e[p]));return n.notify(l),this}:"splice"===t?function(){let r,s,a,l,p,i,b,f,c=[],v=e.length;b=(r=Array.from(arguments)).length;for(let e,t=0;t<b;t++)e=r[t],t>1&&e&&"object"==typeof e&&(r[t]=new Observed(e,t,o).proxy);l=0===b?0:r[0]<0?v+r[0]:r[0],p=b<2?v-l:r[1],i=Math.max(b-2,0),s=Reflect.apply(e[t],e,r);for(let t,r=0;r<v;r++)(t=e[r])&&"object"==typeof t&&((a=targetsToObserved.get(proxiesToTargetsMap.get(t)))?a.ownKey=r:console.error("failed to resolve proxy -> target -> observed"));for(let e,t,r=0,o=s.length;r<o;r++)e=s[r],(t=proxiesToTargetsMap.get(e))&&(targetsToObserved.get(t).revoke(),s[r]=t);for(f=0;f<p;f++)f<i?c.push(new UpdateChange(o.path.concat(l+f),e[l+f],s[f])):c.push(new DeleteChange(o.path.concat(l+f),s[f]));for(;f<i;f++)c.push(new InsertChange(o.path.concat(l+f),e[l+f]));return n.notify(c),s}:Reflect.get(e,t)}function proxiedSet(e,t,r){let o,n,s=e.hasOwnProperty(t),a=e[t],l=targetsToObserved.get(e),p=observedToObservable.get(l.root);if((o=r&&"object"==typeof r&&!isNonObservable(r)?Reflect.set(e,t,new Observed(r,t,l).proxy):Reflect.set(e,t,r))&&((n=proxiesToTargetsMap.get(a))&&targetsToObserved.get(n).revoke(),p.hasListeners)){let e=l.path.concat(t),o=[s?new UpdateChange(e,r,n||a):new InsertChange(e,r)];l.preventCallbacks||p.notify(o)}return o}function proxiedDelete(e,t){let r,o,n=e[t],s=targetsToObserved.get(e),a=observedToObservable.get(s.root);if((r=Reflect.deleteProperty(e,t))&&((o=proxiesToTargetsMap.get(n))&&targetsToObserved.get(o).revoke(),a.hasListeners)){let e=[new DeleteChange(s.path.concat(t),o||n)];s.preventCallbacks||a.notify(e)}return r}function processArraySubgraph(e,t){for(let r,o=0,n=e.length;o<n;o++)(r=e[o])&&"object"==typeof r&&!isNonObservable(r)&&(e[o]=new Observed(r,o,t).proxy)}function processObjectSubgraph(e,t){let r=Object.keys(e);for(let o,n,s=0,a=r.length;s<a;s++)(n=e[o=r[s]])&&"object"==typeof n&&!isNonObservable(n)&&(e[o]=new Observed(n,o,t).proxy)}function Observed(e,t,r){let o,n,s;if(!e||"object"!=typeof e)throw new Error("Observed MUST be created from a non null object origin");if(r&&(void 0===t||null===t))throw new Error("any non-root (parent-less) Observed MUST have an own path; now parent is "+r+"; key is "+t);if(r&&!(r instanceof Observed))throw new Error("parent, when supplied, MUST be an instance of Observed");o=copyShallow(e),Array.isArray(o)?(processArraySubgraph(o,this),n=Proxy.revocable(o,{set:proxiedSet,get:proxiedArrayGet,deleteProperty:proxiedDelete})):(processObjectSubgraph(o,this),n=Proxy.revocable(o,{set:proxiedSet,deleteProperty:proxiedDelete})),s=n.proxy,targetsToObserved.set(o,this),proxiesToTargetsMap.set(s,o),Object.defineProperties(this,{revokable:{value:n},proxy:{value:s},parent:{value:r},ownKey:{value:t,writable:!0}})}function Observable(e){let t=!1,r=[];Object.defineProperties(e.proxy,{observe:{value:function(e){if(t)throw new TypeError("revoked Observable MAY NOT be observed anymore");if("function"!=typeof e)throw new Error("observer (callback) parameter MUST be a function");r.indexOf(e)<0?r.push(e):console.info("observer (callback) may be bound to an observable only once")}},unobserve:{value:function(){if(t)throw new TypeError("revoked Observable MAY NOT be unobserved anymore");if(arguments.length)for(let e,t=0,o=arguments.length;t<o;t++)(e=r.indexOf(arguments[t]))>=0&&r.splice(e,1);else r.splice(0,r.length)}},revoke:{value:function(){t?console.log("revoking of Observable effective only once"):(t=!0,e.revoke())}}}),Object.defineProperties(this,{hasListeners:{value:function(){return r.length>0}},notify:{value:function(e){for(let t,o=0,n=r.length;o<n;o++){t=r[o];try{t(e)}catch(e){console.error("one/some of the observing callbacks failed with ",e)}}}}})}function InsertChange(e,t){Object.defineProperties(this,{type:{value:"insert"},path:{value:e},value:{value:t}})}function UpdateChange(e,t,r){Object.defineProperties(this,{type:{value:"update"},path:{value:e},value:{value:t},oldValue:{value:r}})}function DeleteChange(e,t){Object.defineProperties(this,{type:{value:"delete"},path:{value:e},oldValue:{value:t}})}function ReverseChange(){Object.defineProperties(this,{type:{value:"reverse"}})}function ShuffleChange(){Object.defineProperties(this,{type:{value:"shuffle"}})}Object.defineProperty(Observed.prototype,"root",{get:function(){let e=this;for(;e.parent;)e=e.parent;return e}}),Object.defineProperty(Observed.prototype,"path",{get:function(){let e=[],t=this;for(;void 0!==t.ownKey;)e.unshift(t.ownKey),t=t.parent;return e}}),Object.defineProperty(Observed.prototype,"revoke",{value:function(){let e=proxiesToTargetsMap.get(this.proxy),t=Object.keys(e);this.revokable.revoke();for(let r,o,n=0,s=t.length;n<s;n++)r=t[n],(o=proxiesToTargetsMap.get(e[r]))&&(e[r]=targetsToObserved.get(o).revoke());return proxiesToTargetsMap.delete(this.proxy),targetsToObserved.delete(e),e}}),Object.defineProperty(Observable,"from",{value:function(e){if(!e||"object"!=typeof e)throw new Error("observable MAY ONLY be created from non-null object only");if("observe"in e||"unobserve"in e||"revoke"in e)throw new Error('target object MUST NOT have nor own neither inherited properties from the following list: "observe", "unobserve", "revoke"');if(isNonObservable(e))throw new Error(e+" found to be one of non-observable object types: "+nonObservables);let t=new Observed(e),r=new Observable(t);return observedToObservable.set(t,r),t.proxy}}),Object.freeze(Observable); | ||
const proxiesToTargetsMap=new Map,targetsToObserved=new Map,observedToObservable=new Map,nonObservables=["Date","Blob","Number","String","Boolean","Error","SyntaxError","TypeError","URIError","Function","Promise","RegExp"];export default Observable;function copyShallow(e){return Array.isArray(e)?e.slice():Object.assign({},e)}function isNonObservable(e){return nonObservables.indexOf(e.constructor.name)>=0}function proxiedArrayGet(e,t){let r,o=targetsToObserved.get(e),n=observedToObservable.get(o.root);return r="pop"===t?function(){let r,s,a;return r=e.length-1,s=Reflect.apply(e[t],e,arguments),(a=proxiesToTargetsMap.get(s))&&targetsToObserved.get(a).revoke(),n.notify([new DeleteChange(o.path.concat(r),a||s)]),a||s}:"push"===t?function(){let r,s,a,l=[];r=Array.from(arguments),a=e.length;for(let e,t=0,n=r.length;t<n;t++)(e=r[t])&&"object"==typeof e&&(r[t]=new Observed(e,a+t,o).proxy),l.push(new InsertChange(o.path.concat(a+t),e));return s=Reflect.apply(e[t],e,r),n.notify(l),s}:"shift"===t?function(){let r,s;r=Reflect.apply(e[t],e,arguments),(s=proxiesToTargetsMap.get(r))&&targetsToObserved.get(s).revoke();for(let t,r,o=0,n=e.length;o<n;o++)(t=e[o])&&"object"==typeof t&&((r=targetsToObserved.get(proxiesToTargetsMap.get(t)))?r.ownKey=o:console.error("unexpectedly failed to resolve proxy -> target -> observed"));return n.notify([new DeleteChange(o.path.concat(0),s||r)]),s||r}:"unshift"===t?function(){let r,s,a,l=[];(r=Array.from(arguments)).forEach(function(e,t){e&&"object"==typeof e&&(r[t]=new Observed(e,t,o).proxy)}),s=Reflect.apply(e[t],e,r);for(let t,r=0,o=e.length;r<o;r++)(t=e[r])&&"object"==typeof t&&((a=targetsToObserved.get(proxiesToTargetsMap.get(t)))?a.ownKey=r:console.error("failed to resolve proxy -> target -> observed"));for(let t=0,n=r.length;t<n;t++)l.push(new InsertChange(o.path.concat(t),e[t]));return n.notify(l),s}:"reverse"===t?function(){let r;Reflect.apply(e[t],e,arguments);for(let t,o=0,n=e.length;o<n;o++)(t=e[o])&&"object"==typeof t&&((r=targetsToObserved.get(proxiesToTargetsMap.get(t)))?r.ownKey=o:console.error("failed to resolve proxy -> target -> observed"));return n.notify([new ReverseChange]),this}:"sort"===t?function(){let r;Reflect.apply(e[t],e,arguments);for(let t,o=0,n=e.length;o<n;o++)(t=e[o])&&"object"==typeof t&&((r=targetsToObserved.get(proxiesToTargetsMap.get(t)))?r.ownKey=o:console.error("failed to resolve proxy -> target -> observed"));return n.notify([new ShuffleChange]),this}:"fill"===t?function(){let r,s,a,l=[],p=arguments.length,i=e.length;r=p<2?0:arguments[1]<0?i+arguments[1]:arguments[1],s=p<3?i:arguments[2]<0?i+arguments[2]:arguments[2],a=e.slice(),Reflect.apply(e[t],e,arguments);for(let t,n,p=r;p<s;p++)(t=e[p])&&"object"==typeof t&&(e[p]=new Observed(t,p,o).proxy),a.hasOwnProperty(p)?((n=proxiesToTargetsMap.get(a[p]))&&targetsToObserved.get(n).revoke(),l.push(new UpdateChange(o.path.concat(p),e[p],n||a[p]))):l.push(new InsertChange(o.path.concat(p),e[p]));return n.notify(l),this}:"splice"===t?function(){let r,s,a,l,p,i,b,f,c=[],v=e.length;b=(r=Array.from(arguments)).length;for(let e,t=0;t<b;t++)e=r[t],t>1&&e&&"object"==typeof e&&(r[t]=new Observed(e,t,o).proxy);l=0===b?0:r[0]<0?v+r[0]:r[0],p=b<2?v-l:r[1],i=Math.max(b-2,0),s=Reflect.apply(e[t],e,r);for(let t,r=0;r<v;r++)(t=e[r])&&"object"==typeof t&&((a=targetsToObserved.get(proxiesToTargetsMap.get(t)))?a.ownKey=r:console.error("failed to resolve proxy -> target -> observed"));for(let e,t,r=0,o=s.length;r<o;r++)e=s[r],(t=proxiesToTargetsMap.get(e))&&(targetsToObserved.get(t).revoke(),s[r]=t);for(f=0;f<p;f++)f<i?c.push(new UpdateChange(o.path.concat(l+f),e[l+f],s[f])):c.push(new DeleteChange(o.path.concat(l+f),s[f]));for(;f<i;f++)c.push(new InsertChange(o.path.concat(l+f),e[l+f]));return n.notify(c),s}:Reflect.get(e,t)}function proxiedSet(e,t,r){let o,n,s=e.hasOwnProperty(t),a=e[t],l=targetsToObserved.get(e),p=observedToObservable.get(l.root);if((o=r&&"object"==typeof r&&!isNonObservable(r)?Reflect.set(e,t,new Observed(r,t,l).proxy):Reflect.set(e,t,r))&&((n=proxiesToTargetsMap.get(a))&&targetsToObserved.get(n).revoke(),p.hasListeners()&&!l.preventCallbacks)){let e=l.path.concat(t);p.notify([s?new UpdateChange(e,r,n||a):new InsertChange(e,r)])}return o}function proxiedDelete(e,t){let r,o,n=e[t],s=targetsToObserved.get(e),a=observedToObservable.get(s.root);if((r=Reflect.deleteProperty(e,t))&&((o=proxiesToTargetsMap.get(n))&&targetsToObserved.get(o).revoke(),a.hasListeners()&&!s.preventCallbacks)){let e=s.path.concat(t);a.notify([new DeleteChange(e,o||n)])}return r}function processArraySubgraph(e,t){for(let r,o=0,n=e.length;o<n;o++)(r=e[o])&&"object"==typeof r&&!isNonObservable(r)&&(e[o]=new Observed(r,o,t).proxy)}function processObjectSubgraph(e,t){let r=Object.keys(e);for(let o,n,s=0,a=r.length;s<a;s++)(n=e[o=r[s]])&&"object"==typeof n&&!isNonObservable(n)&&(e[o]=new Observed(n,o,t).proxy)}function Observed(e,t,r){let o,n,s;if(!e||"object"!=typeof e)throw new Error("Observed MUST be created from a non null object origin");if(r&&(void 0===t||null===t))throw new Error("any non-root (parent-less) Observed MUST have an own path; now parent is "+r+"; key is "+t);if(r&&!(r instanceof Observed))throw new Error("parent, when supplied, MUST be an instance of Observed");o=copyShallow(e),Array.isArray(o)?(processArraySubgraph(o,this),n=Proxy.revocable(o,{set:proxiedSet,get:proxiedArrayGet,deleteProperty:proxiedDelete})):(processObjectSubgraph(o,this),n=Proxy.revocable(o,{set:proxiedSet,deleteProperty:proxiedDelete})),s=n.proxy,targetsToObserved.set(o,this),proxiesToTargetsMap.set(s,o),Object.defineProperties(this,{revokable:{value:n},proxy:{value:s},parent:{value:r},ownKey:{value:t,writable:!0}})}function Observable(e){let t=!1,r=[];Object.defineProperties(e.proxy,{observe:{value:function(e){if(t)throw new TypeError("revoked Observable MAY NOT be observed anymore");if("function"!=typeof e)throw new Error("observer (callback) parameter MUST be a function");r.indexOf(e)<0?r.push(e):console.info("observer (callback) may be bound to an observable only once")}},unobserve:{value:function(){if(t)throw new TypeError("revoked Observable MAY NOT be unobserved anymore");if(arguments.length)for(let e,t=0,o=arguments.length;t<o;t++)(e=r.indexOf(arguments[t]))>=0&&r.splice(e,1);else r.splice(0,r.length)}},revoke:{value:function(){t?console.log("revoking of Observable effective only once"):(t=!0,e.revoke())}}}),Object.defineProperties(this,{hasListeners:{value:function(){return r.length>0}},notify:{value:function(e){for(let t,o=0,n=r.length;o<n;o++){t=r[o];try{t(e)}catch(e){console.error("one/some of the observing callbacks failed with ",e)}}}}})}function InsertChange(e,t){Object.defineProperties(this,{type:{value:"insert"},path:{value:e},value:{value:t}})}function UpdateChange(e,t,r){Object.defineProperties(this,{type:{value:"update"},path:{value:e},value:{value:t},oldValue:{value:r}})}function DeleteChange(e,t){Object.defineProperties(this,{type:{value:"delete"},path:{value:e},oldValue:{value:t}})}function ReverseChange(){Object.defineProperties(this,{type:{value:"reverse"}})}function ShuffleChange(){Object.defineProperties(this,{type:{value:"shuffle"}})}Object.defineProperty(Observed.prototype,"root",{get:function(){let e=this;for(;e.parent;)e=e.parent;return e}}),Object.defineProperty(Observed.prototype,"path",{get:function(){let e=[],t=this;for(;void 0!==t.ownKey;)e.unshift(t.ownKey),t=t.parent;return e}}),Object.defineProperty(Observed.prototype,"revoke",{value:function(){let e=proxiesToTargetsMap.get(this.proxy),t=Object.keys(e);this.revokable.revoke();for(let r,o,n=0,s=t.length;n<s;n++)r=t[n],(o=proxiesToTargetsMap.get(e[r]))&&(e[r]=targetsToObserved.get(o).revoke());return proxiesToTargetsMap.delete(this.proxy),targetsToObserved.delete(e),e}}),Object.defineProperty(Observable,"from",{value:function(e){if(!e||"object"!=typeof e)throw new Error("observable MAY ONLY be created from non-null object only");if("observe"in e||"unobserve"in e||"revoke"in e)throw new Error('target object MUST NOT have nor own neither inherited properties from the following list: "observe", "unobserve", "revoke"');if(isNonObservable(e))throw new Error(e+" found to be one of non-observable object types: "+nonObservables);let t=new Observed(e),r=new Observable(t);return observedToObservable.set(t,r),t.proxy}}),Object.freeze(Observable); |
@@ -22,3 +22,3 @@ const proxiesToTargetsMap = new Map(), | ||
result = function proxiedPop() { | ||
let poppedIndex, popResult, tmpTarget, changes; | ||
let poppedIndex, popResult, tmpTarget; | ||
poppedIndex = target.length - 1; | ||
@@ -30,4 +30,3 @@ popResult = Reflect.apply(target[key], target, arguments); | ||
} | ||
changes = [new DeleteChange(observed.path.concat(poppedIndex), tmpTarget || popResult)]; | ||
observable.notify(changes); | ||
observable.notify([new DeleteChange(observed.path.concat(poppedIndex), tmpTarget || popResult)]); | ||
return tmpTarget || popResult; | ||
@@ -53,3 +52,3 @@ }; | ||
result = function proxiedShift() { | ||
let shiftResult, changes, tmpTarget; | ||
let shiftResult, tmpTarget; | ||
shiftResult = Reflect.apply(target[key], target, arguments); | ||
@@ -73,4 +72,3 @@ tmpTarget = proxiesToTargetsMap.get(shiftResult); | ||
} | ||
changes = [new DeleteChange(observed.path.concat(0), tmpTarget || shiftResult)]; | ||
observable.notify(changes); | ||
observable.notify([new DeleteChange(observed.path.concat(0), tmpTarget || shiftResult)]); | ||
return tmpTarget || shiftResult; | ||
@@ -107,3 +105,3 @@ }; | ||
result = function proxiedReverse() { | ||
let changes, tmpObserved; | ||
let tmpObserved; | ||
Reflect.apply(target[key], target, arguments); | ||
@@ -121,4 +119,3 @@ for (let i = 0, l = target.length, item; i < l; i++) { | ||
} | ||
changes = [new ReverseChange()]; | ||
observable.notify(changes); | ||
observable.notify([new ReverseChange()]); | ||
return this; | ||
@@ -128,3 +125,3 @@ }; | ||
result = function proxiedSort() { | ||
let changes, tmpObserved; | ||
let tmpObserved; | ||
Reflect.apply(target[key], target, arguments); | ||
@@ -142,4 +139,3 @@ for (let i = 0, l = target.length, item; i < l; i++) { | ||
} | ||
changes = [new ShuffleChange()]; | ||
observable.notify(changes); | ||
observable.notify([new ShuffleChange()]); | ||
return this; | ||
@@ -260,8 +256,5 @@ }; | ||
if (observable.hasListeners) { | ||
let path = observed.path.concat(key), | ||
changes = [oldValuePresent ? new UpdateChange(path, value, oldTarget || oldValue) : new InsertChange(path, value)]; | ||
if (!observed.preventCallbacks) { | ||
observable.notify(changes); | ||
} | ||
if (observable.hasListeners() && !observed.preventCallbacks) { | ||
let path = observed.path.concat(key); | ||
observable.notify([oldValuePresent ? new UpdateChange(path, value, oldTarget || oldValue) : new InsertChange(path, value)]); | ||
} | ||
@@ -287,8 +280,5 @@ } | ||
if (observable.hasListeners) { | ||
let path = observed.path.concat(key), | ||
changes = [new DeleteChange(path, oldTarget || oldValue)]; | ||
if (!observed.preventCallbacks) { | ||
observable.notify(changes); | ||
} | ||
if (observable.hasListeners() && !observed.preventCallbacks) { | ||
let path = observed.path.concat(key); | ||
observable.notify([new DeleteChange(path, oldTarget || oldValue)]); | ||
} | ||
@@ -295,0 +285,0 @@ } |
@@ -1,1 +0,1 @@ | ||
const proxiesToTargetsMap=new Map,targetsToObserved=new Map,observedToObservable=new Map,nonObservables=["Date","Blob","Number","String","Boolean","Error","SyntaxError","TypeError","URIError","Function","Promise","RegExp"];function copyShallow(e){return Array.isArray(e)?e.slice():Object.assign({},e)}function isNonObservable(e){return nonObservables.indexOf(e.constructor.name)>=0}function proxiedArrayGet(e,t){let r,o=targetsToObserved.get(e),n=observedToObservable.get(o.root);return r="pop"===t?function(){let r,s,a,l;return r=e.length-1,s=Reflect.apply(e[t],e,arguments),(a=proxiesToTargetsMap.get(s))&&targetsToObserved.get(a).revoke(),l=[new DeleteChange(o.path.concat(r),a||s)],n.notify(l),a||s}:"push"===t?function(){let r,s,a,l=[];r=Array.from(arguments),a=e.length;for(let e,t=0,n=r.length;t<n;t++)(e=r[t])&&"object"==typeof e&&(r[t]=new Observed(e,a+t,o).proxy),l.push(new InsertChange(o.path.concat(a+t),e));return s=Reflect.apply(e[t],e,r),n.notify(l),s}:"shift"===t?function(){let r,s,a;r=Reflect.apply(e[t],e,arguments),(a=proxiesToTargetsMap.get(r))&&targetsToObserved.get(a).revoke();for(let t,r,o=0,n=e.length;o<n;o++)(t=e[o])&&"object"==typeof t&&((r=targetsToObserved.get(proxiesToTargetsMap.get(t)))?r.ownKey=o:console.error("unexpectedly failed to resolve proxy -> target -> observed"));return s=[new DeleteChange(o.path.concat(0),a||r)],n.notify(s),a||r}:"unshift"===t?function(){let r,s,a,l=[];(r=Array.from(arguments)).forEach(function(e,t){e&&"object"==typeof e&&(r[t]=new Observed(e,t,o).proxy)}),s=Reflect.apply(e[t],e,r);for(let t,r=0,o=e.length;r<o;r++)(t=e[r])&&"object"==typeof t&&((a=targetsToObserved.get(proxiesToTargetsMap.get(t)))?a.ownKey=r:console.error("failed to resolve proxy -> target -> observed"));for(let t=0,n=r.length;t<n;t++)l.push(new InsertChange(o.path.concat(t),e[t]));return n.notify(l),s}:"reverse"===t?function(){let r,o;Reflect.apply(e[t],e,arguments);for(let t,r=0,n=e.length;r<n;r++)(t=e[r])&&"object"==typeof t&&((o=targetsToObserved.get(proxiesToTargetsMap.get(t)))?o.ownKey=r:console.error("failed to resolve proxy -> target -> observed"));return r=[new ReverseChange],n.notify(r),this}:"sort"===t?function(){let r,o;Reflect.apply(e[t],e,arguments);for(let t,r=0,n=e.length;r<n;r++)(t=e[r])&&"object"==typeof t&&((o=targetsToObserved.get(proxiesToTargetsMap.get(t)))?o.ownKey=r:console.error("failed to resolve proxy -> target -> observed"));return r=[new ShuffleChange],n.notify(r),this}:"fill"===t?function(){let r,s,a,l=[],p=arguments.length,i=e.length;r=p<2?0:arguments[1]<0?i+arguments[1]:arguments[1],s=p<3?i:arguments[2]<0?i+arguments[2]:arguments[2],a=e.slice(),Reflect.apply(e[t],e,arguments);for(let t,n,p=r;p<s;p++)(t=e[p])&&"object"==typeof t&&(e[p]=new Observed(t,p,o).proxy),a.hasOwnProperty(p)?((n=proxiesToTargetsMap.get(a[p]))&&targetsToObserved.get(n).revoke(),l.push(new UpdateChange(o.path.concat(p),e[p],n||a[p]))):l.push(new InsertChange(o.path.concat(p),e[p]));return n.notify(l),this}:"splice"===t?function(){let r,s,a,l,p,i,b,f,c=[],v=e.length;b=(r=Array.from(arguments)).length;for(let e,t=0;t<b;t++)e=r[t],t>1&&e&&"object"==typeof e&&(r[t]=new Observed(e,t,o).proxy);l=0===b?0:r[0]<0?v+r[0]:r[0],p=b<2?v-l:r[1],i=Math.max(b-2,0),s=Reflect.apply(e[t],e,r);for(let t,r=0;r<v;r++)(t=e[r])&&"object"==typeof t&&((a=targetsToObserved.get(proxiesToTargetsMap.get(t)))?a.ownKey=r:console.error("failed to resolve proxy -> target -> observed"));for(let e,t,r=0,o=s.length;r<o;r++)e=s[r],(t=proxiesToTargetsMap.get(e))&&(targetsToObserved.get(t).revoke(),s[r]=t);for(f=0;f<p;f++)f<i?c.push(new UpdateChange(o.path.concat(l+f),e[l+f],s[f])):c.push(new DeleteChange(o.path.concat(l+f),s[f]));for(;f<i;f++)c.push(new InsertChange(o.path.concat(l+f),e[l+f]));return n.notify(c),s}:Reflect.get(e,t)}function proxiedSet(e,t,r){let o,n,s=e.hasOwnProperty(t),a=e[t],l=targetsToObserved.get(e),p=observedToObservable.get(l.root);if((o=r&&"object"==typeof r&&!isNonObservable(r)?Reflect.set(e,t,new Observed(r,t,l).proxy):Reflect.set(e,t,r))&&((n=proxiesToTargetsMap.get(a))&&targetsToObserved.get(n).revoke(),p.hasListeners)){let e=l.path.concat(t),o=[s?new UpdateChange(e,r,n||a):new InsertChange(e,r)];l.preventCallbacks||p.notify(o)}return o}function proxiedDelete(e,t){let r,o,n=e[t],s=targetsToObserved.get(e),a=observedToObservable.get(s.root);if((r=Reflect.deleteProperty(e,t))&&((o=proxiesToTargetsMap.get(n))&&targetsToObserved.get(o).revoke(),a.hasListeners)){let e=[new DeleteChange(s.path.concat(t),o||n)];s.preventCallbacks||a.notify(e)}return r}function processArraySubgraph(e,t){for(let r,o=0,n=e.length;o<n;o++)(r=e[o])&&"object"==typeof r&&!isNonObservable(r)&&(e[o]=new Observed(r,o,t).proxy)}function processObjectSubgraph(e,t){let r=Object.keys(e);for(let o,n,s=0,a=r.length;s<a;s++)(n=e[o=r[s]])&&"object"==typeof n&&!isNonObservable(n)&&(e[o]=new Observed(n,o,t).proxy)}function Observed(e,t,r){let o,n,s;if(!e||"object"!=typeof e)throw new Error("Observed MUST be created from a non null object origin");if(r&&(void 0===t||null===t))throw new Error("any non-root (parent-less) Observed MUST have an own path; now parent is "+r+"; key is "+t);if(r&&!(r instanceof Observed))throw new Error("parent, when supplied, MUST be an instance of Observed");o=copyShallow(e),Array.isArray(o)?(processArraySubgraph(o,this),n=Proxy.revocable(o,{set:proxiedSet,get:proxiedArrayGet,deleteProperty:proxiedDelete})):(processObjectSubgraph(o,this),n=Proxy.revocable(o,{set:proxiedSet,deleteProperty:proxiedDelete})),s=n.proxy,targetsToObserved.set(o,this),proxiesToTargetsMap.set(s,o),Object.defineProperties(this,{revokable:{value:n},proxy:{value:s},parent:{value:r},ownKey:{value:t,writable:!0}})}function Observable(e){let t=!1,r=[];Object.defineProperties(e.proxy,{observe:{value:function(e){if(t)throw new TypeError("revoked Observable MAY NOT be observed anymore");if("function"!=typeof e)throw new Error("observer (callback) parameter MUST be a function");r.indexOf(e)<0?r.push(e):console.info("observer (callback) may be bound to an observable only once")}},unobserve:{value:function(){if(t)throw new TypeError("revoked Observable MAY NOT be unobserved anymore");if(arguments.length)for(let e,t=0,o=arguments.length;t<o;t++)(e=r.indexOf(arguments[t]))>=0&&r.splice(e,1);else r.splice(0,r.length)}},revoke:{value:function(){t?console.log("revoking of Observable effective only once"):(t=!0,e.revoke())}}}),Object.defineProperties(this,{hasListeners:{value:function(){return r.length>0}},notify:{value:function(e){for(let t,o=0,n=r.length;o<n;o++){t=r[o];try{t(e)}catch(e){console.error("one/some of the observing callbacks failed with ",e)}}}}})}function InsertChange(e,t){Object.defineProperties(this,{type:{value:"insert"},path:{value:e},value:{value:t}})}function UpdateChange(e,t,r){Object.defineProperties(this,{type:{value:"update"},path:{value:e},value:{value:t},oldValue:{value:r}})}function DeleteChange(e,t){Object.defineProperties(this,{type:{value:"delete"},path:{value:e},oldValue:{value:t}})}function ReverseChange(){Object.defineProperties(this,{type:{value:"reverse"}})}function ShuffleChange(){Object.defineProperties(this,{type:{value:"shuffle"}})}module.exports=Observable,Object.defineProperty(Observed.prototype,"root",{get:function(){let e=this;for(;e.parent;)e=e.parent;return e}}),Object.defineProperty(Observed.prototype,"path",{get:function(){let e=[],t=this;for(;void 0!==t.ownKey;)e.unshift(t.ownKey),t=t.parent;return e}}),Object.defineProperty(Observed.prototype,"revoke",{value:function(){let e=proxiesToTargetsMap.get(this.proxy),t=Object.keys(e);this.revokable.revoke();for(let r,o,n=0,s=t.length;n<s;n++)r=t[n],(o=proxiesToTargetsMap.get(e[r]))&&(e[r]=targetsToObserved.get(o).revoke());return proxiesToTargetsMap.delete(this.proxy),targetsToObserved.delete(e),e}}),Object.defineProperty(Observable,"from",{value:function(e){if(!e||"object"!=typeof e)throw new Error("observable MAY ONLY be created from non-null object only");if("observe"in e||"unobserve"in e||"revoke"in e)throw new Error('target object MUST NOT have nor own neither inherited properties from the following list: "observe", "unobserve", "revoke"');if(isNonObservable(e))throw new Error(e+" found to be one of non-observable object types: "+nonObservables);let t=new Observed(e),r=new Observable(t);return observedToObservable.set(t,r),t.proxy}}),Object.freeze(Observable); | ||
const proxiesToTargetsMap=new Map,targetsToObserved=new Map,observedToObservable=new Map,nonObservables=["Date","Blob","Number","String","Boolean","Error","SyntaxError","TypeError","URIError","Function","Promise","RegExp"];function copyShallow(e){return Array.isArray(e)?e.slice():Object.assign({},e)}function isNonObservable(e){return nonObservables.indexOf(e.constructor.name)>=0}function proxiedArrayGet(e,t){let r,o=targetsToObserved.get(e),n=observedToObservable.get(o.root);return r="pop"===t?function(){let r,s,a;return r=e.length-1,s=Reflect.apply(e[t],e,arguments),(a=proxiesToTargetsMap.get(s))&&targetsToObserved.get(a).revoke(),n.notify([new DeleteChange(o.path.concat(r),a||s)]),a||s}:"push"===t?function(){let r,s,a,l=[];r=Array.from(arguments),a=e.length;for(let e,t=0,n=r.length;t<n;t++)(e=r[t])&&"object"==typeof e&&(r[t]=new Observed(e,a+t,o).proxy),l.push(new InsertChange(o.path.concat(a+t),e));return s=Reflect.apply(e[t],e,r),n.notify(l),s}:"shift"===t?function(){let r,s;r=Reflect.apply(e[t],e,arguments),(s=proxiesToTargetsMap.get(r))&&targetsToObserved.get(s).revoke();for(let t,r,o=0,n=e.length;o<n;o++)(t=e[o])&&"object"==typeof t&&((r=targetsToObserved.get(proxiesToTargetsMap.get(t)))?r.ownKey=o:console.error("unexpectedly failed to resolve proxy -> target -> observed"));return n.notify([new DeleteChange(o.path.concat(0),s||r)]),s||r}:"unshift"===t?function(){let r,s,a,l=[];(r=Array.from(arguments)).forEach(function(e,t){e&&"object"==typeof e&&(r[t]=new Observed(e,t,o).proxy)}),s=Reflect.apply(e[t],e,r);for(let t,r=0,o=e.length;r<o;r++)(t=e[r])&&"object"==typeof t&&((a=targetsToObserved.get(proxiesToTargetsMap.get(t)))?a.ownKey=r:console.error("failed to resolve proxy -> target -> observed"));for(let t=0,n=r.length;t<n;t++)l.push(new InsertChange(o.path.concat(t),e[t]));return n.notify(l),s}:"reverse"===t?function(){let r;Reflect.apply(e[t],e,arguments);for(let t,o=0,n=e.length;o<n;o++)(t=e[o])&&"object"==typeof t&&((r=targetsToObserved.get(proxiesToTargetsMap.get(t)))?r.ownKey=o:console.error("failed to resolve proxy -> target -> observed"));return n.notify([new ReverseChange]),this}:"sort"===t?function(){let r;Reflect.apply(e[t],e,arguments);for(let t,o=0,n=e.length;o<n;o++)(t=e[o])&&"object"==typeof t&&((r=targetsToObserved.get(proxiesToTargetsMap.get(t)))?r.ownKey=o:console.error("failed to resolve proxy -> target -> observed"));return n.notify([new ShuffleChange]),this}:"fill"===t?function(){let r,s,a,l=[],p=arguments.length,i=e.length;r=p<2?0:arguments[1]<0?i+arguments[1]:arguments[1],s=p<3?i:arguments[2]<0?i+arguments[2]:arguments[2],a=e.slice(),Reflect.apply(e[t],e,arguments);for(let t,n,p=r;p<s;p++)(t=e[p])&&"object"==typeof t&&(e[p]=new Observed(t,p,o).proxy),a.hasOwnProperty(p)?((n=proxiesToTargetsMap.get(a[p]))&&targetsToObserved.get(n).revoke(),l.push(new UpdateChange(o.path.concat(p),e[p],n||a[p]))):l.push(new InsertChange(o.path.concat(p),e[p]));return n.notify(l),this}:"splice"===t?function(){let r,s,a,l,p,i,b,f,c=[],v=e.length;b=(r=Array.from(arguments)).length;for(let e,t=0;t<b;t++)e=r[t],t>1&&e&&"object"==typeof e&&(r[t]=new Observed(e,t,o).proxy);l=0===b?0:r[0]<0?v+r[0]:r[0],p=b<2?v-l:r[1],i=Math.max(b-2,0),s=Reflect.apply(e[t],e,r);for(let t,r=0;r<v;r++)(t=e[r])&&"object"==typeof t&&((a=targetsToObserved.get(proxiesToTargetsMap.get(t)))?a.ownKey=r:console.error("failed to resolve proxy -> target -> observed"));for(let e,t,r=0,o=s.length;r<o;r++)e=s[r],(t=proxiesToTargetsMap.get(e))&&(targetsToObserved.get(t).revoke(),s[r]=t);for(f=0;f<p;f++)f<i?c.push(new UpdateChange(o.path.concat(l+f),e[l+f],s[f])):c.push(new DeleteChange(o.path.concat(l+f),s[f]));for(;f<i;f++)c.push(new InsertChange(o.path.concat(l+f),e[l+f]));return n.notify(c),s}:Reflect.get(e,t)}function proxiedSet(e,t,r){let o,n,s=e.hasOwnProperty(t),a=e[t],l=targetsToObserved.get(e),p=observedToObservable.get(l.root);if((o=r&&"object"==typeof r&&!isNonObservable(r)?Reflect.set(e,t,new Observed(r,t,l).proxy):Reflect.set(e,t,r))&&((n=proxiesToTargetsMap.get(a))&&targetsToObserved.get(n).revoke(),p.hasListeners()&&!l.preventCallbacks)){let e=l.path.concat(t);p.notify([s?new UpdateChange(e,r,n||a):new InsertChange(e,r)])}return o}function proxiedDelete(e,t){let r,o,n=e[t],s=targetsToObserved.get(e),a=observedToObservable.get(s.root);if((r=Reflect.deleteProperty(e,t))&&((o=proxiesToTargetsMap.get(n))&&targetsToObserved.get(o).revoke(),a.hasListeners()&&!s.preventCallbacks)){let e=s.path.concat(t);a.notify([new DeleteChange(e,o||n)])}return r}function processArraySubgraph(e,t){for(let r,o=0,n=e.length;o<n;o++)(r=e[o])&&"object"==typeof r&&!isNonObservable(r)&&(e[o]=new Observed(r,o,t).proxy)}function processObjectSubgraph(e,t){let r=Object.keys(e);for(let o,n,s=0,a=r.length;s<a;s++)(n=e[o=r[s]])&&"object"==typeof n&&!isNonObservable(n)&&(e[o]=new Observed(n,o,t).proxy)}function Observed(e,t,r){let o,n,s;if(!e||"object"!=typeof e)throw new Error("Observed MUST be created from a non null object origin");if(r&&(void 0===t||null===t))throw new Error("any non-root (parent-less) Observed MUST have an own path; now parent is "+r+"; key is "+t);if(r&&!(r instanceof Observed))throw new Error("parent, when supplied, MUST be an instance of Observed");o=copyShallow(e),Array.isArray(o)?(processArraySubgraph(o,this),n=Proxy.revocable(o,{set:proxiedSet,get:proxiedArrayGet,deleteProperty:proxiedDelete})):(processObjectSubgraph(o,this),n=Proxy.revocable(o,{set:proxiedSet,deleteProperty:proxiedDelete})),s=n.proxy,targetsToObserved.set(o,this),proxiesToTargetsMap.set(s,o),Object.defineProperties(this,{revokable:{value:n},proxy:{value:s},parent:{value:r},ownKey:{value:t,writable:!0}})}function Observable(e){let t=!1,r=[];Object.defineProperties(e.proxy,{observe:{value:function(e){if(t)throw new TypeError("revoked Observable MAY NOT be observed anymore");if("function"!=typeof e)throw new Error("observer (callback) parameter MUST be a function");r.indexOf(e)<0?r.push(e):console.info("observer (callback) may be bound to an observable only once")}},unobserve:{value:function(){if(t)throw new TypeError("revoked Observable MAY NOT be unobserved anymore");if(arguments.length)for(let e,t=0,o=arguments.length;t<o;t++)(e=r.indexOf(arguments[t]))>=0&&r.splice(e,1);else r.splice(0,r.length)}},revoke:{value:function(){t?console.log("revoking of Observable effective only once"):(t=!0,e.revoke())}}}),Object.defineProperties(this,{hasListeners:{value:function(){return r.length>0}},notify:{value:function(e){for(let t,o=0,n=r.length;o<n;o++){t=r[o];try{t(e)}catch(e){console.error("one/some of the observing callbacks failed with ",e)}}}}})}function InsertChange(e,t){Object.defineProperties(this,{type:{value:"insert"},path:{value:e},value:{value:t}})}function UpdateChange(e,t,r){Object.defineProperties(this,{type:{value:"update"},path:{value:e},value:{value:t},oldValue:{value:r}})}function DeleteChange(e,t){Object.defineProperties(this,{type:{value:"delete"},path:{value:e},oldValue:{value:t}})}function ReverseChange(){Object.defineProperties(this,{type:{value:"reverse"}})}function ShuffleChange(){Object.defineProperties(this,{type:{value:"shuffle"}})}module.exports=Observable,Object.defineProperty(Observed.prototype,"root",{get:function(){let e=this;for(;e.parent;)e=e.parent;return e}}),Object.defineProperty(Observed.prototype,"path",{get:function(){let e=[],t=this;for(;void 0!==t.ownKey;)e.unshift(t.ownKey),t=t.parent;return e}}),Object.defineProperty(Observed.prototype,"revoke",{value:function(){let e=proxiesToTargetsMap.get(this.proxy),t=Object.keys(e);this.revokable.revoke();for(let r,o,n=0,s=t.length;n<s;n++)r=t[n],(o=proxiesToTargetsMap.get(e[r]))&&(e[r]=targetsToObserved.get(o).revoke());return proxiesToTargetsMap.delete(this.proxy),targetsToObserved.delete(e),e}}),Object.defineProperty(Observable,"from",{value:function(e){if(!e||"object"!=typeof e)throw new Error("observable MAY ONLY be created from non-null object only");if("observe"in e||"unobserve"in e||"revoke"in e)throw new Error('target object MUST NOT have nor own neither inherited properties from the following list: "observe", "unobserve", "revoke"');if(isNonObservable(e))throw new Error(e+" found to be one of non-observable object types: "+nonObservables);let t=new Observed(e),r=new Observable(t);return observedToObservable.set(t,r),t.proxy}}),Object.freeze(Observable); |
@@ -24,3 +24,3 @@ (() => { | ||
result = function proxiedPop() { | ||
let poppedIndex, popResult, tmpTarget, changes; | ||
let poppedIndex, popResult, tmpTarget; | ||
poppedIndex = target.length - 1; | ||
@@ -32,4 +32,3 @@ popResult = Reflect.apply(target[key], target, arguments); | ||
} | ||
changes = [new DeleteChange(observed.path.concat(poppedIndex), tmpTarget || popResult)]; | ||
observable.notify(changes); | ||
observable.notify([new DeleteChange(observed.path.concat(poppedIndex), tmpTarget || popResult)]); | ||
return tmpTarget || popResult; | ||
@@ -55,3 +54,3 @@ }; | ||
result = function proxiedShift() { | ||
let shiftResult, changes, tmpTarget; | ||
let shiftResult, tmpTarget; | ||
shiftResult = Reflect.apply(target[key], target, arguments); | ||
@@ -75,4 +74,3 @@ tmpTarget = proxiesToTargetsMap.get(shiftResult); | ||
} | ||
changes = [new DeleteChange(observed.path.concat(0), tmpTarget || shiftResult)]; | ||
observable.notify(changes); | ||
observable.notify([new DeleteChange(observed.path.concat(0), tmpTarget || shiftResult)]); | ||
return tmpTarget || shiftResult; | ||
@@ -109,3 +107,3 @@ }; | ||
result = function proxiedReverse() { | ||
let changes, tmpObserved; | ||
let tmpObserved; | ||
Reflect.apply(target[key], target, arguments); | ||
@@ -123,4 +121,3 @@ for (let i = 0, l = target.length, item; i < l; i++) { | ||
} | ||
changes = [new ReverseChange()]; | ||
observable.notify(changes); | ||
observable.notify([new ReverseChange()]); | ||
return this; | ||
@@ -130,3 +127,3 @@ }; | ||
result = function proxiedSort() { | ||
let changes, tmpObserved; | ||
let tmpObserved; | ||
Reflect.apply(target[key], target, arguments); | ||
@@ -144,4 +141,3 @@ for (let i = 0, l = target.length, item; i < l; i++) { | ||
} | ||
changes = [new ShuffleChange()]; | ||
observable.notify(changes); | ||
observable.notify([new ShuffleChange()]); | ||
return this; | ||
@@ -262,8 +258,5 @@ }; | ||
if (observable.hasListeners) { | ||
let path = observed.path.concat(key), | ||
changes = [oldValuePresent ? new UpdateChange(path, value, oldTarget || oldValue) : new InsertChange(path, value)]; | ||
if (!observed.preventCallbacks) { | ||
observable.notify(changes); | ||
} | ||
if (observable.hasListeners() && !observed.preventCallbacks) { | ||
let path = observed.path.concat(key); | ||
observable.notify([oldValuePresent ? new UpdateChange(path, value, oldTarget || oldValue) : new InsertChange(path, value)]); | ||
} | ||
@@ -289,8 +282,5 @@ } | ||
if (observable.hasListeners) { | ||
let path = observed.path.concat(key), | ||
changes = [new DeleteChange(path, oldTarget || oldValue)]; | ||
if (!observed.preventCallbacks) { | ||
observable.notify(changes); | ||
} | ||
if (observable.hasListeners() && !observed.preventCallbacks) { | ||
let path = observed.path.concat(key); | ||
observable.notify([new DeleteChange(path, oldTarget || oldValue)]); | ||
} | ||
@@ -322,3 +312,3 @@ } | ||
// CLASSES | ||
// | ||
function Observed(origin, ownKey, parent) { | ||
@@ -325,0 +315,0 @@ let targetClone, revokable, proxy; |
@@ -1,1 +0,1 @@ | ||
(()=>{"use strict";const e=this||window,t=new Map,o=new Map,r=new Map,n=["Date","Blob","Number","String","Boolean","Error","SyntaxError","TypeError","URIError","Function","Promise","RegExp"];function l(e){return n.indexOf(e.constructor.name)>=0}function i(e,n){let l,i=o.get(e),f=r.get(i.root);return l="pop"===n?function(){let r,l,a,c;return r=e.length-1,l=Reflect.apply(e[n],e,arguments),(a=t.get(l))&&o.get(a).revoke(),c=[new y(i.path.concat(r),a||l)],f.notify(c),a||l}:"push"===n?function(){let t,o,r,l=[];t=Array.from(arguments),r=e.length;for(let e,o=0,n=t.length;o<n;o++)(e=t[o])&&"object"==typeof e&&(t[o]=new c(e,r+o,i).proxy),l.push(new s(i.path.concat(r+o),e));return o=Reflect.apply(e[n],e,t),f.notify(l),o}:"shift"===n?function(){let r,l,a;r=Reflect.apply(e[n],e,arguments),(a=t.get(r))&&o.get(a).revoke();for(let r,n,l=0,i=e.length;l<i;l++)(r=e[l])&&"object"==typeof r&&((n=o.get(t.get(r)))?n.ownKey=l:console.error("unexpectedly failed to resolve proxy -> target -> observed"));return l=[new y(i.path.concat(0),a||r)],f.notify(l),a||r}:"unshift"===n?function(){let r,l,a,p=[];(r=Array.from(arguments)).forEach(function(e,t){e&&"object"==typeof e&&(r[t]=new c(e,t,i).proxy)}),l=Reflect.apply(e[n],e,r);for(let r,n=0,l=e.length;n<l;n++)(r=e[n])&&"object"==typeof r&&((a=o.get(t.get(r)))?a.ownKey=n:console.error("failed to resolve proxy -> target -> observed"));for(let t=0,o=r.length;t<o;t++)p.push(new s(i.path.concat(t),e[t]));return f.notify(p),l}:"reverse"===n?function(){let r,l;Reflect.apply(e[n],e,arguments);for(let r,n=0,i=e.length;n<i;n++)(r=e[n])&&"object"==typeof r&&((l=o.get(t.get(r)))?l.ownKey=n:console.error("failed to resolve proxy -> target -> observed"));return r=[new function(){Object.defineProperties(this,{type:{value:"reverse"}})}],f.notify(r),this}:"sort"===n?function(){let r,l;Reflect.apply(e[n],e,arguments);for(let r,n=0,i=e.length;n<i;n++)(r=e[n])&&"object"==typeof r&&((l=o.get(t.get(r)))?l.ownKey=n:console.error("failed to resolve proxy -> target -> observed"));return r=[new function(){Object.defineProperties(this,{type:{value:"shuffle"}})}],f.notify(r),this}:"fill"===n?function(){let r,l,a,p=[],y=arguments.length,h=e.length;r=y<2?0:arguments[1]<0?h+arguments[1]:arguments[1],l=y<3?h:arguments[2]<0?h+arguments[2]:arguments[2],a=e.slice(),Reflect.apply(e[n],e,arguments);for(let n,f,y=r;y<l;y++)(n=e[y])&&"object"==typeof n&&(e[y]=new c(n,y,i).proxy),a.hasOwnProperty(y)?((f=t.get(a[y]))&&o.get(f).revoke(),p.push(new u(i.path.concat(y),e[y],f||a[y]))):p.push(new s(i.path.concat(y),e[y]));return f.notify(p),this}:"splice"===n?function(){let r,l,a,p,h,b,v,g,w=[],d=e.length;v=(r=Array.from(arguments)).length;for(let e,t=0;t<v;t++)e=r[t],t>1&&e&&"object"==typeof e&&(r[t]=new c(e,t,i).proxy);p=0===v?0:r[0]<0?d+r[0]:r[0],h=v<2?d-p:r[1],b=Math.max(v-2,0),l=Reflect.apply(e[n],e,r);for(let r,n=0;n<d;n++)(r=e[n])&&"object"==typeof r&&((a=o.get(t.get(r)))?a.ownKey=n:console.error("failed to resolve proxy -> target -> observed"));for(let e,r,n=0,i=l.length;n<i;n++)e=l[n],(r=t.get(e))&&(o.get(r).revoke(),l[n]=r);for(g=0;g<h;g++)g<b?w.push(new u(i.path.concat(p+g),e[p+g],l[g])):w.push(new y(i.path.concat(p+g),l[g]));for(;g<b;g++)w.push(new s(i.path.concat(p+g),e[p+g]));return f.notify(w),l}:Reflect.get(e,n)}function f(e,n,i){let f,a,p=e.hasOwnProperty(n),y=e[n],h=o.get(e),b=r.get(h.root);if((f=i&&"object"==typeof i&&!l(i)?Reflect.set(e,n,new c(i,n,h).proxy):Reflect.set(e,n,i))&&((a=t.get(y))&&o.get(a).revoke(),b.hasListeners)){let e=h.path.concat(n),t=[p?new u(e,i,a||y):new s(e,i)];h.preventCallbacks||b.notify(t)}return f}function a(e,n){let l,i,f=e[n],a=o.get(e),c=r.get(a.root);if((l=Reflect.deleteProperty(e,n))&&((i=t.get(f))&&o.get(i).revoke(),c.hasListeners)){let e=[new y(a.path.concat(n),i||f)];a.preventCallbacks||c.notify(e)}return l}function c(e,r,n){let p,s,u;if(!e||"object"!=typeof e)throw new Error("Observed MUST be created from a non null object origin");if(n&&(void 0===r||null===r))throw new Error("any non-root (parent-less) Observed MUST have an own path; now parent is "+n+"; key is "+r);if(n&&!(n instanceof c))throw new Error("parent, when supplied, MUST be an instance of Observed");var y;y=e,p=Array.isArray(y)?y.slice():Object.assign({},y),Array.isArray(p)?(!function(e,t){for(let o,r=0,n=e.length;r<n;r++)(o=e[r])&&"object"==typeof o&&!l(o)&&(e[r]=new c(o,r,t).proxy)}(p,this),s=Proxy.revocable(p,{set:f,get:i,deleteProperty:a})):(!function(e,t){let o=Object.keys(e);for(let r,n,i=0,f=o.length;i<f;i++)(n=e[r=o[i]])&&"object"==typeof n&&!l(n)&&(e[r]=new c(n,r,t).proxy)}(p,this),s=Proxy.revocable(p,{set:f,deleteProperty:a})),u=s.proxy,o.set(p,this),t.set(u,p),Object.defineProperties(this,{revokable:{value:s},proxy:{value:u},parent:{value:n},ownKey:{value:r,writable:!0}})}function p(e){let t=!1,o=[];Object.defineProperties(e.proxy,{observe:{value:function(e){if(t)throw new TypeError("revoked Observable MAY NOT be observed anymore");if("function"!=typeof e)throw new Error("observer (callback) parameter MUST be a function");o.indexOf(e)<0?o.push(e):console.info("observer (callback) may be bound to an observable only once")}},unobserve:{value:function(){if(t)throw new TypeError("revoked Observable MAY NOT be unobserved anymore");if(arguments.length)for(let e,t=0,r=arguments.length;t<r;t++)(e=o.indexOf(arguments[t]))>=0&&o.splice(e,1);else o.splice(0,o.length)}},revoke:{value:function(){t?console.log("revoking of Observable effective only once"):(t=!0,e.revoke())}}}),Object.defineProperties(this,{hasListeners:{value:function(){return o.length>0}},notify:{value:function(e){for(let t,r=0,n=o.length;r<n;r++){t=o[r];try{t(e)}catch(e){console.error("one/some of the observing callbacks failed with ",e)}}}}})}function s(e,t){Object.defineProperties(this,{type:{value:"insert"},path:{value:e},value:{value:t}})}function u(e,t,o){Object.defineProperties(this,{type:{value:"update"},path:{value:e},value:{value:t},oldValue:{value:o}})}function y(e,t){Object.defineProperties(this,{type:{value:"delete"},path:{value:e},oldValue:{value:t}})}Object.defineProperty(c.prototype,"root",{get:function(){let e=this;for(;e.parent;)e=e.parent;return e}}),Object.defineProperty(c.prototype,"path",{get:function(){let e=[],t=this;for(;void 0!==t.ownKey;)e.unshift(t.ownKey),t=t.parent;return e}}),Object.defineProperty(c.prototype,"revoke",{value:function(){let e=t.get(this.proxy),r=Object.keys(e);this.revokable.revoke();for(let n,l,i=0,f=r.length;i<f;i++)n=r[i],(l=t.get(e[n]))&&(e[n]=o.get(l).revoke());return t.delete(this.proxy),o.delete(e),e}}),Object.defineProperty(p,"from",{value:function(e){if(!e||"object"!=typeof e)throw new Error("observable MAY ONLY be created from non-null object only");if("observe"in e||"unobserve"in e||"revoke"in e)throw new Error('target object MUST NOT have nor own neither inherited properties from the following list: "observe", "unobserve", "revoke"');if(l(e))throw new Error(e+" found to be one of non-observable object types: "+n);let t=new c(e),o=new p(t);return r.set(t,o),t.proxy}}),Object.defineProperty(e,"Observable",{value:p})})(); | ||
(()=>{"use strict";const e=this||window,t=new Map,o=new Map,r=new Map,n=["Date","Blob","Number","String","Boolean","Error","SyntaxError","TypeError","URIError","Function","Promise","RegExp"];function l(e){return n.indexOf(e.constructor.name)>=0}function i(e,n){let l,i=o.get(e),f=r.get(i.root);return l="pop"===n?function(){let r,l,a;return r=e.length-1,l=Reflect.apply(e[n],e,arguments),(a=t.get(l))&&o.get(a).revoke(),f.notify([new y(i.path.concat(r),a||l)]),a||l}:"push"===n?function(){let t,o,r,l=[];t=Array.from(arguments),r=e.length;for(let e,o=0,n=t.length;o<n;o++)(e=t[o])&&"object"==typeof e&&(t[o]=new c(e,r+o,i).proxy),l.push(new s(i.path.concat(r+o),e));return o=Reflect.apply(e[n],e,t),f.notify(l),o}:"shift"===n?function(){let r,l;r=Reflect.apply(e[n],e,arguments),(l=t.get(r))&&o.get(l).revoke();for(let r,n,l=0,i=e.length;l<i;l++)(r=e[l])&&"object"==typeof r&&((n=o.get(t.get(r)))?n.ownKey=l:console.error("unexpectedly failed to resolve proxy -> target -> observed"));return f.notify([new y(i.path.concat(0),l||r)]),l||r}:"unshift"===n?function(){let r,l,a,p=[];(r=Array.from(arguments)).forEach(function(e,t){e&&"object"==typeof e&&(r[t]=new c(e,t,i).proxy)}),l=Reflect.apply(e[n],e,r);for(let r,n=0,l=e.length;n<l;n++)(r=e[n])&&"object"==typeof r&&((a=o.get(t.get(r)))?a.ownKey=n:console.error("failed to resolve proxy -> target -> observed"));for(let t=0,o=r.length;t<o;t++)p.push(new s(i.path.concat(t),e[t]));return f.notify(p),l}:"reverse"===n?function(){let r;Reflect.apply(e[n],e,arguments);for(let n,l=0,i=e.length;l<i;l++)(n=e[l])&&"object"==typeof n&&((r=o.get(t.get(n)))?r.ownKey=l:console.error("failed to resolve proxy -> target -> observed"));return f.notify([new function(){Object.defineProperties(this,{type:{value:"reverse"}})}]),this}:"sort"===n?function(){let r;Reflect.apply(e[n],e,arguments);for(let n,l=0,i=e.length;l<i;l++)(n=e[l])&&"object"==typeof n&&((r=o.get(t.get(n)))?r.ownKey=l:console.error("failed to resolve proxy -> target -> observed"));return f.notify([new function(){Object.defineProperties(this,{type:{value:"shuffle"}})}]),this}:"fill"===n?function(){let r,l,a,p=[],y=arguments.length,h=e.length;r=y<2?0:arguments[1]<0?h+arguments[1]:arguments[1],l=y<3?h:arguments[2]<0?h+arguments[2]:arguments[2],a=e.slice(),Reflect.apply(e[n],e,arguments);for(let n,f,y=r;y<l;y++)(n=e[y])&&"object"==typeof n&&(e[y]=new c(n,y,i).proxy),a.hasOwnProperty(y)?((f=t.get(a[y]))&&o.get(f).revoke(),p.push(new u(i.path.concat(y),e[y],f||a[y]))):p.push(new s(i.path.concat(y),e[y]));return f.notify(p),this}:"splice"===n?function(){let r,l,a,p,h,b,v,g,w=[],d=e.length;v=(r=Array.from(arguments)).length;for(let e,t=0;t<v;t++)e=r[t],t>1&&e&&"object"==typeof e&&(r[t]=new c(e,t,i).proxy);p=0===v?0:r[0]<0?d+r[0]:r[0],h=v<2?d-p:r[1],b=Math.max(v-2,0),l=Reflect.apply(e[n],e,r);for(let r,n=0;n<d;n++)(r=e[n])&&"object"==typeof r&&((a=o.get(t.get(r)))?a.ownKey=n:console.error("failed to resolve proxy -> target -> observed"));for(let e,r,n=0,i=l.length;n<i;n++)e=l[n],(r=t.get(e))&&(o.get(r).revoke(),l[n]=r);for(g=0;g<h;g++)g<b?w.push(new u(i.path.concat(p+g),e[p+g],l[g])):w.push(new y(i.path.concat(p+g),l[g]));for(;g<b;g++)w.push(new s(i.path.concat(p+g),e[p+g]));return f.notify(w),l}:Reflect.get(e,n)}function f(e,n,i){let f,a,p=e.hasOwnProperty(n),y=e[n],h=o.get(e),b=r.get(h.root);if((f=i&&"object"==typeof i&&!l(i)?Reflect.set(e,n,new c(i,n,h).proxy):Reflect.set(e,n,i))&&((a=t.get(y))&&o.get(a).revoke(),b.hasListeners()&&!h.preventCallbacks)){let e=h.path.concat(n);b.notify([p?new u(e,i,a||y):new s(e,i)])}return f}function a(e,n){let l,i,f=e[n],a=o.get(e),c=r.get(a.root);if((l=Reflect.deleteProperty(e,n))&&((i=t.get(f))&&o.get(i).revoke(),c.hasListeners()&&!a.preventCallbacks)){let e=a.path.concat(n);c.notify([new y(e,i||f)])}return l}function c(e,r,n){let p,s,u;if(!e||"object"!=typeof e)throw new Error("Observed MUST be created from a non null object origin");if(n&&(void 0===r||null===r))throw new Error("any non-root (parent-less) Observed MUST have an own path; now parent is "+n+"; key is "+r);if(n&&!(n instanceof c))throw new Error("parent, when supplied, MUST be an instance of Observed");var y;y=e,p=Array.isArray(y)?y.slice():Object.assign({},y),Array.isArray(p)?(!function(e,t){for(let o,r=0,n=e.length;r<n;r++)(o=e[r])&&"object"==typeof o&&!l(o)&&(e[r]=new c(o,r,t).proxy)}(p,this),s=Proxy.revocable(p,{set:f,get:i,deleteProperty:a})):(!function(e,t){let o=Object.keys(e);for(let r,n,i=0,f=o.length;i<f;i++)(n=e[r=o[i]])&&"object"==typeof n&&!l(n)&&(e[r]=new c(n,r,t).proxy)}(p,this),s=Proxy.revocable(p,{set:f,deleteProperty:a})),u=s.proxy,o.set(p,this),t.set(u,p),Object.defineProperties(this,{revokable:{value:s},proxy:{value:u},parent:{value:n},ownKey:{value:r,writable:!0}})}function p(e){let t=!1,o=[];Object.defineProperties(e.proxy,{observe:{value:function(e){if(t)throw new TypeError("revoked Observable MAY NOT be observed anymore");if("function"!=typeof e)throw new Error("observer (callback) parameter MUST be a function");o.indexOf(e)<0?o.push(e):console.info("observer (callback) may be bound to an observable only once")}},unobserve:{value:function(){if(t)throw new TypeError("revoked Observable MAY NOT be unobserved anymore");if(arguments.length)for(let e,t=0,r=arguments.length;t<r;t++)(e=o.indexOf(arguments[t]))>=0&&o.splice(e,1);else o.splice(0,o.length)}},revoke:{value:function(){t?console.log("revoking of Observable effective only once"):(t=!0,e.revoke())}}}),Object.defineProperties(this,{hasListeners:{value:function(){return o.length>0}},notify:{value:function(e){for(let t,r=0,n=o.length;r<n;r++){t=o[r];try{t(e)}catch(e){console.error("one/some of the observing callbacks failed with ",e)}}}}})}function s(e,t){Object.defineProperties(this,{type:{value:"insert"},path:{value:e},value:{value:t}})}function u(e,t,o){Object.defineProperties(this,{type:{value:"update"},path:{value:e},value:{value:t},oldValue:{value:o}})}function y(e,t){Object.defineProperties(this,{type:{value:"delete"},path:{value:e},oldValue:{value:t}})}Object.defineProperty(c.prototype,"root",{get:function(){let e=this;for(;e.parent;)e=e.parent;return e}}),Object.defineProperty(c.prototype,"path",{get:function(){let e=[],t=this;for(;void 0!==t.ownKey;)e.unshift(t.ownKey),t=t.parent;return e}}),Object.defineProperty(c.prototype,"revoke",{value:function(){let e=t.get(this.proxy),r=Object.keys(e);this.revokable.revoke();for(let n,l,i=0,f=r.length;i<f;i++)n=r[i],(l=t.get(e[n]))&&(e[n]=o.get(l).revoke());return t.delete(this.proxy),o.delete(e),e}}),Object.defineProperty(p,"from",{value:function(e){if(!e||"object"!=typeof e)throw new Error("observable MAY ONLY be created from non-null object only");if("observe"in e||"unobserve"in e||"revoke"in e)throw new Error('target object MUST NOT have nor own neither inherited properties from the following list: "observe", "unobserve", "revoke"');if(l(e))throw new Error(e+" found to be one of non-observable object types: "+n);let t=new c(e),o=new p(t);return r.set(t,o),t.proxy}}),Object.defineProperty(e,"Observable",{value:p})})(); |
{ | ||
"name": "object-observer", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Object observer utility provides simple means to (deeply) observe specified object/array changes; implemented via native Proxy; changes delivered in a synchronous way", | ||
@@ -10,2 +10,4 @@ "keywords": [ | ||
"observer", | ||
"object observe", | ||
"object.observe", | ||
"observable", | ||
@@ -50,4 +52,5 @@ "changes", | ||
"uglify-es": "^3.3.9", | ||
"just-test": "^0.1.0" | ||
"just-test": "^0.1.0", | ||
"puppeteer": "^1.8.0" | ||
} | ||
} |
@@ -26,2 +26,5 @@ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) | ||
- __1.0.2__ | ||
- Removed named export, only a default export/import is available (see docs below) | ||
- __1.0.1__ | ||
@@ -34,5 +37,2 @@ - Added ES6 module packaging (both regular and minified) | ||
- __0.2.5__ | ||
- Fix: [issue #8](https://github.com/gullerya/object-observer/issues/8) - incorrect `oldValue` supplied in `update`/`delete` events when handling inner object/s sub-graph | ||
For a short preview you may want to play with this [JSFiddle](https://jsfiddle.net/gullerya/5a4tyoqs/). | ||
@@ -42,5 +42,5 @@ | ||
You have few ways to load the library: as an __ES6 module__ (named or default, pay attention to the __`module`__ / __`node-module`__ in the path) or as a __regular script__ (into a 'window' global scope, or a custom scope provided by you). | ||
You have few ways to load the library: as an __ES6 module__ (pay attention to the __`module`__ / __`node-module`__ in the path) or as a __regular script__ (into a 'window' global scope, or a custom scope provided by you). | ||
* ES6 module - default import (__preferred__): | ||
* ES6 module (__preferred__): | ||
```javascript | ||
@@ -54,7 +54,2 @@ // browser | ||
* ES6 module - named import: | ||
```javascript | ||
import {Observable as Obsrvbl} from 'dist/module/object-observer.min.js'; | ||
``` | ||
* Simple a reference (script tag) to the `object-observer.min.js`/`object-observer.js` in your `HTML` will load it into the __global scope__: | ||
@@ -120,8 +115,4 @@ ```html | ||
Changes delivered always as an array. Changes MAY NOT be null. Changes MAY be an empty array. | ||
Each change is a defined, non-null object, having: | ||
- `type` - one of the following: 'insert', 'update', 'delete', 'shuffle' or 'reverse' | ||
- `path` - path to the changed property represented as an __Array__ of nodes (see examples below) | ||
- `value` - new value; not available in 'delete', 'shuffle' and 'reverse' changes | ||
- `oldValue` - old value; not available in 'insert', 'shuffle' or 'reverse' changes | ||
Changes delivered always as a never-null-nor-empty array of [__`Change`__](#change-instance-properties) objects. | ||
Each change is a defined, non-null object, see `Change` definition below. | ||
@@ -137,3 +128,3 @@ - __`unobserve`__ - receives a _function/s_ which previously was/were registered as an observer/s and removes it/them. If _no arguments_ passed, all observers will be removed: | ||
- __`revoke`__ - parameterless. All of the proxies along the observed graph will be revoked and thus become unusable. `observe` and `unobserve` methods will mimic the revoked `Proxy` behaviour and throw `TypeError` if used on the revoked `Observable`. Subsequent `revoke` invokations will have no effect: | ||
- __`revoke`__ - parameterless. All of the proxies along the observed graph will be revoked and thus become unusable. `observe` and `unobserve` methods will mimic the revoked `Proxy` behaviour and throw `TypeError` if used on the revoked `Observable`. Subsequent `revoke` invocations will have no effect: | ||
```javascript | ||
@@ -145,2 +136,10 @@ ... | ||
##### `Change` instance properties | ||
- __`type`__ - one of the following: 'insert', 'update', 'delete', 'shuffle' or 'reverse' | ||
- __`path`__ - path to the changed property represented as an __Array__ of nodes (see examples below) | ||
- __`value`__ - new value; not available in 'delete', 'shuffle' and 'reverse' changes | ||
- __`oldValue`__ - old value; not available in 'insert', 'shuffle' or 'reverse' changes | ||
# Examples | ||
@@ -147,0 +146,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
82867
10
1359
211