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.3.0-1663317035337 to 6.3.0-1686952849485

dist/proxy-state-tree.min.js.map

3

dist/proxy-state-tree.min.js

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

!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{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}}}]);
(()=>{let e;try{e="production"}catch{e="development"}})(),Symbol("IS_PROXY"),Symbol("PATH"),Symbol("VALUE"),Symbol("PROXY_TREE"),new Set(["push","shift","pop","unshift","splice","reverse","sort","copyWithin"]);
//# sourceMappingURL=proxy-state-tree.min.js.map

@@ -70,3 +70,3 @@ export interface IProxifier<T extends object> {

}
export declare type TTree = IMutationTree<any> | ITrackStateTree<any>;
export type TTree = IMutationTree<any> | ITrackStateTree<any>;
export interface IRemoveProxyCallback {

@@ -73,0 +73,0 @@ (path: string): void;

@@ -70,3 +70,3 @@ export interface IProxifier<T extends object> {

}
export declare type TTree = IMutationTree<any> | ITrackStateTree<any>;
export type TTree = IMutationTree<any> | ITrackStateTree<any>;
export interface IRemoveProxyCallback {

@@ -73,0 +73,0 @@ (path: string): void;

{
"name": "proxy-state-tree",
"version": "6.3.0-1663317035337",
"version": "6.3.0-1686952849485",
"description": "An implementation of the Mobx/Vue state tracking approach, for library authors",

@@ -41,4 +41,4 @@ "main": "lib/index.js",

"bundlesize": "^0.17.2",
"terser-webpack-plugin": "^1.3.0",
"webpack": "^4.35.0"
"terser-webpack-plugin": "^5.3.9",
"webpack": "^5.87.0"
},

@@ -45,0 +45,0 @@ "bundlesize": [

@@ -11,9 +11,10 @@ const path = require('path')

},
devtool: 'source-map',
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
test: /\.js(\?.*)?$/i,
parallel: true,
sourceMap: true,
terserOptions: {
sourceMap: true,
module: true,

@@ -20,0 +21,0 @@ },

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