Socket
Socket
Sign inDemoInstall

proxy-state-tree

Package Overview
Dependencies
Maintainers
2
Versions
865
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

proxy-state-tree - npm Package Compare versions

Comparing version 6.2.0-1611398336423 to 6.2.0-1624124645626

2

dist/proxy-state-tree.min.js

@@ -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=(()=>{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,this.ssr=Boolean(t.master.options.ssr)}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.ssr&&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 this.ssr||Object.defineProperty(t,this.CACHED_PROXY,{value:i,configurable:!0}),i}createObjectProxy(t,e){if(!this.ssr&&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 this.ssr||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.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}}}]);
!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 @@ }

@@ -1,2 +0,1 @@

import isPlainObject from 'is-plain-obj';
const ENVIRONMENT = (() => {

@@ -16,2 +15,5 @@ let env;

export const PROXY_TREE = Symbol('PROXY_TREE');
const isPlainObject = (value) => {
return (String(value) === '[object Object]' && value.constructor.name === 'Object');
};
const arrayMutations = new Set([

@@ -18,0 +20,0 @@ 'push',

@@ -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 @@ }

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Proxifier = exports.PROXY_TREE = exports.VALUE = exports.PATH = exports.IS_PROXY = void 0;
const tslib_1 = require("tslib");
const is_plain_obj_1 = tslib_1.__importDefault(require("is-plain-obj"));
const ENVIRONMENT = (() => {

@@ -20,2 +18,5 @@ let env;

exports.PROXY_TREE = Symbol('PROXY_TREE');
const isPlainObject = (value) => {
return (String(value) === '[object Object]' && value.constructor.name === 'Object');
};
const arrayMutations = new Set([

@@ -311,3 +312,3 @@ 'push',

}
else if (is_plain_obj_1.default(value) || isClass(value)) {
else if (isPlainObject(value) || isClass(value)) {
return this.createObjectProxy(value, path);

@@ -314,0 +315,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.2.0-1611398336423",
"version": "6.2.0-1624124645626",
"description": "An implementation of the Mobx/Vue state tracking approach, for library authors",

@@ -39,5 +39,2 @@ "main": "lib/index.js",

"homepage": "https://github.com/christianalfoni/proxy-state-tree#readme",
"dependencies": {
"is-plain-obj": "^1.1.0"
},
"devDependencies": {

@@ -44,0 +41,0 @@ "bundlesize": "^0.17.2",

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc