proxy-state-tree
Advanced tools
Comparing version 6.2.0-1610292726381 to 6.2.0-1610312088833
@@ -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=1)}([function(t,e,r){var i=Object.prototype.toString;t.exports=function(t){var e;return"[object Object]"===i.call(t)&&(null===(e=Object.getPrototypeOf(t))||e===Object.getPrototypeOf({}))}},function(t,e,r){r.r(e);var i=r(0),s=r.n(i);const n=Symbol("IS_PROXY"),a=Symbol("PATH"),o=Symbol("VALUE"),c=Symbol("PROXY_TREE"),h=new Set(["push","shift","pop","unshift","splice","reverse","sort","copyWithin"]),u=t=>t&&t[n]?t[o]:t,l=t=>"object"==typeof t&&null!==t&&!Array.isArray(t)&&"Object"!==t.constructor.name&&Object.isExtensible(t),f=t=>void 0!==t&&(!l(t)||l(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}concat(t,e){return t?t+this.delimiter+e:e}ensureMutationTrackingIsEnabled(t){}isDefaultProxifier(){return this.tree.proxifier===this.tree.master.proxifier}ensureValueDosntExistInStateTreeElsewhere(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][a])===String(e)}createArrayProxy(t,e){if(this.isProxyCached(t,e))return t[this.CACHED_PROXY];const r=this,i=new Proxy(t,{get(i,s){if(s===n)return!0;if(s===a)return e;if(s===o)return t;if("indexOf"===s)return(e,r)=>t.indexOf(u(e),u(r));if("length"===s||"function"==typeof i[s]&&!h.has(String(s))||"symbol"==typeof s)return i[s];const c=r.getTrackingTree(),l=r.concat(e,s),p=c||r.tree;c&&c.proxifier.trackPath(l),p.trackPathListeners.forEach(t=>t(l));const d=String(s);return h.has(d)?(...t)=>{const n=r.getMutationTree();let a;return a=i[s](...t),n.addMutation({method:d,path:e,delimiter:r.delimiter,args:t,hasChangedValue:!0}),a}:f(i[s])?r.proxify(i[s],l):i[s]},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 Object.defineProperty(t,this.CACHED_PROXY,{value:i,configurable:!0}),i}createObjectProxy(t,e){if(this.isProxyCached(t,e))return t[this.CACHED_PROXY];const r=this,i=new Proxy(t,{get(s,h){if(h===n)return!0;if(h===a)return e;if(h===o)return t;if(h===c)return r.tree;if("symbol"==typeof h||h in Object.prototype)return s[h];const u=Object.getOwnPropertyDescriptor(s,h)||Object.getPrototypeOf(s)&&Object.getOwnPropertyDescriptor(Object.getPrototypeOf(s),h);if(u&&"get"in u){const t=u.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 p=r.getTrackingTree(),d=s[h],m=r.concat(e,h),g=p||r.tree;return"function"==typeof d?r.tree.master.options.onGetFunction?r.tree.master.options.onGetFunction(p||r.tree,m,s,h):l(s)?d:d.call(s,r.tree,m):(g.trackPathListeners.forEach(t=>t(m)),p&&p.proxifier.trackPath(m),f(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 Object.defineProperty(t,this.CACHED_PROXY,{value:i,configurable:!0}),i}proxify(t,e){if(t){if(t[n]&&(String(t[a])!==String(e)||t[o][this.CACHED_PROXY]!==t))return this.proxify(t[o],e);if(t[n])return t;if(Array.isArray(t))return this.createArrayProxy(t,e);if(s()(t)||l(t))return this.createObjectProxy(t,e)}return t}}class d{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 m{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 g})),r.d(e,"IS_PROXY",(function(){return n})),r.d(e,"PROXY_TREE",(function(){return c})),r.d(e,"VALUE",(function(){return o})),r.d(e,"PATH",(function(){return a})),r.d(e,"TrackStateTree",(function(){return m})),r.d(e,"MutationTree",(function(){return d}));class g{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 m(this);this.options.ssr?this.state=this.sourceState:(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 d(this,this.proxifier);return this.cache.mutationTree.pop()||new d(this)}getTrackStateTree(){return this.cache.trackStateTree.pop()||new m(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 d?this.cache.mutationTree.push(t.dispose()):t instanceof m&&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[n]?e.proxifier.proxify(t[o],t[a]):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=1)}([function(t,e,r){var i=Object.prototype.toString;t.exports=function(t){var e;return"[object Object]"===i.call(t)&&(null===(e=Object.getPrototypeOf(t))||e===Object.getPrototypeOf({}))}},function(t,e,r){r.r(e);var i=r(0),s=r.n(i);const n=(()=>{let t;try{t="production"}catch(e){t="development"}return t})(),a=Symbol("IS_PROXY"),o=Symbol("PATH"),c=Symbol("VALUE"),h=Symbol("PROXY_TREE"),u=new Set(["push","shift","pop","unshift","splice","reverse","sort","copyWithin"]),l=t=>t&&t[a]?t[c]:t,p=t=>"object"==typeof t&&null!==t&&!Array.isArray(t)&&"Object"!==t.constructor.name&&Object.isExtensible(t),f=t=>void 0!==t&&(!p(t)||p(t)&&!(t instanceof Date)&&!(t instanceof Map)&&!(t instanceof Set));class d{constructor(t){this.tree=t,this.CACHED_PROXY=Symbol("CACHED_PROXY"),this.delimiter=t.master.options.delimiter}concat(t,e){return t?t+this.delimiter+e:e}ensureMutationTrackingIsEnabled(t){if("production"!==n&&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"!==n){if(t&&!0===t[a])throw new Error(`proxy-state-tree - You are trying to insert a value that already exists in the state tree on path "${t[o]}"`);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][o])===String(e)}createArrayProxy(t,e){if(this.isProxyCached(t,e))return t[this.CACHED_PROXY];const r=this,i=new Proxy(t,{get(i,s){if(s===a)return!0;if(s===o)return e;if(s===c)return t;if("indexOf"===s)return(e,r)=>t.indexOf(l(e),l(r));if("length"===s||"function"==typeof i[s]&&!u.has(String(s))||"symbol"==typeof s)return i[s];const h=r.getTrackingTree(),p=r.concat(e,s),d=h||r.tree;h&&h.proxifier.trackPath(p),d.trackPathListeners.forEach(t=>t(p));const m=String(s);return u.has(m)?(...t)=>{const a=r.getMutationTree();let o;return o="production"===n?i[s](...t):i[s](...t.map(t=>r.ensureValueDosntExistInStateTreeElsewhere(t))),a.addMutation({method:m,path:e,delimiter:r.delimiter,args:t,hasChangedValue:!0}),o}:f(i[s])?r.proxify(i[s],p):i[s]},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 Object.defineProperty(t,this.CACHED_PROXY,{value:i,configurable:!0}),i}createObjectProxy(t,e){if(this.isProxyCached(t,e))return t[this.CACHED_PROXY];const r=this,i=new Proxy(t,{get(s,n){if(n===a)return!0;if(n===o)return e;if(n===c)return t;if(n===h)return r.tree;if("symbol"==typeof n||n in Object.prototype)return s[n];const u=Object.getOwnPropertyDescriptor(s,n)||Object.getPrototypeOf(s)&&Object.getOwnPropertyDescriptor(Object.getPrototypeOf(s),n);if(u&&"get"in u){const t=u.get.call(i);return r.tree.master.options.devmode&&r.tree.master.options.onGetter&&r.tree.master.options.onGetter(r.concat(e,n),t),t}const l=r.getTrackingTree(),d=s[n],m=r.concat(e,n),g=l||r.tree;return"function"==typeof d?r.tree.master.options.onGetFunction?r.tree.master.options.onGetFunction(l||r.tree,m,s,n):p(s)?d:d.call(s,r.tree,m):(g.trackPathListeners.forEach(t=>t(m)),l&&l.proxifier.trackPath(m),f(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 Object.defineProperty(t,this.CACHED_PROXY,{value:i,configurable:!0}),i}proxify(t,e){if(t){if(t[a]&&(String(t[o])!==String(e)||t[c][this.CACHED_PROXY]!==t))return this.proxify(t[c],e);if(t[a])return t;if(Array.isArray(t))return this.createArrayProxy(t,e);if(s()(t)||p(t))return this.createObjectProxy(t,e)}return t}}class m{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 d(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 g{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 T})),r.d(e,"IS_PROXY",(function(){return a})),r.d(e,"PROXY_TREE",(function(){return h})),r.d(e,"VALUE",(function(){return c})),r.d(e,"PATH",(function(){return o})),r.d(e,"TrackStateTree",(function(){return g})),r.d(e,"MutationTree",(function(){return m}));class T{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 g(this);this.options.ssr?this.state=this.sourceState:(this.proxifier=t.proxifier=new d(t),this.state=t.state=this.proxifier.proxify(this.sourceState,""))}getMutationTree(){if(!this.options.devmode)return this.mutationTree=this.mutationTree||new m(this,this.proxifier);return this.cache.mutationTree.pop()||new m(this)}getTrackStateTree(){return this.cache.trackStateTree.pop()||new g(this)}getTrackStateTreeWithProxifier(){const t=this.getTrackStateTree();return this.options.ssr?t.state=this.sourceState:(t.proxifier=new d(t),t.state=t.proxifier.proxify(this.sourceState,"")),t}changeTrackStateTree(t){this.previousTree=this.currentTree,this.currentTree=t}disposeTree(t){t instanceof m?this.cache.mutationTree.push(t.dispose()):t instanceof g&&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[a]?e.proxifier.proxify(t[c],t[o]):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}}}]); |
import isPlainObject from 'is-plain-obj'; | ||
const ENVIRONMENT = (() => { | ||
let env; | ||
try { | ||
env = process.env.NODE_ENV; | ||
} | ||
catch (_a) { | ||
env = 'development'; | ||
} | ||
return env; | ||
})(); | ||
export const IS_PROXY = Symbol('IS_PROXY'); | ||
@@ -40,3 +50,3 @@ export const PATH = Symbol('PATH'); | ||
ensureMutationTrackingIsEnabled(path) { | ||
if (process.env.NODE_ENV === 'production') | ||
if (ENVIRONMENT === 'production') | ||
return; | ||
@@ -56,3 +66,3 @@ if (this.tree.master.options.devmode && !this.tree.canMutate()) { | ||
ensureValueDosntExistInStateTreeElsewhere(value) { | ||
if (process.env.NODE_ENV === 'production') | ||
if (ENVIRONMENT === 'production') | ||
return; | ||
@@ -136,3 +146,3 @@ if (value && value[IS_PROXY] === true) { | ||
let result; | ||
if (process.env.NODE_ENV === 'production') { | ||
if (ENVIRONMENT === 'production') { | ||
result = target[prop](...args); | ||
@@ -139,0 +149,0 @@ } |
@@ -6,2 +6,12 @@ "use strict"; | ||
const is_plain_obj_1 = tslib_1.__importDefault(require("is-plain-obj")); | ||
const ENVIRONMENT = (() => { | ||
let env; | ||
try { | ||
env = process.env.NODE_ENV; | ||
} | ||
catch (_a) { | ||
env = 'development'; | ||
} | ||
return env; | ||
})(); | ||
exports.IS_PROXY = Symbol('IS_PROXY'); | ||
@@ -45,3 +55,3 @@ exports.PATH = Symbol('PATH'); | ||
ensureMutationTrackingIsEnabled(path) { | ||
if (process.env.NODE_ENV === 'production') | ||
if (ENVIRONMENT === 'production') | ||
return; | ||
@@ -61,3 +71,3 @@ if (this.tree.master.options.devmode && !this.tree.canMutate()) { | ||
ensureValueDosntExistInStateTreeElsewhere(value) { | ||
if (process.env.NODE_ENV === 'production') | ||
if (ENVIRONMENT === 'production') | ||
return; | ||
@@ -141,3 +151,3 @@ if (value && value[exports.IS_PROXY] === true) { | ||
let result; | ||
if (process.env.NODE_ENV === 'production') { | ||
if (ENVIRONMENT === 'production') { | ||
result = target[prop](...args); | ||
@@ -144,0 +154,0 @@ } |
{ | ||
"name": "proxy-state-tree", | ||
"version": "6.2.0-1610292726381", | ||
"version": "6.2.0-1610312088833", | ||
"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
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
184021
1786
2