proxy-state-tree
Advanced tools
Comparing version 6.3.0-1615750082257 to 6.3.0-1624521495651
@@ -1,1 +0,1 @@ | ||
!function(t){var e={};function r(i){if(e[i])return e[i].exports;var s=e[i]={i:i,l:!1,exports:{}};return t[i].call(s.exports,s,s.exports,r),s.l=!0,s.exports}r.m=t,r.c=e,r.d=function(t,e,i){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:i})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var i=Object.create(null);if(r.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var s in t)r.d(i,s,function(e){return t[e]}.bind(null,s));return i},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){r.r(e);const i=(()=>{let t;try{t="production"}catch(e){t="development"}return t})(),s=Symbol("IS_PROXY"),n=Symbol("PATH"),a=Symbol("VALUE"),o=Symbol("PROXY_TREE"),c=new Set(["push","shift","pop","unshift","splice","reverse","sort","copyWithin"]),h=t=>t&&t[s]?t[a]:t,u=t=>"object"==typeof t&&null!==t&&!Array.isArray(t)&&"Object"!==t.constructor.name&&Object.isExtensible(t),l=t=>void 0!==t&&(!u(t)||u(t)&&!(t instanceof Date)&&!(t instanceof Map)&&!(t instanceof Set));class p{constructor(t){this.tree=t,this.CACHED_PROXY=Symbol("CACHED_PROXY"),this.delimiter=t.master.options.delimiter,this.ssr=Boolean(t.master.options.ssr)}concat(t,e){return t?t+this.delimiter+e:e}ensureMutationTrackingIsEnabled(t){if("production"!==i&&this.tree.master.options.devmode&&!this.tree.canMutate())throw new Error(`proxy-state-tree - You are mutating the path "${t}", but it is not allowed. The following could have happened:\n \n - The mutation is explicitly being blocket\n - You are passing state to a 3rd party tool trying to manipulate the state\n - You are running asynchronous code and forgot to "await" its execution\n `)}isDefaultProxifier(){return this.tree.proxifier===this.tree.master.proxifier}ensureValueDosntExistInStateTreeElsewhere(t){if("production"!==i){if(t&&!0===t[s])throw new Error(`proxy-state-tree - You are trying to insert a value that already exists in the state tree on path "${t[n]}"`);return t}}trackPath(t){if(this.tree.canTrack())if(this.isDefaultProxifier()){const e=this.tree.master.currentTree;if(!e)return;e.addTrackingPath(t)}else this.tree.addTrackingPath(t)}getTrackingTree(){return this.tree.master.currentTree&&this.isDefaultProxifier()?this.tree.master.currentTree:this.tree.canTrack()&&this.tree.canTrack()?this.tree:null}getMutationTree(){return this.tree.master.mutationTree||this.tree}isProxyCached(t,e){return t[this.CACHED_PROXY]&&String(t[this.CACHED_PROXY][n])===String(e)}createArrayProxy(t,e){if(!this.ssr&&this.isProxyCached(t,e))return t[this.CACHED_PROXY];const r=this,o=new Proxy(t,{get(o,u){if(u===s)return!0;if(u===n)return e;if(u===a)return t;if("indexOf"===u)return(e,r)=>t.indexOf(h(e),h(r));if("length"===u||"function"==typeof o[u]&&!c.has(String(u))||"symbol"==typeof u)return o[u];const p=r.getTrackingTree(),f=r.concat(e,u),d=p||r.tree;p&&p.proxifier.trackPath(f),d.trackPathListeners.forEach(t=>t(f));const m=String(u);return c.has(m)?(...t)=>{const s=r.getMutationTree();let n;return n="production"===i?o[u](...t):o[u](...t.map(t=>r.ensureValueDosntExistInStateTreeElsewhere(t))),s.addMutation({method:m,path:e,delimiter:r.delimiter,args:t,hasChangedValue:!0}),n}:l(o[u])?r.proxify(o[u],f):o[u]},set(t,i,s){const n=r.concat(e,i),a=r.getMutationTree(),o=Reflect.set(t,i,s);return a.addMutation({method:"set",path:n,args:[s],delimiter:r.delimiter,hasChangedValue:!0}),o}});return this.ssr||Object.defineProperty(t,this.CACHED_PROXY,{value:o,configurable:!0}),o}createObjectProxy(t,e){if(!this.ssr&&this.isProxyCached(t,e))return t[this.CACHED_PROXY];const r=this,i=new Proxy(t,{get(c,h){if(h===s)return!0;if(h===n)return e;if(h===a)return t;if(h===o)return r.tree;if("symbol"==typeof h||h in Object.prototype)return c[h];const p=Object.getOwnPropertyDescriptor(c,h)||Object.getPrototypeOf(c)&&Object.getOwnPropertyDescriptor(Object.getPrototypeOf(c),h);if(p&&"get"in p){const t=p.get.call(i);return r.tree.master.options.devmode&&r.tree.master.options.onGetter&&r.tree.master.options.onGetter(r.concat(e,h),t),t}const f=r.getTrackingTree(),d=c[h],m=r.concat(e,h),g=f||r.tree;return"function"==typeof d?r.tree.master.options.onGetFunction?r.tree.master.options.onGetFunction(f||r.tree,m,c,h):u(c)?d:d.call(c,r.tree,m):(g.trackPathListeners.forEach(t=>t(m)),f&&f.proxifier.trackPath(m),l(d)?r.proxify(d,m):d)},set(t,i,s){const n=r.concat(e,i);let a;i in t||(a=e);const o=r.getMutationTree(),c=t[i];"function"==typeof s&&r.tree.master.options.onSetFunction&&(s=r.tree.master.options.onSetFunction(r.getTrackingTree()||r.tree,n,t,i,s));const h=c!==s,u=Reflect.set(t,i,s);return o.addMutation({method:"set",path:n,args:[s],delimiter:r.delimiter,hasChangedValue:h},a),u},deleteProperty(t,i){const s=r.concat(e,i);let n;i in t&&(n=e);const a=r.getMutationTree();return delete t[i],a.addMutation({method:"unset",path:s,args:[],delimiter:r.delimiter,hasChangedValue:!0},n),!0}});return this.ssr||Object.defineProperty(t,this.CACHED_PROXY,{value:i,configurable:!0}),i}proxify(t,e){if(t){if(t[s]&&(String(t[n])!==String(e)||t[a][this.CACHED_PROXY]!==t))return this.proxify(t[a],e);if(t[s])return t;if(Array.isArray(t))return this.createArrayProxy(t,e);if((t=>"[object Object]"===String(t)&&"Object"===t.constructor.name)(t)||u(t))return this.createObjectProxy(t,e)}return t}}class f{constructor(t,e){this.mutationCallbacks=[],this.mutations=[],this.objectChanges=new Set,this.isTracking=!1,this.isBlocking=!1,this.trackPathListeners=[],this.isTracking=!0,this.master=t,this.proxifier=e||new p(this),this.state=this.proxifier.proxify(t.sourceState,"")}trackPaths(){const t=new Set,e=e=>{t.add(e)};return this.trackPathListeners.push(e),()=>(this.trackPathListeners.splice(this.trackPathListeners.indexOf(e),1),t)}getMutations(){const t=this.mutations.slice();return this.mutations.length=0,t}getObjectChanges(){const t=new Set([...this.objectChanges]);return this.objectChanges.clear(),t}addMutation(t,e){const r=this.master.currentFlushId;this.mutations.push(t),e&&this.objectChanges.add(e);for(let i of this.master.mutationCallbacks)i(t,new Set(e?[t.path,e]:[t.path]),r);for(let i of this.mutationCallbacks)i(t,new Set(e?[t.path,e]:[t.path]),r)}flush(t=!1){return this.master.flush(this,t)}onMutation(t){this.mutationCallbacks.push(t)}canMutate(){return this.isTracking&&!this.isBlocking}canTrack(){return!1}blockMutations(){this.isBlocking=!0}enableMutations(){this.isBlocking=!1}dispose(){return this.isTracking=!1,this.mutationCallbacks.length=0,this.proxifier=this.master.proxifier,this}}class d{constructor(t){this.pathDependencies=new Set,this.shouldTrack=!1,this.trackPathListeners=[],this.master=t,this.proxifier=t.proxifier,this.state=t.state}trackPaths(){const t=new Set,e=e=>{t.add(e)};return this.trackPathListeners.push(e),()=>(this.trackPathListeners.splice(this.trackPathListeners.indexOf(e),1),t)}canMutate(){return!1}canTrack(){return!0}addTrackingPath(t){this.shouldTrack&&(this.pathDependencies.add(t),this.callback&&this.master.addPathDependency(t,this.callback))}track(t){return this.master.changeTrackStateTree(this),this.shouldTrack=!0,this.clearTracking(),t&&(this.callback=(...e)=>{this.callback&&t(...e)}),this}clearTracking(){if(this.callback)for(let t of this.pathDependencies)this.master.removePathDependency(t,this.callback);this.pathDependencies.clear()}stopTracking(){this.shouldTrack=!1}trackScope(t,e){const r=this.master.previousTree,i=this.master.currentTree;this.master.currentTree=this,this.track(e);const s=t(this);return this.master.currentTree=i,this.master.previousTree=r,this.stopTracking(),s}dispose(){return this.callback?(this.clearTracking(),this.callback=null,this.proxifier=this.master.proxifier,this.master.currentTree===this&&(this.master.currentTree=null),this):(this.pathDependencies.clear(),this)}}r.d(e,"ProxyStateTree",(function(){return m})),r.d(e,"IS_PROXY",(function(){return s})),r.d(e,"PROXY_TREE",(function(){return o})),r.d(e,"VALUE",(function(){return a})),r.d(e,"PATH",(function(){return n})),r.d(e,"TrackStateTree",(function(){return d})),r.d(e,"MutationTree",(function(){return f}));class m{constructor(t,e={}){this.cache={mutationTree:[],trackStateTree:[]},this.flushCallbacks=[],this.mutationCallbacks=[],this.currentFlushId=0,this.pathDependencies={},void 0===e.devmode&&(e.devmode=!0),e.delimiter||(e.delimiter="."),this.master=this,this.sourceState=t,this.options=e,this.createTrackStateProxifier()}createTrackStateProxifier(){const t=new d(this);this.proxifier=t.proxifier=new p(t),this.state=t.state=this.proxifier.proxify(this.sourceState,"")}getMutationTree(){if(!this.options.devmode)return this.mutationTree=this.mutationTree||new f(this,this.proxifier);return this.cache.mutationTree.pop()||new f(this)}getTrackStateTree(){return this.cache.trackStateTree.pop()||new d(this)}getTrackStateTreeWithProxifier(){const t=this.getTrackStateTree();return this.options.ssr?t.state=this.sourceState:(t.proxifier=new p(t),t.state=t.proxifier.proxify(this.sourceState,"")),t}changeTrackStateTree(t){this.previousTree=this.currentTree,this.currentTree=t}disposeTree(t){t instanceof f?this.cache.mutationTree.push(t.dispose()):t instanceof d&&this.cache.trackStateTree.push(t.dispose())}onMutation(t){return this.mutationCallbacks.push(t),()=>{this.mutationCallbacks.splice(this.mutationCallbacks.indexOf(t),1)}}forceFlush(){const t=[],e=[];for(let r in this.pathDependencies){this.pathDependencies[r].forEach(r=>{r(t,e,this.currentFlushId++,!1)})}}flush(t,e=!1){let r;if(r=Array.isArray(t)?t.reduce((t,e)=>({mutations:t.mutations.concat(e.getMutations()),objectChanges:new Set([...t.objectChanges,...e.getObjectChanges()])}),{mutations:[],objectChanges:new Set}):{mutations:t.getMutations(),objectChanges:t.getObjectChanges()},!r.mutations.length&&!r.objectChanges.size)return{mutations:[],flushId:null};const i=new Set,s=new Set,n=this.currentFlushId++;for(let t of r.objectChanges)this.pathDependencies[t]&&i.add(t);for(let t of r.mutations)t.hasChangedValue&&i.add(t.path);const a=Array.from(i).sort();for(let t of a)if(this.pathDependencies[t])for(let e of this.pathDependencies[t])s.add(e);for(let t of s)t(r.mutations,a,n,e);const o=this.flushCallbacks.slice();for(let t of o)this.flushCallbacks.includes(t)&&t(r.mutations,a,n,e);return i.clear(),s.clear(),{mutations:r.mutations,flushId:n}}onFlush(t){return this.flushCallbacks.push(t),()=>this.flushCallbacks.splice(this.flushCallbacks.indexOf(t),1)}rescope(t,e){return t&&t[s]?e.proxifier.proxify(t[a],t[n]):t}addPathDependency(t,e){this.pathDependencies[t]||(this.pathDependencies[t]=new Set),this.pathDependencies[t].add(e)}removePathDependency(t,e){this.pathDependencies[t].delete(e),this.pathDependencies[t].size||delete this.pathDependencies[t]}toJSON(){return this.sourceState}}}]); | ||
!function(t){var e={};function r(i){if(e[i])return e[i].exports;var s=e[i]={i:i,l:!1,exports:{}};return t[i].call(s.exports,s,s.exports,r),s.l=!0,s.exports}r.m=t,r.c=e,r.d=function(t,e,i){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:i})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var i=Object.create(null);if(r.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var s in t)r.d(i,s,function(e){return t[e]}.bind(null,s));return i},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){r.r(e);const i=(()=>{let t;try{t="production"}catch(e){t="development"}return t})(),s=Symbol("IS_PROXY"),n=Symbol("PATH"),a=Symbol("VALUE"),o=Symbol("PROXY_TREE"),c=new Set(["push","shift","pop","unshift","splice","reverse","sort","copyWithin"]),h=t=>t&&t[s]?t[a]:t,u=t=>"object"==typeof t&&null!==t&&!Array.isArray(t)&&"Object"!==t.constructor.name&&Object.isExtensible(t),l=t=>void 0!==t&&(!u(t)||u(t)&&!(t instanceof Date)&&!(t instanceof Map)&&!(t instanceof Set));class p{constructor(t){this.tree=t,this.CACHED_PROXY=Symbol("CACHED_PROXY"),this.delimiter=t.master.options.delimiter,this.ssr=Boolean(t.master.options.ssr)}concat(t,e){return t?t+this.delimiter+e:e}ensureMutationTrackingIsEnabled(t){if("production"!==i&&this.tree.master.options.devmode&&!this.tree.canMutate())throw new Error(`proxy-state-tree - You are mutating the path "${t}", but it is not allowed. The following could have happened:\n \n - The mutation is explicitly being blocket\n - You are passing state to a 3rd party tool trying to manipulate the state\n - You are running asynchronous code and forgot to "await" its execution\n `)}isDefaultProxifier(){return this.tree.proxifier===this.tree.master.proxifier}ensureValueDosntExistInStateTreeElsewhere(t){if("production"!==i){if(t&&!0===t[s])throw new Error(`proxy-state-tree - You are trying to insert a value that already exists in the state tree on path "${t[n]}"`);return t}}trackPath(t){if(this.tree.canTrack())if(this.isDefaultProxifier()){const e=this.tree.master.currentTree;if(!e)return;e.addTrackingPath(t)}else this.tree.addTrackingPath(t)}getTrackingTree(){return this.tree.master.currentTree&&this.isDefaultProxifier()?this.tree.master.currentTree:this.tree.canTrack()&&this.tree.canTrack()?this.tree:null}getMutationTree(){return this.tree.master.mutationTree||this.tree}isProxyCached(t,e){return t[this.CACHED_PROXY]&&String(t[this.CACHED_PROXY][n])===String(e)}createArrayProxy(t,e){if(!this.ssr&&this.isProxyCached(t,e))return t[this.CACHED_PROXY];const r=this,o=new Proxy(t,{get(o,u){if(u===s)return!0;if(u===n)return e;if(u===a)return t;if("indexOf"===u)return(e,r)=>t.indexOf(h(e),h(r));if("length"===u||"function"==typeof o[u]&&!c.has(String(u))||"symbol"==typeof u)return o[u];const p=r.getTrackingTree(),f=r.concat(e,u),d=p||r.tree;p&&p.proxifier.trackPath(f),d.trackPathListeners.forEach(t=>t(f));const m=String(u);return c.has(m)?(...t)=>{const s=r.getMutationTree();let n;return n="production"===i?o[u](...t):o[u](...t.map(t=>r.ensureValueDosntExistInStateTreeElsewhere(t))),s.addMutation({method:m,path:e,delimiter:r.delimiter,args:t,hasChangedValue:!0}),n}:l(o[u])?r.proxify(o[u],f):o[u]},set(t,i,s){const n=r.concat(e,i),a=r.getMutationTree(),o=Reflect.set(t,i,s);return a.addMutation({method:"set",path:n,args:[s],delimiter:r.delimiter,hasChangedValue:!0}),o}});return this.ssr||Object.defineProperty(t,this.CACHED_PROXY,{value:o,configurable:!0}),o}createObjectProxy(t,e){if(!this.ssr&&this.isProxyCached(t,e))return t[this.CACHED_PROXY];const r=this,i=new Proxy(t,{get(c,h){if(h===s)return!0;if(h===n)return e;if(h===a)return t;if(h===o)return r.tree;if("symbol"==typeof h||h in Object.prototype)return c[h];const p=Object.getOwnPropertyDescriptor(c,h)||Object.getPrototypeOf(c)&&Object.getOwnPropertyDescriptor(Object.getPrototypeOf(c),h);if(p&&"get"in p){const t=p.get.call(i);return r.tree.master.options.devmode&&r.tree.master.options.onGetter&&r.tree.master.options.onGetter(r.concat(e,h),t),t}const f=r.getTrackingTree(),d=c[h],m=r.concat(e,h),g=f||r.tree;return"function"==typeof d?r.tree.master.options.onGetFunction?r.tree.master.options.onGetFunction(f||r.tree,m,c,h):u(c)?d:d.call(c,r.tree,m):(g.trackPathListeners.forEach(t=>t(m)),f&&f.proxifier.trackPath(m),l(d)?r.proxify(d,m):d)},set(t,i,s){const n=r.concat(e,i);let a;i in t||(a=e);const o=r.getMutationTree(),c=t[i];"function"==typeof s&&r.tree.master.options.onSetFunction&&(s=r.tree.master.options.onSetFunction(r.getTrackingTree()||r.tree,n,t,i,s));const h=c!==s,u=Reflect.set(t,i,s);return o.addMutation({method:"set",path:n,args:[s],delimiter:r.delimiter,hasChangedValue:h},a),u},deleteProperty(t,i){const s=r.concat(e,i);let n;i in t&&(n=e);const a=r.getMutationTree();return delete t[i],a.addMutation({method:"unset",path:s,args:[],delimiter:r.delimiter,hasChangedValue:!0},n),!0}});return this.ssr||Object.defineProperty(t,this.CACHED_PROXY,{value:i,configurable:!0}),i}proxify(t,e){if(t){if(t[s]&&(String(t[n])!==String(e)||t[a][this.CACHED_PROXY]!==t))return this.proxify(t[a],e);if(t[s])return t;if(Array.isArray(t))return this.createArrayProxy(t,e);if((t=>"[object Object]"===String(t)&&"Object"===t.constructor.name)(t)||u(t))return this.createObjectProxy(t,e)}return t}}class f{constructor(t,e){this.mutationCallbacks=[],this.mutations=[],this.objectChanges=new Set,this.isTracking=!1,this.isBlocking=!1,this.trackPathListeners=[],this.isTracking=!0,this.master=t,this.proxifier=e||new p(this),this.state=this.proxifier.proxify(t.sourceState,"")}trackPaths(){const t=new Set,e=e=>{t.add(e)};return this.trackPathListeners.push(e),()=>(this.trackPathListeners.splice(this.trackPathListeners.indexOf(e),1),t)}getMutations(){const t=this.mutations.slice();return this.mutations.length=0,t}getObjectChanges(){const t=new Set([...this.objectChanges]);return this.objectChanges.clear(),t}addMutation(t,e){const r=this.master.currentFlushId;this.mutations.push(t),e&&this.objectChanges.add(e);for(const i of this.master.mutationCallbacks)i(t,new Set(e?[t.path,e]:[t.path]),r);for(const i of this.mutationCallbacks)i(t,new Set(e?[t.path,e]:[t.path]),r)}flush(t=!1){return this.master.flush(this,t)}onMutation(t){this.mutationCallbacks.push(t)}canMutate(){return this.isTracking&&!this.isBlocking}canTrack(){return!1}blockMutations(){this.isBlocking=!0}enableMutations(){this.isBlocking=!1}dispose(){return this.isTracking=!1,this.mutationCallbacks.length=0,this.proxifier=this.master.proxifier,this}}class d{constructor(t){this.pathDependencies=new Set,this.shouldTrack=!1,this.trackPathListeners=[],this.master=t,this.proxifier=t.proxifier,this.state=t.state}trackPaths(){const t=new Set,e=e=>{t.add(e)};return this.trackPathListeners.push(e),()=>(this.trackPathListeners.splice(this.trackPathListeners.indexOf(e),1),t)}canMutate(){return!1}canTrack(){return!0}addTrackingPath(t){this.shouldTrack&&(this.pathDependencies.add(t),this.callback&&this.master.addPathDependency(t,this.callback))}track(t){return this.master.changeTrackStateTree(this),this.shouldTrack=!0,this.clearTracking(),t&&(this.callback=(...e)=>{this.callback&&t(...e)}),this}clearTracking(){if(this.callback)for(const t of this.pathDependencies)this.master.removePathDependency(t,this.callback);this.pathDependencies.clear()}stopTracking(){this.shouldTrack=!1}trackScope(t,e){const r=this.master.previousTree,i=this.master.currentTree;this.master.currentTree=this,this.track(e);const s=t(this);return this.master.currentTree=i,this.master.previousTree=r,this.stopTracking(),s}dispose(){return this.callback?(this.clearTracking(),this.callback=null,this.proxifier=this.master.proxifier,this.master.currentTree===this&&(this.master.currentTree=null),this):(this.pathDependencies.clear(),this)}}r.d(e,"ProxyStateTree",(function(){return m})),r.d(e,"IS_PROXY",(function(){return s})),r.d(e,"PROXY_TREE",(function(){return o})),r.d(e,"VALUE",(function(){return a})),r.d(e,"PATH",(function(){return n})),r.d(e,"TrackStateTree",(function(){return d})),r.d(e,"MutationTree",(function(){return f}));class m{constructor(t,e={}){this.cache={mutationTree:[],trackStateTree:[]},this.flushCallbacks=[],this.mutationCallbacks=[],this.currentFlushId=0,this.pathDependencies={},void 0===e.devmode&&(e.devmode=!0),e.delimiter||(e.delimiter="."),this.master=this,this.sourceState=t,this.options=e,this.createTrackStateProxifier()}createTrackStateProxifier(){const t=new d(this);this.proxifier=t.proxifier=new p(t),this.state=t.state=this.proxifier.proxify(this.sourceState,"")}getMutationTree(){if(!this.options.devmode)return this.mutationTree=this.mutationTree||new f(this,this.proxifier);return this.cache.mutationTree.pop()||new f(this)}getTrackStateTree(){return this.cache.trackStateTree.pop()||new d(this)}getTrackStateTreeWithProxifier(){const t=this.getTrackStateTree();return this.options.ssr?t.state=this.sourceState:(t.proxifier=new p(t),t.state=t.proxifier.proxify(this.sourceState,"")),t}changeTrackStateTree(t){this.previousTree=this.currentTree,this.currentTree=t}disposeTree(t){t instanceof f?this.cache.mutationTree.push(t.dispose()):t instanceof d&&this.cache.trackStateTree.push(t.dispose())}onMutation(t){return this.mutationCallbacks.push(t),()=>{this.mutationCallbacks.splice(this.mutationCallbacks.indexOf(t),1)}}forceFlush(){const t=[],e=[];for(const r in this.pathDependencies){this.pathDependencies[r].forEach(r=>{r(t,e,this.currentFlushId++,!1)})}}flush(t,e=!1){let r;if(r=Array.isArray(t)?t.reduce((t,e)=>({mutations:t.mutations.concat(e.getMutations()),objectChanges:new Set([...t.objectChanges,...e.getObjectChanges()])}),{mutations:[],objectChanges:new Set}):{mutations:t.getMutations(),objectChanges:t.getObjectChanges()},!r.mutations.length&&!r.objectChanges.size)return{mutations:[],flushId:null};const i=new Set,s=new Set,n=this.currentFlushId++;for(const t of r.objectChanges)this.pathDependencies[t]&&i.add(t);for(const t of r.mutations)t.hasChangedValue&&i.add(t.path);const a=Array.from(i).sort();for(const t of a)if(this.pathDependencies[t])for(const e of this.pathDependencies[t])s.add(e);for(const t of s)t(r.mutations,a,n,e);const o=this.flushCallbacks.slice();for(const t of o)this.flushCallbacks.includes(t)&&t(r.mutations,a,n,e);return i.clear(),s.clear(),{mutations:r.mutations,flushId:n}}onFlush(t){return this.flushCallbacks.push(t),()=>this.flushCallbacks.splice(this.flushCallbacks.indexOf(t),1)}rescope(t,e){return t&&t[s]?e.proxifier.proxify(t[a],t[n]):t}addPathDependency(t,e){this.pathDependencies[t]||(this.pathDependencies[t]=new Set),this.pathDependencies[t].add(e)}removePathDependency(t,e){this.pathDependencies[t].delete(e),this.pathDependencies[t].size||delete this.pathDependencies[t]}toJSON(){return this.sourceState}}}]); |
@@ -80,3 +80,3 @@ import { MutationTree } from './MutationTree'; | ||
const emptyPaths = []; | ||
for (let key in this.pathDependencies) { | ||
for (const key in this.pathDependencies) { | ||
const callbacks = this.pathDependencies[key]; | ||
@@ -117,3 +117,3 @@ callbacks.forEach((callback) => { | ||
const flushId = this.currentFlushId++; | ||
for (let objectChange of changes.objectChanges) { | ||
for (const objectChange of changes.objectChanges) { | ||
if (this.pathDependencies[objectChange]) { | ||
@@ -123,3 +123,3 @@ paths.add(objectChange); | ||
} | ||
for (let mutation of changes.mutations) { | ||
for (const mutation of changes.mutations) { | ||
if (mutation.hasChangedValue) { | ||
@@ -131,5 +131,5 @@ paths.add(mutation.path); | ||
const sortedPaths = Array.from(paths).sort(); | ||
for (let path of sortedPaths) { | ||
for (const path of sortedPaths) { | ||
if (this.pathDependencies[path]) { | ||
for (let callback of this.pathDependencies[path]) { | ||
for (const callback of this.pathDependencies[path]) { | ||
pathCallbacksToCall.add(callback); | ||
@@ -139,3 +139,3 @@ } | ||
} | ||
for (let callback of pathCallbacksToCall) { | ||
for (const callback of pathCallbacksToCall) { | ||
callback(changes.mutations, sortedPaths, flushId, isAsync); | ||
@@ -149,3 +149,3 @@ } | ||
const flushCallbacks = this.flushCallbacks.slice(); | ||
for (let callback of flushCallbacks) { | ||
for (const callback of flushCallbacks) { | ||
if (this.flushCallbacks.includes(callback)) { | ||
@@ -152,0 +152,0 @@ callback(changes.mutations, sortedPaths, flushId, isAsync); |
@@ -42,6 +42,6 @@ import { Proxifier } from './Proxyfier'; | ||
} | ||
for (let cb of this.master.mutationCallbacks) { | ||
for (const cb of this.master.mutationCallbacks) { | ||
cb(mutation, new Set(objectChangePath ? [mutation.path, objectChangePath] : [mutation.path]), currentFlushId); | ||
} | ||
for (let callback of this.mutationCallbacks) { | ||
for (const callback of this.mutationCallbacks) { | ||
callback(mutation, new Set(objectChangePath ? [mutation.path, objectChangePath] : [mutation.path]), currentFlushId); | ||
@@ -48,0 +48,0 @@ } |
@@ -45,2 +45,3 @@ export class TrackStateTree { | ||
} | ||
// eslint-disable-next-line | ||
cb(...args); | ||
@@ -53,3 +54,3 @@ }; | ||
if (this.callback) { | ||
for (let path of this.pathDependencies) { | ||
for (const path of this.pathDependencies) { | ||
this.master.removePathDependency(path, this.callback); | ||
@@ -56,0 +57,0 @@ } |
@@ -89,3 +89,3 @@ "use strict"; | ||
const emptyPaths = []; | ||
for (let key in this.pathDependencies) { | ||
for (const key in this.pathDependencies) { | ||
const callbacks = this.pathDependencies[key]; | ||
@@ -126,3 +126,3 @@ callbacks.forEach((callback) => { | ||
const flushId = this.currentFlushId++; | ||
for (let objectChange of changes.objectChanges) { | ||
for (const objectChange of changes.objectChanges) { | ||
if (this.pathDependencies[objectChange]) { | ||
@@ -132,3 +132,3 @@ paths.add(objectChange); | ||
} | ||
for (let mutation of changes.mutations) { | ||
for (const mutation of changes.mutations) { | ||
if (mutation.hasChangedValue) { | ||
@@ -140,5 +140,5 @@ paths.add(mutation.path); | ||
const sortedPaths = Array.from(paths).sort(); | ||
for (let path of sortedPaths) { | ||
for (const path of sortedPaths) { | ||
if (this.pathDependencies[path]) { | ||
for (let callback of this.pathDependencies[path]) { | ||
for (const callback of this.pathDependencies[path]) { | ||
pathCallbacksToCall.add(callback); | ||
@@ -148,3 +148,3 @@ } | ||
} | ||
for (let callback of pathCallbacksToCall) { | ||
for (const callback of pathCallbacksToCall) { | ||
callback(changes.mutations, sortedPaths, flushId, isAsync); | ||
@@ -158,3 +158,3 @@ } | ||
const flushCallbacks = this.flushCallbacks.slice(); | ||
for (let callback of flushCallbacks) { | ||
for (const callback of flushCallbacks) { | ||
if (this.flushCallbacks.includes(callback)) { | ||
@@ -161,0 +161,0 @@ callback(changes.mutations, sortedPaths, flushId, isAsync); |
@@ -45,6 +45,6 @@ "use strict"; | ||
} | ||
for (let cb of this.master.mutationCallbacks) { | ||
for (const cb of this.master.mutationCallbacks) { | ||
cb(mutation, new Set(objectChangePath ? [mutation.path, objectChangePath] : [mutation.path]), currentFlushId); | ||
} | ||
for (let callback of this.mutationCallbacks) { | ||
for (const callback of this.mutationCallbacks) { | ||
callback(mutation, new Set(objectChangePath ? [mutation.path, objectChangePath] : [mutation.path]), currentFlushId); | ||
@@ -51,0 +51,0 @@ } |
@@ -48,2 +48,3 @@ "use strict"; | ||
} | ||
// eslint-disable-next-line | ||
cb(...args); | ||
@@ -56,3 +57,3 @@ }; | ||
if (this.callback) { | ||
for (let path of this.pathDependencies) { | ||
for (const path of this.pathDependencies) { | ||
this.master.removePathDependency(path, this.callback); | ||
@@ -59,0 +60,0 @@ } |
{ | ||
"name": "proxy-state-tree", | ||
"version": "6.3.0-1615750082257", | ||
"version": "6.3.0-1624521495651", | ||
"description": "An implementation of the Mobx/Vue state tracking approach, for library authors", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
185307
1793