mobx-state-tree
Advanced tools
Comparing version 3.7.0 to 3.7.1
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("mobx")):"function"==typeof define&&define.amd?define(["exports","mobx"],e):e(t.mobxStateTree={},t.mobx)}(this,function(t,l){"use strict";var r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};function a(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var o=function(){return(o=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function n(t,e,n,r){var i,o=arguments.length,a=o<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,n,r);else for(var s=t.length-1;0<=s;s--)(i=t[s])&&(a=(o<3?i(a):3<o?i(e,n,a):i(e,n))||a);return 3<o&&a&&Object.defineProperty(e,n,a),a}function u(t){return Y(t).type}function i(t,e){return Y(t).onPatch(e)}function s(t,e){Y(t).applyPatches(at(e))}function p(t,e){return Y(t).applySnapshot(e)}function c(t){return Y(t).root.storedValue}function h(t,e){var n=K(Y(t),e,!1);if(void 0!==n)try{return n.value}catch(t){return}}function f(t,e){var n=Y(t);n.getChildren().forEach(function(t){J(t.storedValue)&&f(t.storedValue,e)}),e(n.storedValue)}function e(t){var e;return{name:(e=J(t)?u(t):t).name,properties:o({},e.properties)}}var d=function(){function t(t,e,n,r,i){this.parent=null,this.subpath="",this.state=U.INITIALIZING,this._environment=void 0,this._initialSnapshot=i,this.type=t,this.parent=e,this.subpath=n;var o=!0;try{this.storedValue=t.createNewInstance(this,{},i),this.state=U.CREATED,o=!1}finally{o&&(this.state=U.DEAD)}}return Object.defineProperty(t.prototype,"path",{get:function(){return this.parent?this.parent.path+"/"+vt(this.subpath):""},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isRoot",{get:function(){return null===this.parent},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"root",{get:function(){return this.parent?this.parent.root:nt("This scalar node is not part of a tree")},enumerable:!0,configurable:!0}),t.prototype.setParent=function(t,e){if(void 0===e&&(e=null),this.parent!==t||this.subpath!==e)if(this.parent&&!t)this.die();else{var n=null===e?"":e;this.subpath!==n&&(this.subpath=n),t&&t!==this.parent&&(this.parent=t)}},Object.defineProperty(t.prototype,"value",{get:function(){return this.type.getValue(this)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"snapshot",{get:function(){return ct(this.getSnapshot())},enumerable:!0,configurable:!0}),t.prototype.getSnapshot=function(){return this.type.getSnapshot(this)},Object.defineProperty(t.prototype,"isAlive",{get:function(){return this.state!==U.DEAD},enumerable:!0,configurable:!0}),t.prototype.toString=function(){return this.type.name+"@"+(this.path||"<root>")+(this.isAlive?"":"[dead]")},t.prototype.die=function(){this.state=U.DEAD},t}(),y=1,v="warn";var b,g,m={onError:function(t){throw t}},S=function(){function r(t,e,n,r,i){if(this.nodeId=++y,this.subpathAtom=l.createAtom("path"),this.subpath="",this.parent=null,this.state=U.INITIALIZING,this.isProtectionEnabled=!0,this.middlewares=null,this._autoUnbox=!0,this._environment=void 0,this._isRunningAction=!1,this._hasSnapshotReaction=!1,this._disposers=null,this._patchSubscribers=null,this._snapshotSubscribers=null,this._observableInstanceCreated=!1,this._cachedInitialSnapshot=null,this._environment=r,this._initialSnapshot=ct(i),this.type=t,this.parent=e,this.subpath=n,this.escapedSubpath=vt(this.subpath),this.identifierAttribute=t.identifierAttribute,e||(this.identifierCache=new $),this._childNodes=t.initializeChildNodes(this,this._initialSnapshot),this.identifier=null,this.identifierAttribute&&this._initialSnapshot){var o=this._initialSnapshot[this.identifierAttribute];if(void 0===o){var a=this._childNodes[this.identifierAttribute];a&&(o=a.value)}"string"!=typeof o&&"number"!=typeof o&&nt("Instance identifier '"+this.identifierAttribute+"' for type '"+this.type.name+"' must be a string or a number"),this.identifier=""+o}e?e.root.identifierCache.addNodeToCache(this):this.identifierCache.addNodeToCache(this)}return r.prototype.applyPatches=function(t){this._observableInstanceCreated||this._createObservableInstance(),this.applyPatches(t)},r.prototype.applySnapshot=function(t){this._observableInstanceCreated||this._createObservableInstance(),this.applySnapshot(t)},r.prototype._createObservableInstance=function(){var t=this.type;this.storedValue=t.createNewInstance(this,this._childNodes,this._initialSnapshot),this.preboot();var e,n,r=!0;this._observableInstanceCreated=!0;try{this._isRunningAction=!0,t.finalizeNewInstance(this,this.storedValue),this._isRunningAction=!1,this.fireHook("afterCreate"),this.state=U.CREATED,r=!1}finally{r&&(this.state=U.DEAD)}e=this,n="snapshot",l.getAtom(e,n).trackAndCompute(),this.isRoot&&this._addSnapshotReaction(),this.finalizeCreation(),this._childNodes=tt},Object.defineProperty(r.prototype,"path",{get:function(){return this.subpathAtom.reportObserved(),this.parent?this.parent.path+"/"+this.escapedSubpath:""},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"root",{get:function(){var t=this.parent;return t?t.root:this},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"isRoot",{get:function(){return null===this.parent},enumerable:!0,configurable:!0}),r.prototype.setParent=function(t,e){if(void 0===e&&(e=null),this.parent!==t||this.subpath!==e)if(this.parent&&!t)this.die();else{var n=null===e?"":e;this.subpath!==n&&(this.subpath=n,this.escapedSubpath=vt(this.subpath),this.subpathAtom.reportChanged()),t&&t!==this.parent&&(t.root.identifierCache.mergeCache(this),this.parent=t,this.subpathAtom.reportChanged(),this.fireHook("afterAttach"))}},r.prototype.fireHook=function(t){var e=this,n=this.storedValue&&"object"==typeof this.storedValue&&this.storedValue[t];"function"==typeof n&&(l._allowStateChangesInsideComputed?l._allowStateChangesInsideComputed(function(){n.apply(e.storedValue)}):n.apply(this.storedValue))},r.prototype.createObservableInstanceIfNeeded=function(){this._observableInstanceCreated||this._createObservableInstance()},Object.defineProperty(r.prototype,"isObservableInstanceCreated",{get:function(){return this._observableInstanceCreated},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"value",{get:function(){if(this.createObservableInstanceIfNeeded(),this.isAlive)return this.type.getValue(this)},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"snapshot",{get:function(){if(this.isAlive)return ct(this.getSnapshot())},enumerable:!0,configurable:!0}),r.prototype.getSnapshot=function(){if(this.isAlive)return this._observableInstanceCreated?this._getActualSnapshot():this._getInitialSnapshot()},r.prototype._getActualSnapshot=function(){return this.type.getSnapshot(this)},r.prototype._getInitialSnapshot=function(){if(this.isAlive){if(!this._initialSnapshot)return this._initialSnapshot;if(this._cachedInitialSnapshot)return this._cachedInitialSnapshot;var t=this.type,e=this._childNodes,n=this._initialSnapshot;return this._cachedInitialSnapshot=t.processInitialSnapshot(e,n),this._cachedInitialSnapshot}},r.prototype.isRunningAction=function(){return!!this._isRunningAction||!this.isRoot&&this.parent.isRunningAction()},Object.defineProperty(r.prototype,"isAlive",{get:function(){return this.state!==U.DEAD},enumerable:!0,configurable:!0}),r.prototype.assertAlive=function(){if(!this.isAlive){var t="[mobx-state-tree][error] You are trying to read or write to an object that is no longer part of a state tree. (Object type was '"+this.type.name+"'). Either detach nodes first, or don't use objects after removing / replacing them in the tree.";switch(v){case"error":throw new Error(t);case"warn":console.warn(t+' Use setLivelynessChecking("error") to simplify debugging this error.')}}},r.prototype.getChildNode=function(t){this.assertAlive(),this._autoUnbox=!1;try{return this._observableInstanceCreated?this.type.getChildNode(this,t):this._childNodes[t]}finally{this._autoUnbox=!0}},r.prototype.getChildren=function(){this.assertAlive(),this._autoUnbox=!1;try{return this._observableInstanceCreated?this.type.getChildren(this):Q(this._childNodes)}finally{this._autoUnbox=!0}},r.prototype.getChildType=function(t){return this.type.getChildType(t)},Object.defineProperty(r.prototype,"isProtected",{get:function(){return this.root.isProtectionEnabled},enumerable:!0,configurable:!0}),r.prototype.assertWritable=function(){this.assertAlive(),!this.isRunningAction()&&this.isProtected&&nt("Cannot modify '"+this+"', the object is protected and can only be modified by using an action.")},r.prototype.removeChild=function(t){this.type.removeChild(this,t)},r.prototype.unbox=function(t){return t&&t.parent&&t.parent.assertAlive(),t&&t.parent&&t.parent._autoUnbox?t.value:t},r.prototype.toString=function(){var t=this.identifier?"(id: "+this.identifier+")":"";return this.type.name+"@"+(this.path||"<root>")+t+(this.isAlive?"":"[dead]")},r.prototype.finalizeCreation=function(){if(this.state===U.CREATED){if(this.parent){if(this.parent.state!==U.FINALIZED)return;this.fireHook("afterAttach")}this.state=U.FINALIZED;for(var t=0,e=this.getChildren();t<e.length;t++){var n=e[t];n instanceof r&&n.finalizeCreation()}}},r.prototype.detach=function(){this.isAlive||nt("Error while detaching, node is not alive."),this.isRoot||(this.fireHook("beforeDetach"),this._environment=this.root._environment,this.state=U.DETACHING,this.identifierCache=this.root.identifierCache.splitCache(this),this.parent.removeChild(this.subpath),this.parent=null,this.subpath=this.escapedSubpath="",this.subpathAtom.reportChanged(),this.state=U.FINALIZED)},r.prototype.preboot=function(){var n=this;this.applyPatches=E(this.storedValue,"@APPLY_PATCHES",function(t){t.forEach(function(t){var e=mt(t.path);q(n,e.slice(0,-1)).applyPatchLocally(e[e.length-1],t)})}),this.applySnapshot=E(this.storedValue,"@APPLY_SNAPSHOT",function(t){if(t!==n.snapshot)return n.type.applySnapshot(n,t)}),lt(this.storedValue,"$treenode",this),lt(this.storedValue,"toJSON",Z)},r.prototype.die=function(){this.state!==U.DETACHING&&J(this.storedValue)&&(f(this.storedValue,function(t){var e=Y(t);e instanceof r&&e.aboutToDie()}),f(this.storedValue,function(t){var e=Y(t);e instanceof r&&e.finalizeDeath()}))},r.prototype.aboutToDie=function(){this._disposers&&(this._disposers.forEach(function(t){return t()}),this._disposers=null),this.fireHook("beforeDestroy")},r.prototype.finalizeDeath=function(){var t,e,n;this.root.identifierCache.notifyDied(this),e="snapshot",n=(t=this).snapshot,Object.defineProperty(t,e,{enumerable:!0,writable:!1,configurable:!0,value:n}),this._patchSubscribers&&(this._patchSubscribers=null),this._snapshotSubscribers&&(this._snapshotSubscribers=null),this.state=U.DEAD,this.subpath=this.escapedSubpath="",this.parent=null,this.subpathAtom.reportChanged()},r.prototype.onSnapshot=function(t){return this._addSnapshotReaction(),this._snapshotSubscribers||(this._snapshotSubscribers=[]),ht(this._snapshotSubscribers,t)},r.prototype.emitSnapshot=function(e){this._snapshotSubscribers&&this._snapshotSubscribers.forEach(function(t){return t(e)})},r.prototype.onPatch=function(t){return this._patchSubscribers||(this._patchSubscribers=[]),ht(this._patchSubscribers,t)},r.prototype.emitPatch=function(t,e){var n=this._patchSubscribers;if(n&&n.length){var r=function(t){"oldValue"in t||nt("Patches without `oldValue` field cannot be inversed");return[function(t){switch(t.op){case"add":return{op:"add",path:t.path,value:t.value};case"remove":return{op:"remove",path:t.path};case"replace":return{op:"replace",path:t.path,value:t.value}}}(t),function(t){switch(t.op){case"add":return{op:"remove",path:t.path};case"remove":return{op:"add",path:t.path,value:t.oldValue};case"replace":return{op:"replace",path:t.path,value:t.oldValue}}}(t)]}(function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];for(var r=0;r<e.length;r++){var i=e[r];for(var o in i)t[o]=i[o]}return t}({},t,{path:e.path.substr(this.path.length)+"/"+t.path})),i=r[0],o=r[1];n.forEach(function(t){return t(i,o)})}this.parent&&this.parent.emitPatch(t,e)},r.prototype.addDisposer=function(t){this._disposers?this._disposers.unshift(t):this._disposers=[t]},r.prototype.removeMiddleware=function(e){this.middlewares&&(this.middlewares=this.middlewares.filter(function(t){return t.handler!==e}))},r.prototype.addMiddleWare=function(t,e){var n=this;return void 0===e&&(e=!0),this.middlewares?this.middlewares.push({handler:t,includeHooks:e}):this.middlewares=[{handler:t,includeHooks:e}],function(){n.removeMiddleware(t)}},r.prototype.applyPatchLocally=function(t,e){this.assertWritable(),this._observableInstanceCreated||this._createObservableInstance(),this.type.applyPatchLocally(this,t,e)},r.prototype._addSnapshotReaction=function(){var e=this;if(!this._hasSnapshotReaction){var t=l.reaction(function(){return e.snapshot},function(t){return e.emitSnapshot(t)},m);this.addDisposer(t),this._hasSnapshotReaction=!0}},n([l.action],r.prototype,"_createObservableInstance",null),n([l.computed],r.prototype,"snapshot",null),n([l.action],r.prototype,"detach",null),n([l.action],r.prototype,"die",null),r}();(g=b||(b={}))[g.String=1]="String",g[g.Number=2]="Number",g[g.Boolean=4]="Boolean",g[g.Date=8]="Date",g[g.Literal=16]="Literal",g[g.Array=32]="Array",g[g.Map=64]="Map",g[g.Object=128]="Object",g[g.Frozen=256]="Frozen",g[g.Optional=512]="Optional",g[g.Reference=1024]="Reference",g[g.Identifier=2048]="Identifier",g[g.Late=4096]="Late",g[g.Refinement=8192]="Refinement",g[g.Union=16384]="Union",g[g.Null=32768]="Null",g[g.Undefined=65536]="Undefined",g[g.Integer=131072]="Integer";var w=function(){function t(t){this["!!complexType"]=void 0,this.isType=!0,this.name=t}return t.prototype.create=function(t,e){return void 0===t&&(t=this.getDefaultSnapshot()),this.instantiate(null,"",e,t).value},t.prototype.initializeChildNodes=function(t,e){return tt},t.prototype.createNewInstance=function(t,e,n){return n},t.prototype.finalizeNewInstance=function(t,e){},t.prototype.processInitialSnapshot=function(t,e){return e},t.prototype.isAssignableFrom=function(t){return t===this},t.prototype.validate=function(t,e){return J(t)?u(t)===this||this.isAssignableFrom(u(t))?z():M(e,t):this.isValidSnapshot(t,e)},t.prototype.is=function(t){return 0===this.validate(t,[{path:"",type:this}]).length},t.prototype.reconcile=function(t,e){if(t.snapshot===e)return t;if(J(e)&&Y(e)===t)return t;if(t.type===this&&ut(e)&&!J(e)&&(!t.identifierAttribute||t.identifier===""+e[t.identifierAttribute]))return t.applySnapshot(e),t;var n=t.parent,r=t.subpath;if(t.die(),J(e)&&this.isAssignableFrom(u(e))){var i=Y(e);return i.setParent(n,r),i}return this.instantiate(n,r,t._environment,e)},Object.defineProperty(t.prototype,"Type",{get:function(){return nt("Factory.Type should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.Type`")},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"SnapshotType",{get:function(){return nt("Factory.SnapshotType should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.SnapshotType`")},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"CreationType",{get:function(){return nt("Factory.CreationType should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.CreationType`")},enumerable:!0,configurable:!0}),n([l.action],t.prototype,"create",null),t}(),A=function(e){function t(t){return e.call(this,t)||this}return a(t,e),t.prototype.getValue=function(t){return t.storedValue},t.prototype.getSnapshot=function(t){return t.storedValue},t.prototype.getDefaultSnapshot=function(){},t.prototype.applySnapshot=function(t,e){nt("Immutable types do not support applying snapshots")},t.prototype.applyPatchLocally=function(t,e,n){nt("Immutable types do not support applying patches")},t.prototype.getChildren=function(t){return X},t.prototype.getChildNode=function(t,e){return nt("No child '"+e+"' available in type: "+this.name)},t.prototype.getChildType=function(t){return nt("No child '"+t+"' available in type: "+this.name)},t.prototype.reconcile=function(t,e){if(t.type===this&&t.storedValue===e)return t;var n=this.instantiate(t.parent,t.subpath,t._environment,e);return t.die(),n},t.prototype.removeChild=function(t,e){return nt("No child '"+e+"' available in type: "+this.name)},t}(w);function P(t){return"object"==typeof t&&t&&!0===t.isType}var _=new Map;function I(t){return{$MST_UNSERIALIZABLE:!0,type:t}}function V(e,t){l.runInAction(function(){at(t).forEach(function(t){return function(t,e){var n=h(t,e.path||"");if(!n)return nt("Invalid action path: "+(e.path||""));var r=Y(n);if("@APPLY_PATCHES"===e.name)return s.call(null,n,e.args[0]);if("@APPLY_SNAPSHOT"===e.name)return p.call(null,n,e.args[0]);"function"!=typeof n[e.name]&&nt("Action '"+e.name+"' does not exist in '"+r.path+"'");return n[e.name].apply(n,e.args?e.args.map(function(t){return(e=t)&&"object"==typeof e&&"$MST_DATE"in e?new Date(e.$MST_DATE):e;var e}):[])}(e,t)})})}function T(o,a,s){return void 0===s&&(s=!1),D(o,function(n,t){if("action"!==n.type||n.id!==n.rootId)return t(n);var e=Y(n.context),r={name:n.name,path:B(Y(o),e),args:n.args.map(function(t,e){return function(t,e,n,r){if(r instanceof Date)return{$MST_DATE:r.getTime()};if(pt(r))return r;if(J(r))return I("[MSTNode: "+u(r).name+"]");if("function"==typeof r)return I("[function]");if("object"==typeof r&&!st(r)&&!ot(r))return I("[object "+(r&&r.constructor&&r.constructor.name||"Complex Object")+"]");try{return JSON.stringify(r),r}catch(t){return I(""+t)}}(0,n.name,0,t)})};if(s){var i=t(n);return a(r),i}return a(r),t(n)})}var C=1,N=null;function O(){return C++}function j(t,e){var n=Y(t.context),r=n._isRunningAction,i=N;"action"===t.type&&n.assertAlive(),n._isRunningAction=!0,N=t;try{return function(t,e,s){var u=function(t,e,n){var r=n.$mst_middleware||X,i=t;for(;i;)i.middlewares&&(r=r.concat(i.middlewares)),i=i.parent;return r}(t,0,s);if(!u.length)return l.action(s).apply(null,e.args);var p=0,c=null;return function n(t){var e=u[p++];var r=e&&e.handler;function i(t,e){c=e?e(n(t)||c):n(t)}function o(t){c=t}var a=function(){return r(t,i,o),c};return r&&e.includeHooks?a():r&&!e.includeHooks?Nt[t.name]?n(t):a():l.action(s).apply(null,t.args)}(e)}(n,t,e)}finally{N=i,n._isRunningAction=r}}function E(e,n,r){var t=function(){var t=O();return j({type:"action",name:n,id:t,args:ft(arguments),context:e,tree:c(e),rootId:N?N.rootId:t,parentId:N?N.id:0,allParentIds:N?N.allParentIds.concat([N.id]):[]},r)};return t._isMSTAction=!0,t}function D(t,e,n){return void 0===n&&(n=!0),Y(t).addMiddleWare(e,n)}function x(t){return"function"==typeof t?"<function"+(t.name?" "+t.name:"")+">":J(t)?"<"+t+">":"`"+function(t){try{return JSON.stringify(t)}catch(t){return"<Unserializable: "+t+">"}}(t)+"`"}function R(t){var e=t.value,n=t.context[t.context.length-1].type,r=t.context.map(function(t){return t.path}).filter(function(t){return 0<t.length}).join("/"),i=0<r.length?'at path "/'+r+'" ':"",o=J(e)?"value of type "+Y(e).type.name+":":pt(e)?"value":"snapshot",a=n&&J(e)&&n.is(Y(e).snapshot);return""+i+o+" "+x(e)+" is not assignable "+(n?"to type: `"+n.name+"`":"")+(t.message?" ("+t.message+")":"")+(n?Yt(n)||pt(e)?".":", expected an instance of `"+n.name+"` or a snapshot like `"+n.describe()+"` instead."+(a?" (Note that a snapshot of the provided value is compatible with the targeted type)":""):".")}function k(t,e,n){return t.concat([{path:e,type:n}])}function z(){return X}function M(t,e,n){return[{context:t,value:e,message:n}]}function L(t){return t.reduce(function(t,e){return t.concat(e)},[])}function F(t,e){var n,r=t.validate(e,[{path:"",type:t}]);0<r.length&&nt("Error while converting "+((n=x(e)).length<280?n:n.substring(0,272)+"......"+n.substring(n.length-8))+" to `"+t.name+"`:\n\n "+r.map(R).join("\n "))}var U,H,$=function(){function e(){this.cache=l.observable.map()}return e.prototype.addNodeToCache=function(t){if(t.identifierAttribute){var e=t.identifier;this.cache.has(e)||this.cache.set(e,l.observable.array([],et));var n=this.cache.get(e);-1!==n.indexOf(t)&&nt("Already registered"),n.push(t)}return this},e.prototype.mergeCache=function(t){var e=this;l.values(t.identifierCache.cache).forEach(function(t){return t.forEach(function(t){e.addNodeToCache(t)})})},e.prototype.notifyDied=function(t){if(t.identifierAttribute){var e=this.cache.get(t.identifier);e&&e.remove(t)}},e.prototype.splitCache=function(t){var n=new e,r=t.path;return l.values(this.cache).forEach(function(t){for(var e=t.length-1;0<=e;e--)0===t[e].path.indexOf(r)&&(n.addNodeToCache(t[e]),t.splice(e,1))}),n},e.prototype.resolve=function(e,t){var n=this.cache.get(""+t);if(!n)return null;var r=n.filter(function(t){return e.isAssignableFrom(t.type)});switch(r.length){case 0:return null;case 1:var i=r[0];if(i){for(var o=[],a=i.parent;a&&!a.isObservableInstanceCreated;)o.unshift(a),a=a.parent;for(var s=0,u=o;s<u.length;s++){u[s].createObservableInstanceIfNeeded()}}return i;default:return nt("Cannot resolve a reference to type '"+e.name+"' with id: '"+t+"' unambigously, there are multiple candidates: "+r.map(function(t){return t.path}).join(", "))}},e}();function W(t,e,n,r,i){var o,a=(o=i)&&o.$treenode||null;if(a){if(a.isRoot)return a.setParent(e,n),a;nt("Cannot add an object to a state tree if it is already part of the same or another state tree. Tried to assign an object to '"+(e?e.path:"")+"/"+n+"', but it lives already at '"+a.path+"'")}return new(t.shouldAttachNode?S:d)(t,e,n,r,i)}function J(t){return!(!t||!t.$treenode)}function Y(t){return J(t)?t.$treenode:nt("Value "+t+" is no MST Node")}function Z(){return Y(this).snapshot}(H=U||(U={}))[H.INITIALIZING=0]="INITIALIZING",H[H.CREATED=1]="CREATED",H[H.FINALIZED=2]="FINALIZED",H[H.DETACHING=3]="DETACHING",H[H.DEAD=4]="DEAD";var G=function(t){return".."};function B(t,e){t.root!==e.root&&nt("Cannot calculate relative path: objects '"+t+"' and '"+e+"' are not part of the same object tree");for(var n=mt(t.path),r=mt(e.path),i=0;i<n.length&&n[i]===r[i];i++);return n.slice(i).map(G).join("/")+gt(r.slice(i))}function K(t,e,n){return void 0===n&&(n=!0),q(t,mt(e),n)}function q(t,e,n){void 0===n&&(n=!0);for(var r=t,i=0;i<e.length;i++){var o=e[i];if(""!==o){if(".."===o){if(r=r.parent)continue}else{if("."===o||""===o)continue;if(r){if(r instanceof d)try{var a=r.value;J(a)&&(r=Y(a))}catch(t){if(!n)return;throw t}if(r instanceof S)if(r.getChildType(o)&&(r=r.getChildNode(o)))continue}}return n?nt("Could not resolve '"+o+"' in path '"+(gt(e.slice(0,i))||"/")+"' while resolving '"+gt(e)+"'"):void 0}r=r.root}return r}function Q(n){if(!n)return X;var t=Object.keys(n);if(!t.length)return X;var r=new Array(t.length);return t.forEach(function(t,e){r[e]=n[t]}),r}var X=Object.freeze([]),tt=Object.freeze({}),et="string"==typeof l.$mobx?{deep:!1}:{deep:!1,proxy:!1};function nt(t){throw void 0===t&&(t="Illegal state"),new Error("[mobx-state-tree] "+t)}function rt(t){return t}Object.freeze(et);var it=Number.isInteger||function(t){return"number"==typeof t&&isFinite(t)&&Math.floor(t)===t};function ot(t){return!(!Array.isArray(t)&&!l.isObservableArray(t))}function at(t){return t?ot(t)?t:[t]:X}function st(t){if(null===t||"object"!=typeof t)return!1;var e=Object.getPrototypeOf(t);return e===Object.prototype||null===e}function ut(t){return!(null===t||"object"!=typeof t||t instanceof Date||t instanceof RegExp)}function pt(t){return null==t||("string"==typeof t||"number"==typeof t||"boolean"==typeof t||t instanceof Date)}function ct(t){return t}function lt(t,e,n){Object.defineProperty(t,e,{enumerable:!1,writable:!1,configurable:!0,value:n})}function ht(r,i){return r.push(i),function(){var t,e,n;e=i,-1!==(n=(t=r).indexOf(e))&&t.splice(n,1)}}function ft(t){for(var e=new Array(t.length),n=0;n<t.length;n++)e[n]=t[n];return e}var dt=function(t,e){};function yt(t){return l=t.name,h=t,f=function(){var s=O(),u=N||nt("Not running an action!"),p=arguments;function c(t,e,n){t.$mst_middleware=f.$mst_middleware,j({name:l,type:e,id:s,args:[n],tree:u.tree,context:u.context,parentId:u.id,allParentIds:u.allParentIds.concat([u.id]),rootId:u.rootId},t)}return new Promise(function(e,n){var r,t=function(){r=h.apply(null,arguments),i(void 0)};function i(t){var e;try{c(function(t){e=r.next(t)},"flow_resume",t)}catch(e){return void setImmediate(function(){c(function(t){n(e)},"flow_throw",e)})}a(e)}function o(t){var e;try{c(function(t){e=r.throw(t)},"flow_resume_error",t)}catch(e){return void setImmediate(function(){c(function(t){n(e)},"flow_throw",e)})}a(e)}function a(t){if(!t.done)return t.value&&"function"==typeof t.value.then||nt("Only promises can be yielded to `async`, got: "+t),t.value.then(i,o);setImmediate(function(){c(function(t){e(t)},"flow_return",t.value)})}t.$mst_middleware=f.$mst_middleware,j({name:l,type:"flow_spawn",id:s,args:ft(p),tree:u.tree,context:u.context,parentId:u.id,allParentIds:u.allParentIds.concat([u.id]),rootId:u.rootId},t)})};var l,h,f}function vt(t){return!0==("number"==typeof t)?""+t:t.replace(/~/g,"~1").replace(/\//g,"~0")}function bt(t){return t.replace(/~0/g,"/").replace(/~1/g,"~")}function gt(t){return 0===t.length?"":"/"+t.map(vt).join("/")}function mt(t){var e=t.split("/").map(bt);return""===e[0]?e.slice(1):e}dt.ids={};var St,wt,At="Map.put can only be used to store complex values that have an identifier type attribute";(wt=St||(St={}))[wt.UNKNOWN=0]="UNKNOWN",wt[wt.YES=1]="YES",wt[wt.NO=2]="NO";var Pt=function(n){function t(t){return n.call(this,t,l.observable.ref.enhancer)||this}return a(t,n),t.prototype.get=function(t){return n.prototype.get.call(this,""+t)},t.prototype.has=function(t){return n.prototype.has.call(this,""+t)},t.prototype.delete=function(t){return n.prototype.delete.call(this,""+t)},t.prototype.set=function(t,e){return n.prototype.set.call(this,""+t,e)},t.prototype.put=function(t){if(t||nt("Map.put cannot be used to set empty values"),J(t)){var e=Y(t),n=e.identifier;return this.set(n,e.value),e.value}if(ut(t)){n=void 0;var r=Y(this).type;return r.identifierMode===St.NO?nt(At):r.identifierMode===St.YES?(n=""+t[r.mapIdentifierAttribute],this.set(n,t),this.get(n)):nt(At)}return nt("Map.put can only be used to store complex values")},t}(l.ObservableMap),_t=function(r){function t(t,e){var n=r.call(this,t)||this;return n.shouldAttachNode=!0,n.identifierMode=St.UNKNOWN,n.mapIdentifierAttribute=void 0,n.flags=b.Map,n.subType=e,n._determineIdentifierMode(),n}return a(t,r),t.prototype.instantiate=function(t,e,n,r){return this.identifierMode===St.UNKNOWN&&this._determineIdentifierMode(),W(this,t,e,n,r)},t.prototype._determineIdentifierMode=function(){var t=[];if(function t(e,n){if(e instanceof kt)n.push(e);else if(e instanceof Qt){if(!t(e.type,n))return!1}else if(e instanceof Kt){for(var r=0;r<e.types.length;r++)if(!t(e.types[r],n))return!1}else if(e instanceof ne){var i=e.getSubType(!1);if(!i)return!1;t(i,n)}return!0}(this.subType,t)){var e=void 0;t.forEach(function(t){t.identifierAttribute&&(e&&e!==t.identifierAttribute&&nt("The objects in a map should all have the same identifier attribute, expected '"+e+"', but child of type '"+t.name+"' declared attribute '"+t.identifierAttribute+"' as identifier"),e=t.identifierAttribute)}),e?(this.identifierMode=St.YES,this.mapIdentifierAttribute=e):this.identifierMode=St.NO}},t.prototype.initializeChildNodes=function(e,n){void 0===n&&(n={});var r=e.type.subType,i=e._environment,o={};return Object.keys(n).forEach(function(t){o[t]=r.instantiate(e,t,i,n[t])}),o},t.prototype.createNewInstance=function(t,e,n){return new Pt(e)},t.prototype.finalizeNewInstance=function(t,e){l._interceptReads(e,t.unbox),l.intercept(e,this.willChange),l.observe(e,this.didChange)},t.prototype.describe=function(){return"Map<string, "+this.subType.describe()+">"},t.prototype.getChildren=function(t){return l.values(t.storedValue)},t.prototype.getChildNode=function(t,e){var n=t.storedValue.get(""+e);return n||nt("Not a child "+e),n},t.prototype.willChange=function(t){var e=Y(t.object),n=t.name;e.assertWritable();var r=e.type,i=r.subType;switch(t.type){case"update":var o=t.newValue;if(o===t.object.get(n))return null;t.newValue=i.reconcile(e.getChildNode(n),t.newValue),r.processIdentifier(n,t.newValue);break;case"add":t.newValue,t.newValue=i.instantiate(e,n,void 0,t.newValue),r.processIdentifier(n,t.newValue)}return t},t.prototype.processIdentifier=function(t,e){if(this.identifierMode===St.YES&&e instanceof S){var n=e.identifier;n!==t&&nt("A map of objects containing an identifier should always store the object under their own identifier. Trying to store key '"+n+"', but expected: '"+t+"'")}},t.prototype.getValue=function(t){return t.storedValue},t.prototype.getSnapshot=function(t){var e={};return t.getChildren().forEach(function(t){e[t.subpath]=t.snapshot}),e},t.prototype.processInitialSnapshot=function(e,t){var n={};return Object.keys(e).forEach(function(t){n[t]=e[t].getSnapshot()}),n},t.prototype.didChange=function(t){var e=Y(t.object);switch(t.type){case"update":return void e.emitPatch({op:"replace",path:vt(t.name),value:t.newValue.snapshot,oldValue:t.oldValue?t.oldValue.snapshot:void 0},e);case"add":return void e.emitPatch({op:"add",path:vt(t.name),value:t.newValue.snapshot,oldValue:void 0},e);case"delete":var n=t.oldValue.snapshot;return t.oldValue.die(),void e.emitPatch({op:"remove",path:vt(t.name),oldValue:n},e)}},t.prototype.applyPatchLocally=function(t,e,n){var r=t.storedValue;switch(n.op){case"add":case"replace":r.set(e,n.value);break;case"remove":r.delete(e)}},t.prototype.applySnapshot=function(t,e){var n=t.storedValue,r={};for(var i in Array.from(n.keys()).forEach(function(t){r[t]=!1}),e)n.set(i,e[i]),r[""+i]=!0;Object.keys(r).forEach(function(t){!1===r[t]&&n.delete(t)})},t.prototype.getChildType=function(t){return this.subType},t.prototype.isValidSnapshot=function(e,n){var r=this;return st(e)?L(Object.keys(e).map(function(t){return r.subType.validate(e[t],k(n,t,r.subType))})):M(n,e,"Value is not a plain object")},t.prototype.getDefaultSnapshot=function(){return tt},t.prototype.removeChild=function(t,e){t.storedValue.delete(e)},n([l.action],t.prototype,"applySnapshot",null),t}(w);var It=function(r){function t(t,e){var n=r.call(this,t)||this;return n.shouldAttachNode=!0,n.flags=b.Array,n.subType=e,n}return a(t,r),t.prototype.instantiate=function(t,e,n,r){return W(this,t,e,n,r)},t.prototype.initializeChildNodes=function(r,t){void 0===t&&(t=[]);var i=r.type.subType,o=r._environment,a={};return t.forEach(function(t,e){var n=""+e;a[n]=i.instantiate(r,n,o,t)}),a},t.prototype.createNewInstance=function(t,e,n){return l.observable.array(Q(e),et)},t.prototype.finalizeNewInstance=function(t,e){l._getAdministration(e).dehancer=t.unbox,l.intercept(e,this.willChange),l.observe(e,this.didChange)},t.prototype.describe=function(){return this.subType.describe()+"[]"},t.prototype.getChildren=function(t){return t.storedValue.slice()},t.prototype.getChildNode=function(t,e){var n=parseInt(e,10);return n<t.storedValue.length?t.storedValue[n]:nt("Not a child: "+e)},t.prototype.willChange=function(t){var e=Y(t.object);e.assertWritable();var n=e.type.subType,r=e.getChildren(),i=null;switch(t.type){case"update":if(t.newValue===t.object[t.index])return null;if(!(i=Vt(e,n,[r[t.index]],[t.newValue],[t.index])))return null;t.newValue=i[0];break;case"splice":var o=t.index,a=t.removedCount,s=t.added;if(!(i=Vt(e,n,r.slice(o,o+a),s,s.map(function(t,e){return o+e}))))return null;t.added=i;for(var u=o+a;u<r.length;u++)r[u].setParent(e,""+(u+s.length-a))}return t},t.prototype.getValue=function(t){return t.storedValue},t.prototype.getSnapshot=function(t){return t.getChildren().map(function(t){return t.snapshot})},t.prototype.processInitialSnapshot=function(e,t){var n=[];return Object.keys(e).forEach(function(t){n.push(e[t].getSnapshot())}),n},t.prototype.didChange=function(t){var e=Y(t.object);switch(t.type){case"update":return void e.emitPatch({op:"replace",path:""+t.index,value:t.newValue.snapshot,oldValue:t.oldValue?t.oldValue.snapshot:void 0},e);case"splice":for(var n=t.removedCount-1;0<=n;n--)e.emitPatch({op:"remove",path:""+(t.index+n),oldValue:t.removed[n].snapshot},e);for(n=0;n<t.addedCount;n++)e.emitPatch({op:"add",path:""+(t.index+n),value:e.getChildNode(""+(t.index+n)).snapshot,oldValue:void 0},e);return}},t.prototype.applyPatchLocally=function(t,e,n){var r=t.storedValue,i="-"===e?r.length:parseInt(e);switch(n.op){case"replace":r[i]=n.value;break;case"add":r.splice(i,0,n.value);break;case"remove":r.splice(i,1)}},t.prototype.applySnapshot=function(t,e){t.storedValue.replace(e)},t.prototype.getChildType=function(t){return this.subType},t.prototype.isValidSnapshot=function(t,n){var r=this;return ot(t)?L(t.map(function(t,e){return r.subType.validate(t,k(n,""+e,r.subType))})):M(n,t,"Value is not an array")},t.prototype.getDefaultSnapshot=function(){return X},t.prototype.removeChild=function(t,e){t.storedValue.splice(parseInt(e,10),1)},n([l.action],t.prototype,"applySnapshot",null),t}(w);function Vt(t,e,n,r,i){for(var o,a,s,u=!1,p=void 0,c=!0,l=0;u=l<=r.length-1,o=n[l],a=u?r[l]:void 0,((s=a)instanceof d||s instanceof S)&&(a=a.storedValue),o||u;l++)if(u)if(o)if(Ct(o,a))n[l]=Tt(e,t,""+i[l],a,o);else{p=void 0;for(var h=l;h<n.length;h++)if(Ct(n[h],a)){p=n.splice(h,1)[0];break}n.splice(l,0,Tt(e,t,""+i[l],a,p)),c=!1}else J(a)&&Y(a).parent===t&&nt("Cannot add an object to a state tree if it is already part of the same or another state tree. Tried to assign an object to '"+t.path+"/"+i[l]+"', but it lives already at '"+Y(a).path+"'"),n.splice(l,0,Tt(e,t,""+i[l],a)),c=!1;else o.die(),n.splice(l,1),l--,c=!1;return c?null:n}function Tt(t,e,n,r,i){var o;if(J(r)&&((o=Y(r)).assertAlive(),null!==o.parent&&o.parent===e))return o.setParent(e,n),i&&i!==o&&i.die(),o;return i?((o=t.reconcile(i,r)).setParent(e,n),o):t.instantiate(e,n,e._environment,r)}function Ct(t,e){return J(e)?Y(e)===t:t.snapshot===e||!!(t instanceof S&&null!==t.identifier&&t.identifierAttribute&&st(e)&&t.identifier===""+e[t.identifierAttribute]&&t.type.is(e))}var Nt,Ot,jt="preProcessSnapshot",Et="postProcessSnapshot";function Dt(){return Y(this).toString()}(Ot=Nt||(Nt={})).afterCreate="afterCreate",Ot.afterAttach="afterAttach",Ot.beforeDetach="beforeDetach",Ot.beforeDestroy="beforeDestroy";var xt={name:"AnonymousModel",properties:{},initializers:X};function Rt(t){return Object.keys(t).reduce(function(t,e){var n,r,i;if(e in Nt)return nt("Hook '"+e+"' was defined as property. Hooks should be defined as part of the actions");var o=Object.getOwnPropertyDescriptor(t,e);"get"in o&&nt("Getters are not supported as properties. Please use views instead");var a=o.value;if(null==a)nt("The default value of an attribute cannot be null or undefined as the type cannot be inferred. Did you mean `types.maybe(someType)`?");else{if(pt(a))return Object.assign({},t,((n={})[e]=Xt(function(t){switch(typeof t){case"string":return Lt;case"number":return Ft;case"boolean":return Ht;case"object":if(t instanceof Date)return Jt}return nt("Cannot determine primitive type from value "+t)}(a),a),n));if(a instanceof _t)return Object.assign({},t,((r={})[e]=Xt(a,{}),r));if(a instanceof It)return Object.assign({},t,((i={})[e]=Xt(a,[]),i));if(P(a))return t;nt("Invalid type definition for property '"+e+"', cannot infer a type from a value like '"+a+"' ("+typeof a+")")}},t)}var kt=function(r){function e(t){var e=r.call(this,t.name||xt.name)||this;e.flags=b.Object,e.shouldAttachNode=!0;var n=t.name||xt.name;return/^\w[\w\d_]*$/.test(n)||nt("Typename should be a valid identifier: "+n),Object.assign(e,xt,t),e.properties=Rt(e.properties),ct(e.properties),e.propertyNames=Object.keys(e.properties),e.identifierAttribute=e._getIdentifierAttribute(),e}return a(e,r),e.prototype._getIdentifierAttribute=function(){var n=void 0;return this.forAllProps(function(t,e){e.flags&b.Identifier&&(n&&nt("Cannot define property '"+t+"' as object identifier, property '"+n+"' is already defined as identifier property"),n=t)}),n},e.prototype.cloneAndEnhance=function(t){return new e({name:t.name||this.name,properties:Object.assign({},this.properties,t.properties),initializers:this.initializers.concat(t.initializers||[]),preProcessor:t.preProcessor||this.preProcessor,postProcessor:t.postProcessor||this.postProcessor})},e.prototype.actions=function(e){var n=this;return this.cloneAndEnhance({initializers:[function(t){return n.instantiateActions(t,e(t)),t}]})},e.prototype.instantiateActions=function(s,u){st(u)||nt("actions initializer should return a plain object containing actions"),Object.keys(u).forEach(function(t){t===jt&&nt("Cannot define action '"+jt+"', it should be defined using 'type.preProcessSnapshot(fn)' instead"),t===Et&&nt("Cannot define action '"+Et+"', it should be defined using 'type.postProcessSnapshot(fn)' instead");var e=u[t],n=s[t];if(t in Nt&&n){var r=e;e=function(){n.apply(null,arguments),r.apply(null,arguments)}}var i=e.$mst_middleware,o=e.bind(u);o.$mst_middleware=i;var a=E(s,t,o);u[t]=a,lt(s,t,a)})},e.prototype.named=function(t){return this.cloneAndEnhance({name:t})},e.prototype.props=function(t){return this.cloneAndEnhance({properties:t})},e.prototype.volatile=function(e){var n=this;return this.cloneAndEnhance({initializers:[function(t){return n.instantiateVolatileState(t,e(t)),t}]})},e.prototype.instantiateVolatileState=function(t,e){st(e)||nt("volatile state initializer should return a plain object containing state"),l.set(t,e)},e.prototype.extend=function(s){var u=this;return this.cloneAndEnhance({initializers:[function(t){var e=s(t),n=e.actions,r=e.views,i=e.state,o=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&(n[r[i]]=t[r[i]])}return n}(e,["actions","views","state"]);for(var a in o)nt("The `extend` function should return an object with a subset of the fields 'actions', 'views' and 'state'. Found invalid key '"+a+"'");return i&&u.instantiateVolatileState(t,i),r&&u.instantiateViews(t,r),n&&u.instantiateActions(t,n),t}]})},e.prototype.views=function(e){var n=this;return this.cloneAndEnhance({initializers:[function(t){return n.instantiateViews(t,e(t)),t}]})},e.prototype.instantiateViews=function(i,o){st(o)||nt("views initializer should return a plain object containing views"),Object.keys(o).forEach(function(t){var e=Object.getOwnPropertyDescriptor(o,t),n=e.value;if("get"in e)if(l.isComputedProp(i,t)){var r=l._getAdministration(i,t);r.derivation=e.get,r.scope=i,e.set&&(r.setter=l.action(r.name+"-setter",e.set))}else l.computed(i,t,e,!0);else"function"==typeof n?lt(i,t,n):nt("A view member should either be a function or getter based property")})},e.prototype.preProcessSnapshot=function(e){var n=this.preProcessor;return n?this.cloneAndEnhance({preProcessor:function(t){return n(e(t))}}):this.cloneAndEnhance({preProcessor:e})},e.prototype.postProcessSnapshot=function(e){var n=this.postProcessor;return n?this.cloneAndEnhance({postProcessor:function(t){return e(n(t))}}):this.cloneAndEnhance({postProcessor:e})},e.prototype.instantiate=function(t,e,n,r){return W(this,t,e,n,J(r)?r:this.applySnapshotPreProcessor(r))},e.prototype.initializeChildNodes=function(n,r){void 0===r&&(r={});var t=n.type,i={};return t.forAllProps(function(t,e){i[t]=e.instantiate(n,t,n._environment,r[t])}),i},e.prototype.createNewInstance=function(t,e,n){return l.observable.object(e,tt,et)},e.prototype.finalizeNewInstance=function(e,n){lt(n,"toString",Dt),this.forAllProps(function(t){l._interceptReads(n,t,e.unbox)}),this.initializers.reduce(function(t,e){return e(t)},n),l.intercept(n,this.willChange),l.observe(n,this.didChange)},e.prototype.willChange=function(t){var e=Y(t.object);e.assertWritable();var n=e.type.properties[t.name];return n&&(t.newValue,t.newValue=n.reconcile(e.getChildNode(t.name),t.newValue)),t},e.prototype.didChange=function(t){var e=Y(t.object);if(e.type.properties[t.name]){var n=t.oldValue?t.oldValue.snapshot:void 0;e.emitPatch({op:"replace",path:vt(t.name),value:t.newValue.snapshot,oldValue:n},e)}},e.prototype.getChildren=function(n){var r=this,i=[];return this.forAllProps(function(t,e){i.push(r.getChildNode(n,t))}),i},e.prototype.getChildNode=function(t,e){if(!(e in this.properties))return nt("Not a value property: "+e);var n=l._getAdministration(t.storedValue,e).value;return n||nt("Node not available for property "+e)},e.prototype.getValue=function(t){return t.storedValue},e.prototype.getSnapshot=function(n,t){var r=this;void 0===t&&(t=!0);var i={};return this.forAllProps(function(t,e){l.getAtom(n.storedValue,t).reportObserved(),i[t]=r.getChildNode(n,t).snapshot}),t?this.applySnapshotPostProcessor(i):i},e.prototype.processInitialSnapshot=function(e,t){var n={};return Object.keys(e).forEach(function(t){n[t]=e[t].getSnapshot()}),this.applySnapshotPostProcessor(this.applyOptionalValuesToSnapshot(n))},e.prototype.applyPatchLocally=function(t,e,n){"replace"!==n.op&&"add"!==n.op&&nt("object does not support operation "+n.op),t.storedValue[e]=n.value},e.prototype.applySnapshot=function(n,t){var r=this.applySnapshotPreProcessor(t);this.forAllProps(function(t,e){n.storedValue[t]=r[t]})},e.prototype.applySnapshotPreProcessor=function(t){var e=this.preProcessor;return e?e.call(null,t):t},e.prototype.applyOptionalValuesToSnapshot=function(r){return r&&(r=Object.assign({},r),this.forAllProps(function(t,e){if(!(t in r)){var n=zt(e);n&&(r[t]=n.getDefaultValueSnapshot())}})),r},e.prototype.applySnapshotPostProcessor=function(t){var e=this.postProcessor;return e?e.call(null,t):t},e.prototype.getChildType=function(t){return this.properties[t]},e.prototype.isValidSnapshot=function(t,e){var n=this,r=this.applySnapshotPreProcessor(t);return st(r)?L(this.propertyNames.map(function(t){return n.properties[t].validate(r[t],k(e,t,n.properties[t]))})):M(e,r,"Value is not a plain object")},e.prototype.forAllProps=function(e){var n=this;this.propertyNames.forEach(function(t){return e(t,n.properties[t])})},e.prototype.describe=function(){var e=this;return"{ "+this.propertyNames.map(function(t){return t+": "+e.properties[t].describe()}).join("; ")+" }"},e.prototype.getDefaultSnapshot=function(){return tt},e.prototype.removeChild=function(t,e){t.storedValue[e]=void 0},n([l.action],e.prototype,"applySnapshot",null),e}(w);function zt(t){if(t)return t.flags&b.Union&&t.types?t.types.find(zt):t.flags&b.Late&&t.getSubType&&t.getSubType(!1)?zt(t.subType):t.flags&b.Optional?t:void 0}var Mt=function(o){function t(t,e,n,r){void 0===r&&(r=rt);var i=o.call(this,t)||this;return i.shouldAttachNode=!1,i.flags=e,i.checker=n,i.initializer=r,i}return a(t,o),t.prototype.describe=function(){return this.name},t.prototype.instantiate=function(t,e,n,r){return W(this,t,e,n,r)},t.prototype.createNewInstance=function(t,e,n){return this.initializer(n)},t.prototype.isValidSnapshot=function(t,e){return pt(t)&&this.checker(t)?z():M(e,t,"Value is not a "+("Date"===this.name?"Date or a unix milliseconds timestamp":this.name))},t}(A),Lt=new Mt("string",b.String,function(t){return"string"==typeof t}),Ft=new Mt("number",b.Number,function(t){return"number"==typeof t}),Ut=new Mt("integer",b.Integer,function(t){return it(t)}),Ht=new Mt("boolean",b.Boolean,function(t){return"boolean"==typeof t}),$t=new Mt("null",b.Null,function(t){return null===t}),Wt=new Mt("undefined",b.Undefined,function(t){return void 0===t}),Jt=new Mt("Date",b.Date,function(t){return"number"==typeof t||t instanceof Date},function(t){return t instanceof Date?t:new Date(t)});function Yt(t){return P(t)&&0<(t.flags&(b.String|b.Number|b.Integer|b.Boolean|b.Date))}Jt.getSnapshot=function(t){return t.storedValue.getTime()};var Zt=function(n){function t(t){var e=n.call(this,JSON.stringify(t))||this;return e.shouldAttachNode=!1,e.flags=b.Literal,e.value=t,e}return a(t,n),t.prototype.instantiate=function(t,e,n,r){return W(this,t,e,n,r)},t.prototype.describe=function(){return JSON.stringify(this.value)},t.prototype.isValidSnapshot=function(t,e){return pt(t)&&t===this.value?z():M(e,t,"Value is not a literal "+JSON.stringify(this.value))},t}(A);function Gt(t){return new Zt(t)}var Bt=function(o){function t(t,e,n,r){var i=o.call(this,t)||this;return i.type=e,i.predicate=n,i.message=r,i}return a(t,o),Object.defineProperty(t.prototype,"flags",{get:function(){return this.type.flags|b.Refinement},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"shouldAttachNode",{get:function(){return this.type.shouldAttachNode},enumerable:!0,configurable:!0}),t.prototype.describe=function(){return this.name},t.prototype.instantiate=function(t,e,n,r){return this.type.instantiate(t,e,n,r)},t.prototype.isAssignableFrom=function(t){return this.type.isAssignableFrom(t)},t.prototype.isValidSnapshot=function(t,e){var n=this.type.validate(t,e);if(0<n.length)return n;var r=J(t)?Y(t).snapshot:t;return this.predicate(r)?z():M(e,t,this.message(t))},t}(A);var Kt=function(i){function t(t,e,n){var r=i.call(this,t)||this;return r.eager=!0,n=o({eager:!0,dispatcher:void 0},n),r.dispatcher=n.dispatcher,n.eager||(r.eager=!1),r.types=e,r}return a(t,i),Object.defineProperty(t.prototype,"flags",{get:function(){var e=b.Union;return this.types.forEach(function(t){e|=t.flags}),e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"shouldAttachNode",{get:function(){return this.types.some(function(t){return t.shouldAttachNode})},enumerable:!0,configurable:!0}),t.prototype.isAssignableFrom=function(e){return this.types.some(function(t){return t.isAssignableFrom(e)})},t.prototype.describe=function(){return"("+this.types.map(function(t){return t.describe()}).join(" | ")+")"},t.prototype.instantiate=function(t,e,n,r){var i=this.determineType(r,void 0);return i?i.instantiate(t,e,n,r):nt("No matching type for union "+this.describe())},t.prototype.reconcile=function(t,e){var n=this.determineType(e,t.type);return n?n.reconcile(t,e):nt("No matching type for union "+this.describe())},t.prototype.determineType=function(e,n){return this.dispatcher?this.dispatcher(e):n?n.is(e)?n:this.types.filter(function(t){return t!==n}).find(function(t){return t.is(e)}):this.types.find(function(t){return t.is(e)})},t.prototype.isValidSnapshot=function(t,e){if(this.dispatcher)return this.dispatcher(t).validate(t,e);for(var n=[],r=0,i=0;i<this.types.length;i++){var o=this.types[i].validate(t,e);if(0===o.length){if(this.eager)return z();r++}else n.push(o)}return 1===r?z():M(e,t,"No type is applicable for the union").concat(L(n))},t}(A);function qt(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var r=P(t)?void 0:t,i=P(t)?[t].concat(e):e,o="("+i.map(function(t){return t.name}).join(" | ")+")";return new Kt(o,i,r)}var Qt=function(r){function t(t,e){var n=r.call(this,t.name)||this;return n.type=t,n.defaultValue=e,n}return a(t,r),Object.defineProperty(t.prototype,"flags",{get:function(){return this.type.flags|b.Optional},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"shouldAttachNode",{get:function(){return this.type.shouldAttachNode},enumerable:!0,configurable:!0}),t.prototype.describe=function(){return this.type.describe()+"?"},t.prototype.instantiate=function(t,e,n,r){if(void 0!==r)return this.type.instantiate(t,e,n,r);var i=this.getDefaultInstanceOrSnapshot();return this.type.instantiate(t,e,n,i)},t.prototype.reconcile=function(t,e){return this.type.reconcile(t,this.type.is(e)&&void 0!==e?e:this.getDefaultInstanceOrSnapshot())},t.prototype.getDefaultInstanceOrSnapshot=function(){var t="function"==typeof this.defaultValue?this.defaultValue():this.defaultValue;return this.defaultValue,t},t.prototype.getDefaultValueSnapshot=function(){var t=this.getDefaultInstanceOrSnapshot();return J(t)?Y(t).snapshot:t},t.prototype.isValidSnapshot=function(t,e){return void 0===t?z():this.type.validate(t,e)},t.prototype.isAssignableFrom=function(t){return this.type.isAssignableFrom(t)},t}(A);function Xt(t,e){return"function"!=typeof e&&J(e)&&nt("default value cannot be an instance, pass a snapshot or a function that creates an instance/snapshot instead"),new Qt(t,e)}var te=Xt(Wt,void 0),ee=Xt($t,null);var ne=function(r){function t(t,e){var n=r.call(this,t)||this;return n._subType=null,n.definition=e,n}return a(t,r),Object.defineProperty(t.prototype,"flags",{get:function(){return(this._subType?this._subType.flags:0)|b.Late},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"shouldAttachNode",{get:function(){return this.getSubType(!0).shouldAttachNode},enumerable:!0,configurable:!0}),t.prototype.getSubType=function(t){if(null===this._subType){var e=void 0;try{e=this.definition()}catch(t){if(!(t instanceof ReferenceError))throw t;e=void 0}if(t&&void 0===e&&nt("Late type seems to be used too early, the definition (still) returns undefined"),e)return this._subType=e}return this._subType},t.prototype.instantiate=function(t,e,n,r){return this.getSubType(!0).instantiate(t,e,n,r)},t.prototype.reconcile=function(t,e){return this.getSubType(!0).reconcile(t,e)},t.prototype.describe=function(){var t=this.getSubType(!1);return t?t.name:"<uknown late type>"},t.prototype.isValidSnapshot=function(t,e){var n=this.getSubType(!1);return n?n.validate(t,e):z()},t.prototype.isAssignableFrom=function(t){var e=this.getSubType(!1);return!!e&&e.isAssignableFrom(t)},t}(A);var re=function(n){function t(t){var e=n.call(this,t?"frozen("+t.name+")":"frozen")||this;return e.subType=t,e.shouldAttachNode=!1,e.flags=b.Frozen,e}return a(t,n),t.prototype.describe=function(){return"<any immutable value>"},t.prototype.instantiate=function(t,e,n,r){return W(this,t,e,n,r)},t.prototype.isValidSnapshot=function(t,e){return"function"==typeof t?M(e,t,"Value is not serializable and cannot be frozen"):this.subType?this.subType.validate(t,e):z()},t}(A),ie=new re;var oe=function(){function t(t,e,n){if(this.mode=t,this.value=e,this.targetType=n,"object"===t){if(!J(e))return nt("Can only store references to tree nodes, got: '"+e+"'");if(!Y(e).identifierAttribute)return nt("Can only store references with a defined identifier attribute.")}}return Object.defineProperty(t.prototype,"resolvedValue",{get:function(){var t=this.node,e=this.targetType,n=t.root.identifierCache.resolve(e,this.value);return n?n.value:nt("Failed to resolve reference '"+this.value+"' to type '"+this.targetType.name+"' (from node: "+t.path+")")},enumerable:!0,configurable:!0}),n([l.computed],t.prototype,"resolvedValue",null),t}(),ae=function(n){function t(t){var e=n.call(this,"reference("+t.name+")")||this;return e.targetType=t,e.shouldAttachNode=!1,e.flags=b.Reference,e}return a(t,n),t.prototype.describe=function(){return this.name},t.prototype.isAssignableFrom=function(t){return this.targetType.isAssignableFrom(t)},t.prototype.isValidSnapshot=function(t,e){return"string"==typeof t||"number"==typeof t?z():M(e,t,"Value is not a valid identifier, which is a string or a number")},t}(A),se=function(e){function t(t){return e.call(this,t)||this}return a(t,e),t.prototype.getValue=function(t){if(t.isAlive){var e=t.storedValue;return"object"===e.mode?e.value:e.resolvedValue}},t.prototype.getSnapshot=function(t){var e=t.storedValue;switch(e.mode){case"identifier":return e.value;case"object":return e.value[Y(e.value).identifierAttribute]}},t.prototype.instantiate=function(t,e,n,r){var i,o=J(r)?"object":"identifier",a=W(this,t,e,n,i=new oe(o,r,this.targetType));return i.node=a},t.prototype.reconcile=function(t,e){if(t.type===this){var n=J(e)?"object":"identifier",r=t.storedValue;if(n===r.mode&&r.value===e)return t}var i=this.instantiate(t.parent,t.subpath,t._environment,e);return t.die(),i},t}(ae),ue=function(r){function t(t,e){var n=r.call(this,t)||this;return n.options=e,n}return a(t,r),t.prototype.getValue=function(t){if(t.isAlive)return this.options.get(t.storedValue,t.parent?t.parent.storedValue:null)},t.prototype.getSnapshot=function(t){return t.storedValue},t.prototype.instantiate=function(t,e,n,r){return W(this,t,e,n,J(r)?this.options.set(r,t?t.storedValue:null):r)},t.prototype.reconcile=function(t,e){var n=J(e)?this.options.set(e,t?t.storedValue:null):e;if(t.type===this&&t.storedValue===n)return t;var r=this.instantiate(t.parent,t.subpath,t._environment,n);return t.die(),r},t}(ae);var pe=function(e){function t(){var t=e.call(this,"identifier")||this;return t.shouldAttachNode=!1,t.flags=b.Identifier,t}return a(t,e),t.prototype.instantiate=function(t,e,n,r){return t&&t.type instanceof kt||nt("Identifier types can only be instantiated as direct child of a model type"),W(this,t,e,n,r)},t.prototype.reconcile=function(t,e){return t.storedValue!==e?nt("Tried to change identifier from '"+t.storedValue+"' to '"+e+"'. Changing identifiers is not allowed."):t},t.prototype.describe=function(){return"identifier"},t.prototype.isValidSnapshot=function(t,e){return"string"!=typeof t?M(e,t,"Value is not a valid identifier, expected a string"):z()},t}(A),ce=function(i){function t(){var t=i.call(this)||this;return t.name="identifierNumber",t}return a(t,i),t.prototype.instantiate=function(t,e,n,r){return i.prototype.instantiate.call(this,t,e,n,r)},t.prototype.isValidSnapshot=function(t,e){return"number"==typeof t?z():M(e,t,"Value is not a valid identifierNumber, expected a number")},t.prototype.reconcile=function(t,e){return i.prototype.reconcile.call(this,t,e)},t.prototype.getSnapshot=function(t){return t.storedValue},t.prototype.describe=function(){return"identifierNumber"},t}(pe),le=new pe,he=new ce;var fe=function(n){function t(t){var e=n.call(this,t.name)||this;return e.options=t,e.flags=b.Reference,e.shouldAttachNode=!1,e}return a(t,n),t.prototype.describe=function(){return this.name},t.prototype.isAssignableFrom=function(t){return t===this},t.prototype.isValidSnapshot=function(t,e){if(this.options.isTargetType(t))return z();var n=this.options.getValidationMessage(t);return n?M(e,t,"Invalid value for type '"+this.name+"': "+n):z()},t.prototype.getValue=function(t){if(t.isAlive)return t.storedValue},t.prototype.getSnapshot=function(t){return this.options.toSnapshot(t.storedValue)},t.prototype.instantiate=function(t,e,n,r){return W(this,t,e,n,this.options.isTargetType(r)?r:this.options.fromSnapshot(r))},t.prototype.reconcile=function(t,e){var n=!this.options.isTargetType(e);if(t.type===this&&(n?e===t.snapshot:e===t.storedValue))return t;var r=n?this.options.fromSnapshot(e):e,i=this.instantiate(t.parent,t.subpath,t._environment,r);return t.die(),i},t}(A),de={enumeration:function(t,e){var n=qt.apply(void 0,("string"==typeof t?e:t).map(function(t){return Gt(""+t)}));return"string"==typeof t&&(n.name=t),n},model:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n="string"==typeof t[0]?t.shift():"AnonymousModel",r=t.shift()||{};return new kt({name:n,properties:r})},compose:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n="string"==typeof t[0]?t.shift():"AnonymousModel";return t.reduce(function(e,n){return e.cloneAndEnhance({name:e.name+"_"+n.name,properties:n.properties,initializers:n.initializers,preProcessor:function(t){return n.applySnapshotPreProcessor(e.applySnapshotPreProcessor(t))},postProcessor:function(t){return n.applySnapshotPostProcessor(e.applySnapshotPostProcessor(t))}})}).named(n)},custom:function(t){return new fe(t)},reference:function(t,e){return e?new ue(t,e):new se(t)},union:qt,optional:Xt,literal:Gt,maybe:function(t){return qt(t,te)},maybeNull:function(t){return qt(t,ee)},refinement:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n="string"==typeof t[0]?t.shift():P(t[0])?t[0].name:null,r=t[0],i=t[1],o=t[2]?t[2]:function(t){return"Value does not respect the refinement predicate"};return new Bt(n,r,i,o)},string:Lt,boolean:Ht,number:Ft,integer:Ut,Date:Jt,map:function(t){return new _t("map<string, "+t.name+">",t)},array:function(t){return new It(t.name+"[]",t)},frozen:function(t){return 0===arguments.length?ie:P(t)?new re(t):Xt(ie,t)},identifier:le,identifierNumber:he,late:function(t,e){var n="string"==typeof t?t:"late("+t.toString()+")";return new ne(n,"string"==typeof t?e:t)},undefined:Wt,null:$t};t.types=de,t.typecheck=F,t.escapeJsonPath=vt,t.unescapeJsonPath=bt,t.joinJsonPath=gt,t.splitJsonPath=mt,t.decorate=function(t,e){var n={handler:t,includeHooks:!0};return e.$mst_middleware&&e.$mst_middleware.push(n),e.$mst_middleware=[n],e},t.addMiddleware=D,t.process=function(t){return dt("process","`process()` has been renamed to `flow()`. See https://github.com/mobxjs/mobx-state-tree/issues/399 for more information. Note that the middleware event types starting with `process` now start with `flow`."),yt(t)},t.isStateTreeNode=J,t.flow=yt,t.applyAction=V,t.onAction=T,t.recordActions=function(t){var e={actions:[],stop:function(){return n()},replay:function(t){V(t,e.actions)}},n=T(t,e.actions.push.bind(e.actions));return e},t.createActionTrackingMiddleware=function(a){return function(e,t,n){switch(e.type){case"action":if(a.filter&&!0!==a.filter(e))return t(e);var r=a.onStart(e);a.onResume(e,r),_.set(e.id,{call:e,context:r,async:!1});try{var i=t(e);return a.onSuspend(e,r),!1===_.get(e.id).async&&(_.delete(e.id),a.onSuccess(e,r,i)),i}catch(t){throw _.delete(e.id),a.onFail(e,r,t),t}case"flow_spawn":return(o=_.get(e.rootId)).async=!0,t(e);case"flow_resume":case"flow_resume_error":var o=_.get(e.rootId);a.onResume(e,o.context);try{return t(e)}finally{a.onSuspend(e,o.context)}case"flow_throw":return o=_.get(e.rootId),_.delete(e.id),a.onFail(e,o.context,e.args[0]),t(e);case"flow_return":return o=_.get(e.rootId),_.delete(e.id),a.onSuccess(e,o.context,e.args[0]),t(e)}}},t.setLivelynessChecking=function(t){v=t},t.getType=u,t.getChildType=function(t,e){return Y(t).getChildType(e)},t.onPatch=i,t.onSnapshot=function(t,e){return Y(t).onSnapshot(e)},t.applyPatch=s,t.recordPatches=function(e){var t=null;function n(){t||(t=i(e,function(t,e){r.rawPatches.push([t,e])}))}var r={rawPatches:[],get patches(){return this.rawPatches.map(function(t){return t[0]})},get inversePatches(){return this.rawPatches.map(function(t){return t[0],t[1]})},stop:function(){t&&t(),t=null},resume:n,replay:function(t){s(t||e,r.patches)},undo:function(t){s(t||e,r.inversePatches.slice().reverse())}};return n(),r},t.protect=function(t){var e=Y(t);e.isRoot||nt("`protect` can only be invoked on root nodes"),e.isProtectionEnabled=!0},t.unprotect=function(t){var e=Y(t);e.isRoot||nt("`unprotect` can only be invoked on root nodes"),e.isProtectionEnabled=!1},t.isProtected=function(t){return Y(t).isProtected},t.applySnapshot=p,t.getSnapshot=function(t,e){void 0===e&&(e=!0);var n=Y(t);return e?n.snapshot:ct(n.type.getSnapshot(n,!1))},t.hasParent=function(t,e){void 0===e&&(e=1);for(var n=Y(t).parent;n;){if(0==--e)return!0;n=n.parent}return!1},t.getParent=function(t,e){void 0===e&&(e=1);for(var n=e,r=Y(t).parent;r;){if(0==--n)return r.storedValue;r=r.parent}return nt("Failed to find the parent of "+Y(t)+" at depth "+e)},t.hasParentOfType=function(t,e){for(var n=Y(t).parent;n;){if(e.is(n.storedValue))return!0;n=n.parent}return!1},t.getParentOfType=function(t,e){for(var n=Y(t).parent;n;){if(e.is(n.storedValue))return n.storedValue;n=n.parent}return nt("Failed to find the parent of "+Y(t)+" of a given type")},t.getRoot=c,t.getPath=function(t){return Y(t).path},t.getPathParts=function(t){return mt(Y(t).path)},t.isRoot=function(t){return Y(t).isRoot},t.resolvePath=function(t,e){var n=K(Y(t),e);return n?n.value:void 0},t.resolveIdentifier=function(t,e,n){var r=Y(e).root.identifierCache.resolve(t,""+n);return r?r.value:void 0},t.getIdentifier=function(t){return Y(t).identifier},t.tryResolve=h,t.getRelativePath=function(t,e){return B(Y(t),Y(e))},t.clone=function(t,e){void 0===e&&(e=!0);var n=Y(t);return n.type.create(n.snapshot,!0===e?n.root._environment:!1===e?void 0:e)},t.detach=function(t){return Y(t).detach(),t},t.destroy=function(t){var e=Y(t);e.isRoot?e.die():e.parent.removeChild(e.subpath)},t.isAlive=function(t){return Y(t).isAlive},t.addDisposer=function(t,e){Y(t).addDisposer(e)},t.getEnv=function(t){var e=Y(t).root._environment;return e||tt},t.walk=f,t.getMembers=function(n){var t=Y(n).type,r=o({},e(t),{actions:[],volatile:[],views:[]});return Object.getOwnPropertyNames(n).forEach(function(t){if(!(t in r.properties)){var e=Object.getOwnPropertyDescriptor(n,t);e.get?l.isComputedProp(n,t)?r.views.push(t):r.volatile.push(t):!0===e.value._isMSTAction?r.actions.push(t):l.isObservableProp(n,t)?r.volatile.push(t):r.views.push(t)}}),r},t.getPropertyMembers=e,t.cast=function(t){return t},t.isType=P,t.isArrayType=function(t){return P(t)&&0<(t.flags&b.Array)},t.isFrozenType=function(t){return P(t)&&0<(t.flags&b.Frozen)},t.isIdentifierType=function(t){return P(t)&&0<(t.flags&b.Identifier)},t.isLateType=function(t){return P(t)&&0<(t.flags&b.Late)},t.isLiteralType=function(t){return P(t)&&0<(t.flags&b.Literal)},t.isMapType=function(t){return P(t)&&0<(t.flags&b.Map)},t.isModelType=function(t){return P(t)&&0<(t.flags&b.Object)},t.isOptionalType=function(t){return P(t)&&0<(t.flags&b.Optional)},t.isPrimitiveType=Yt,t.isReferenceType=function(t){return 0<(t.flags&b.Reference)},t.isRefinementType=function(t){return 0<(t.flags&b.Refinement)},t.isUnionType=function(t){return 0<(t.flags&b.Union)},Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("mobx")):"function"==typeof define&&define.amd?define(["exports","mobx"],e):e(t.mobxStateTree={},t.mobx)}(this,function(t,l){"use strict";var r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};function a(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var o=function(){return(o=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function n(t,e,n,r){var i,o=arguments.length,a=o<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,n,r);else for(var s=t.length-1;0<=s;s--)(i=t[s])&&(a=(o<3?i(a):3<o?i(e,n,a):i(e,n))||a);return 3<o&&a&&Object.defineProperty(e,n,a),a}function u(t){return Z(t).type}function i(t,e){return Z(t).onPatch(e)}function s(t,e){Z(t).applyPatches(st(e))}function p(t,e){return Z(t).applySnapshot(e)}function c(t){return Z(t).root.storedValue}function h(t,e){var n=q(Z(t),e,!1);if(void 0!==n)try{return n.value}catch(t){return}}function f(t,e){var n=Z(t);n.getChildren().forEach(function(t){Y(t.storedValue)&&f(t.storedValue,e)}),e(n.storedValue)}function e(t){var e;return{name:(e=Y(t)?u(t):t).name,properties:o({},e.properties)}}var d=function(){function t(t,e,n,r,i){this.parent=null,this.subpath="",this.state=U.INITIALIZING,this._environment=void 0,this._initialSnapshot=i,this.type=t,this.parent=e,this.subpath=n;var o=!0;try{this.storedValue=t.createNewInstance(this,{},i),this.state=U.CREATED,o=!1}finally{o&&(this.state=U.DEAD)}}return Object.defineProperty(t.prototype,"path",{get:function(){return this.parent?this.parent.path+"/"+bt(this.subpath):""},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isRoot",{get:function(){return null===this.parent},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"root",{get:function(){return this.parent?this.parent.root:rt("This scalar node is not part of a tree")},enumerable:!0,configurable:!0}),t.prototype.setParent=function(t,e){if(void 0===e&&(e=null),this.parent!==t||this.subpath!==e)if(this.parent&&!t)this.die();else{var n=null===e?"":e;this.subpath!==n&&(this.subpath=n),t&&t!==this.parent&&(this.parent=t)}},Object.defineProperty(t.prototype,"value",{get:function(){return this.type.getValue(this)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"snapshot",{get:function(){return lt(this.getSnapshot())},enumerable:!0,configurable:!0}),t.prototype.getSnapshot=function(){return this.type.getSnapshot(this)},Object.defineProperty(t.prototype,"isAlive",{get:function(){return this.state!==U.DEAD},enumerable:!0,configurable:!0}),t.prototype.toString=function(){return this.type.name+"@"+(this.path||"<root>")+(this.isAlive?"":"[dead]")},t.prototype.die=function(){this.state=U.DEAD},t}(),y=1,v="warn";var b,g,m={onError:function(t){throw t}},S=function(){function r(t,e,n,r,i){if(this.nodeId=++y,this.subpathAtom=l.createAtom("path"),this.subpath="",this.parent=null,this.state=U.INITIALIZING,this.isProtectionEnabled=!0,this.middlewares=null,this._autoUnbox=!0,this._environment=void 0,this._isRunningAction=!1,this._hasSnapshotReaction=!1,this._disposers=null,this._patchSubscribers=null,this._snapshotSubscribers=null,this._observableInstanceCreated=!1,this._cachedInitialSnapshot=null,this._environment=r,this._initialSnapshot=lt(i),this.type=t,this.parent=e,this.subpath=n,this.escapedSubpath=bt(this.subpath),this.identifierAttribute=t.identifierAttribute,e||(this.identifierCache=new W),this._childNodes=t.initializeChildNodes(this,this._initialSnapshot),this.identifier=null,this.unnormalizedIdentifier=null,this.identifierAttribute&&this._initialSnapshot){var o=this._initialSnapshot[this.identifierAttribute];if(void 0===o){var a=this._childNodes[this.identifierAttribute];a&&(o=a.value)}"string"!=typeof o&&"number"!=typeof o&&rt("Instance identifier '"+this.identifierAttribute+"' for type '"+this.type.name+"' must be a string or a number"),this.identifier=""+o,this.unnormalizedIdentifier=o}e?e.root.identifierCache.addNodeToCache(this):this.identifierCache.addNodeToCache(this)}return r.prototype.applyPatches=function(t){this._observableInstanceCreated||this._createObservableInstance(),this.applyPatches(t)},r.prototype.applySnapshot=function(t){this._observableInstanceCreated||this._createObservableInstance(),this.applySnapshot(t)},r.prototype._createObservableInstance=function(){var t=this.type;this.storedValue=t.createNewInstance(this,this._childNodes,this._initialSnapshot),this.preboot();var e,n,r=!0;this._observableInstanceCreated=!0;try{this._isRunningAction=!0,t.finalizeNewInstance(this,this.storedValue),this._isRunningAction=!1,this.fireHook("afterCreate"),this.state=U.CREATED,r=!1}finally{r&&(this.state=U.DEAD)}e=this,n="snapshot",l.getAtom(e,n).trackAndCompute(),this.isRoot&&this._addSnapshotReaction(),this.finalizeCreation(),this._childNodes=et},Object.defineProperty(r.prototype,"path",{get:function(){return this.subpathAtom.reportObserved(),this.parent?this.parent.path+"/"+this.escapedSubpath:""},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"root",{get:function(){var t=this.parent;return t?t.root:this},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"isRoot",{get:function(){return null===this.parent},enumerable:!0,configurable:!0}),r.prototype.setParent=function(t,e){if(void 0===e&&(e=null),this.parent!==t||this.subpath!==e)if(this.parent&&!t)this.die();else{var n=null===e?"":e;this.subpath!==n&&(this.subpath=n,this.escapedSubpath=bt(this.subpath),this.subpathAtom.reportChanged()),t&&t!==this.parent&&(t.root.identifierCache.mergeCache(this),this.parent=t,this.subpathAtom.reportChanged(),this.fireHook("afterAttach"))}},r.prototype.fireHook=function(t){var e=this,n=this.storedValue&&"object"==typeof this.storedValue&&this.storedValue[t];"function"==typeof n&&(l._allowStateChangesInsideComputed?l._allowStateChangesInsideComputed(function(){n.apply(e.storedValue)}):n.apply(this.storedValue))},r.prototype.createObservableInstanceIfNeeded=function(){this._observableInstanceCreated||this._createObservableInstance()},Object.defineProperty(r.prototype,"isObservableInstanceCreated",{get:function(){return this._observableInstanceCreated},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"value",{get:function(){if(this.createObservableInstanceIfNeeded(),this.isAlive)return this.type.getValue(this)},enumerable:!0,configurable:!0}),Object.defineProperty(r.prototype,"snapshot",{get:function(){if(this.isAlive)return lt(this.getSnapshot())},enumerable:!0,configurable:!0}),r.prototype.getSnapshot=function(){if(this.isAlive)return this._observableInstanceCreated?this._getActualSnapshot():this._getInitialSnapshot()},r.prototype._getActualSnapshot=function(){return this.type.getSnapshot(this)},r.prototype._getInitialSnapshot=function(){if(this.isAlive){if(!this._initialSnapshot)return this._initialSnapshot;if(this._cachedInitialSnapshot)return this._cachedInitialSnapshot;var t=this.type,e=this._childNodes,n=this._initialSnapshot;return this._cachedInitialSnapshot=t.processInitialSnapshot(e,n),this._cachedInitialSnapshot}},r.prototype.isRunningAction=function(){return!!this._isRunningAction||!this.isRoot&&this.parent.isRunningAction()},Object.defineProperty(r.prototype,"isAlive",{get:function(){return this.state!==U.DEAD},enumerable:!0,configurable:!0}),r.prototype.assertAlive=function(){if(!this.isAlive){var t="[mobx-state-tree][error] You are trying to read or write to an object that is no longer part of a state tree. (Object type was '"+this.type.name+"'). Either detach nodes first, or don't use objects after removing / replacing them in the tree.";switch(v){case"error":throw new Error(t);case"warn":console.warn(t+' Use setLivelynessChecking("error") to simplify debugging this error.')}}},r.prototype.getChildNode=function(t){this.assertAlive(),this._autoUnbox=!1;try{return this._observableInstanceCreated?this.type.getChildNode(this,t):this._childNodes[t]}finally{this._autoUnbox=!0}},r.prototype.getChildren=function(){this.assertAlive(),this._autoUnbox=!1;try{return this._observableInstanceCreated?this.type.getChildren(this):X(this._childNodes)}finally{this._autoUnbox=!0}},r.prototype.getChildType=function(t){return this.type.getChildType(t)},Object.defineProperty(r.prototype,"isProtected",{get:function(){return this.root.isProtectionEnabled},enumerable:!0,configurable:!0}),r.prototype.assertWritable=function(){this.assertAlive(),!this.isRunningAction()&&this.isProtected&&rt("Cannot modify '"+this+"', the object is protected and can only be modified by using an action.")},r.prototype.removeChild=function(t){this.type.removeChild(this,t)},r.prototype.unbox=function(t){return t&&t.parent&&t.parent.assertAlive(),t&&t.parent&&t.parent._autoUnbox?t.value:t},r.prototype.toString=function(){var t=this.identifier?"(id: "+this.identifier+")":"";return this.type.name+"@"+(this.path||"<root>")+t+(this.isAlive?"":"[dead]")},r.prototype.finalizeCreation=function(){if(this.state===U.CREATED){if(this.parent){if(this.parent.state!==U.FINALIZED)return;this.fireHook("afterAttach")}this.state=U.FINALIZED;for(var t=0,e=this.getChildren();t<e.length;t++){var n=e[t];n instanceof r&&n.finalizeCreation()}}},r.prototype.detach=function(){this.isAlive||rt("Error while detaching, node is not alive."),this.isRoot||(this.fireHook("beforeDetach"),this._environment=this.root._environment,this.state=U.DETACHING,this.identifierCache=this.root.identifierCache.splitCache(this),this.parent.removeChild(this.subpath),this.parent=null,this.subpath=this.escapedSubpath="",this.subpathAtom.reportChanged(),this.state=U.FINALIZED)},r.prototype.preboot=function(){var n=this;this.applyPatches=E(this.storedValue,"@APPLY_PATCHES",function(t){t.forEach(function(t){var e=St(t.path);Q(n,e.slice(0,-1)).applyPatchLocally(e[e.length-1],t)})}),this.applySnapshot=E(this.storedValue,"@APPLY_SNAPSHOT",function(t){if(t!==n.snapshot)return n.type.applySnapshot(n,t)}),ht(this.storedValue,"$treenode",this),ht(this.storedValue,"toJSON",G)},r.prototype.die=function(){this.state!==U.DETACHING&&Y(this.storedValue)&&(f(this.storedValue,function(t){var e=Z(t);e instanceof r&&e.aboutToDie()}),f(this.storedValue,function(t){var e=Z(t);e instanceof r&&e.finalizeDeath()}))},r.prototype.aboutToDie=function(){this._disposers&&(this._disposers.forEach(function(t){return t()}),this._disposers=null),this.fireHook("beforeDestroy")},r.prototype.finalizeDeath=function(){var t,e,n;this.root.identifierCache.notifyDied(this),e="snapshot",n=(t=this).snapshot,Object.defineProperty(t,e,{enumerable:!0,writable:!1,configurable:!0,value:n}),this._patchSubscribers&&(this._patchSubscribers=null),this._snapshotSubscribers&&(this._snapshotSubscribers=null),this.state=U.DEAD,this.subpath=this.escapedSubpath="",this.parent=null,this.subpathAtom.reportChanged()},r.prototype.onSnapshot=function(t){return this._addSnapshotReaction(),this._snapshotSubscribers||(this._snapshotSubscribers=[]),ft(this._snapshotSubscribers,t)},r.prototype.emitSnapshot=function(e){this._snapshotSubscribers&&this._snapshotSubscribers.forEach(function(t){return t(e)})},r.prototype.onPatch=function(t){return this._patchSubscribers||(this._patchSubscribers=[]),ft(this._patchSubscribers,t)},r.prototype.emitPatch=function(t,e){var n=this._patchSubscribers;if(n&&n.length){var r=function(t){"oldValue"in t||rt("Patches without `oldValue` field cannot be inversed");return[function(t){switch(t.op){case"add":return{op:"add",path:t.path,value:t.value};case"remove":return{op:"remove",path:t.path};case"replace":return{op:"replace",path:t.path,value:t.value}}}(t),function(t){switch(t.op){case"add":return{op:"remove",path:t.path};case"remove":return{op:"add",path:t.path,value:t.oldValue};case"replace":return{op:"replace",path:t.path,value:t.oldValue}}}(t)]}(function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];for(var r=0;r<e.length;r++){var i=e[r];for(var o in i)t[o]=i[o]}return t}({},t,{path:e.path.substr(this.path.length)+"/"+t.path})),i=r[0],o=r[1];n.forEach(function(t){return t(i,o)})}this.parent&&this.parent.emitPatch(t,e)},r.prototype.addDisposer=function(t){this._disposers?this._disposers.unshift(t):this._disposers=[t]},r.prototype.removeMiddleware=function(e){this.middlewares&&(this.middlewares=this.middlewares.filter(function(t){return t.handler!==e}))},r.prototype.addMiddleWare=function(t,e){var n=this;return void 0===e&&(e=!0),this.middlewares?this.middlewares.push({handler:t,includeHooks:e}):this.middlewares=[{handler:t,includeHooks:e}],function(){n.removeMiddleware(t)}},r.prototype.applyPatchLocally=function(t,e){this.assertWritable(),this._observableInstanceCreated||this._createObservableInstance(),this.type.applyPatchLocally(this,t,e)},r.prototype._addSnapshotReaction=function(){var e=this;if(!this._hasSnapshotReaction){var t=l.reaction(function(){return e.snapshot},function(t){return e.emitSnapshot(t)},m);this.addDisposer(t),this._hasSnapshotReaction=!0}},n([l.action],r.prototype,"_createObservableInstance",null),n([l.computed],r.prototype,"snapshot",null),n([l.action],r.prototype,"detach",null),n([l.action],r.prototype,"die",null),r}();(g=b||(b={}))[g.String=1]="String",g[g.Number=2]="Number",g[g.Boolean=4]="Boolean",g[g.Date=8]="Date",g[g.Literal=16]="Literal",g[g.Array=32]="Array",g[g.Map=64]="Map",g[g.Object=128]="Object",g[g.Frozen=256]="Frozen",g[g.Optional=512]="Optional",g[g.Reference=1024]="Reference",g[g.Identifier=2048]="Identifier",g[g.Late=4096]="Late",g[g.Refinement=8192]="Refinement",g[g.Union=16384]="Union",g[g.Null=32768]="Null",g[g.Undefined=65536]="Undefined",g[g.Integer=131072]="Integer";var w=function(){function t(t){this["!!complexType"]=void 0,this.isType=!0,this.name=t}return t.prototype.create=function(t,e){return void 0===t&&(t=this.getDefaultSnapshot()),this.instantiate(null,"",e,t).value},t.prototype.initializeChildNodes=function(t,e){return et},t.prototype.createNewInstance=function(t,e,n){return n},t.prototype.finalizeNewInstance=function(t,e){},t.prototype.processInitialSnapshot=function(t,e){return e},t.prototype.isAssignableFrom=function(t){return t===this},t.prototype.validate=function(t,e){return Y(t)?u(t)===this||this.isAssignableFrom(u(t))?z():k(e,t):this.isValidSnapshot(t,e)},t.prototype.is=function(t){return 0===this.validate(t,[{path:"",type:this}]).length},t.prototype.reconcile=function(t,e){if(t.snapshot===e)return t;if(Y(e)&&Z(e)===t)return t;if(t.type===this&&pt(e)&&!Y(e)&&(!t.identifierAttribute||t.identifier===""+e[t.identifierAttribute]))return t.applySnapshot(e),t;var n=t.parent,r=t.subpath;if(t.die(),Y(e)&&this.isAssignableFrom(u(e))){var i=Z(e);return i.setParent(n,r),i}return this.instantiate(n,r,t._environment,e)},Object.defineProperty(t.prototype,"Type",{get:function(){return rt("Factory.Type should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.Type`")},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"SnapshotType",{get:function(){return rt("Factory.SnapshotType should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.SnapshotType`")},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"CreationType",{get:function(){return rt("Factory.CreationType should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.CreationType`")},enumerable:!0,configurable:!0}),n([l.action],t.prototype,"create",null),t}(),A=function(e){function t(t){return e.call(this,t)||this}return a(t,e),t.prototype.getValue=function(t){return t.storedValue},t.prototype.getSnapshot=function(t){return t.storedValue},t.prototype.getDefaultSnapshot=function(){},t.prototype.applySnapshot=function(t,e){rt("Immutable types do not support applying snapshots")},t.prototype.applyPatchLocally=function(t,e,n){rt("Immutable types do not support applying patches")},t.prototype.getChildren=function(t){return tt},t.prototype.getChildNode=function(t,e){return rt("No child '"+e+"' available in type: "+this.name)},t.prototype.getChildType=function(t){return rt("No child '"+t+"' available in type: "+this.name)},t.prototype.reconcile=function(t,e){if(t.type===this&&t.storedValue===e)return t;var n=this.instantiate(t.parent,t.subpath,t._environment,e);return t.die(),n},t.prototype.removeChild=function(t,e){return rt("No child '"+e+"' available in type: "+this.name)},t}(w);function P(t){return"object"==typeof t&&t&&!0===t.isType}var I=new Map;function _(t){return{$MST_UNSERIALIZABLE:!0,type:t}}function V(e,t){l.runInAction(function(){st(t).forEach(function(t){return function(t,e){var n=h(t,e.path||"");if(!n)return rt("Invalid action path: "+(e.path||""));var r=Z(n);if("@APPLY_PATCHES"===e.name)return s.call(null,n,e.args[0]);if("@APPLY_SNAPSHOT"===e.name)return p.call(null,n,e.args[0]);"function"!=typeof n[e.name]&&rt("Action '"+e.name+"' does not exist in '"+r.path+"'");return n[e.name].apply(n,e.args?e.args.map(function(t){return(e=t)&&"object"==typeof e&&"$MST_DATE"in e?new Date(e.$MST_DATE):e;var e}):[])}(e,t)})})}function C(o,a,s){return void 0===s&&(s=!1),D(o,function(n,t){if("action"!==n.type||n.id!==n.rootId)return t(n);var e=Z(n.context),r={name:n.name,path:K(Z(o),e),args:n.args.map(function(t,e){return function(t,e,n,r){if(r instanceof Date)return{$MST_DATE:r.getTime()};if(ct(r))return r;if(Y(r))return _("[MSTNode: "+u(r).name+"]");if("function"==typeof r)return _("[function]");if("object"==typeof r&&!ut(r)&&!at(r))return _("[object "+(r&&r.constructor&&r.constructor.name||"Complex Object")+"]");try{return JSON.stringify(r),r}catch(t){return _(""+t)}}(0,n.name,0,t)})};if(s){var i=t(n);return a(r),i}return a(r),t(n)})}var T=1,N=null;function O(){return T++}function j(t,e){var n=Z(t.context),r=n._isRunningAction,i=N;"action"===t.type&&n.assertAlive(),n._isRunningAction=!0,N=t;try{return function(t,e,s){var u=function(t,e,n){var r=n.$mst_middleware||tt,i=t;for(;i;)i.middlewares&&(r=r.concat(i.middlewares)),i=i.parent;return r}(t,0,s);if(!u.length)return l.action(s).apply(null,e.args);var p=0,c=null;return function n(t){var e=u[p++];var r=e&&e.handler;function i(t,e){c=e?e(n(t)||c):n(t)}function o(t){c=t}var a=function(){return r(t,i,o),c};return r&&e.includeHooks?a():r&&!e.includeHooks?Ot[t.name]?n(t):a():l.action(s).apply(null,t.args)}(e)}(n,t,e)}finally{N=i,n._isRunningAction=r}}function E(e,n,r){var t=function(){var t=O();return j({type:"action",name:n,id:t,args:dt(arguments),context:e,tree:c(e),rootId:N?N.rootId:t,parentId:N?N.id:0,allParentIds:N?N.allParentIds.concat([N.id]):[]},r)};return t._isMSTAction=!0,t}function D(t,e,n){return void 0===n&&(n=!0),Z(t).addMiddleWare(e,n)}function x(t){return"function"==typeof t?"<function"+(t.name?" "+t.name:"")+">":Y(t)?"<"+t+">":"`"+function(t){try{return JSON.stringify(t)}catch(t){return"<Unserializable: "+t+">"}}(t)+"`"}function R(t){var e=t.value,n=t.context[t.context.length-1].type,r=t.context.map(function(t){return t.path}).filter(function(t){return 0<t.length}).join("/"),i=0<r.length?'at path "/'+r+'" ':"",o=Y(e)?"value of type "+Z(e).type.name+":":ct(e)?"value":"snapshot",a=n&&Y(e)&&n.is(Z(e).snapshot);return""+i+o+" "+x(e)+" is not assignable "+(n?"to type: `"+n.name+"`":"")+(t.message?" ("+t.message+")":"")+(n?Zt(n)||ct(e)?".":", expected an instance of `"+n.name+"` or a snapshot like `"+n.describe()+"` instead."+(a?" (Note that a snapshot of the provided value is compatible with the targeted type)":""):".")}function M(t,e,n){return t.concat([{path:e,type:n}])}function z(){return tt}function k(t,e,n){return[{context:t,value:e,message:n}]}function L(t){return t.reduce(function(t,e){return t.concat(e)},[])}function F(t,e){var n,r=t.validate(e,[{path:"",type:t}]);0<r.length&&rt("Error while converting "+((n=x(e)).length<280?n:n.substring(0,272)+"......"+n.substring(n.length-8))+" to `"+t.name+"`:\n\n "+r.map(R).join("\n "))}var U,H,$=0,W=function(){function e(){this.cacheId=$++,this.cache=l.observable.map(),this.lastCacheModificationPerId=l.observable.map()}return e.prototype.updateLastCacheModificationPerId=function(t){var e=this.lastCacheModificationPerId.get(t);this.lastCacheModificationPerId.set(t,void 0===e?1:e+1)},e.prototype.getLastCacheModificationPerId=function(t){var e=this.lastCacheModificationPerId.get(t)||0;return this.cacheId+"-"+e},e.prototype.addNodeToCache=function(t,e){if(void 0===e&&(e=!0),t.identifierAttribute){var n=t.identifier;this.cache.has(n)||this.cache.set(n,l.observable.array([],nt));var r=this.cache.get(n);-1!==r.indexOf(t)&&rt("Already registered"),r.push(t),e&&this.updateLastCacheModificationPerId(n)}},e.prototype.mergeCache=function(t){var e=this;l.values(t.identifierCache.cache).forEach(function(t){return t.forEach(function(t){e.addNodeToCache(t)})})},e.prototype.notifyDied=function(t){if(t.identifierAttribute){var e=t.identifier,n=this.cache.get(e);n&&(n.remove(t),n.length||this.cache.delete(e),this.updateLastCacheModificationPerId(t.identifier))}},e.prototype.splitCache=function(t){var o=this,a=new e,s=t.path;return l.entries(this.cache).forEach(function(t){for(var e=t[0],n=t[1],r=!1,i=n.length-1;0<=i;i--)0===n[i].path.indexOf(s)&&(a.addNodeToCache(n[i],!1),n.splice(i,1),r=!0);r&&o.updateLastCacheModificationPerId(e)}),a},e.prototype.resolve=function(e,t){var n=this.cache.get(""+t);if(!n)return null;var r=n.filter(function(t){return e.isAssignableFrom(t.type)});switch(r.length){case 0:return null;case 1:var i=r[0];if(i){for(var o=[],a=i.parent;a&&!a.isObservableInstanceCreated;)o.unshift(a),a=a.parent;for(var s=0,u=o;s<u.length;s++){u[s].createObservableInstanceIfNeeded()}}return i;default:return rt("Cannot resolve a reference to type '"+e.name+"' with id: '"+t+"' unambigously, there are multiple candidates: "+r.map(function(t){return t.path}).join(", "))}},e}();function J(t,e,n,r,i){var o,a=(o=i)&&o.$treenode||null;if(a){if(a.isRoot)return a.setParent(e,n),a;rt("Cannot add an object to a state tree if it is already part of the same or another state tree. Tried to assign an object to '"+(e?e.path:"")+"/"+n+"', but it lives already at '"+a.path+"'")}return new(t.shouldAttachNode?S:d)(t,e,n,r,i)}function Y(t){return!(!t||!t.$treenode)}function Z(t){return Y(t)?t.$treenode:rt("Value "+t+" is no MST Node")}function G(){return Z(this).snapshot}(H=U||(U={}))[H.INITIALIZING=0]="INITIALIZING",H[H.CREATED=1]="CREATED",H[H.FINALIZED=2]="FINALIZED",H[H.DETACHING=3]="DETACHING",H[H.DEAD=4]="DEAD";var B=function(t){return".."};function K(t,e){t.root!==e.root&&rt("Cannot calculate relative path: objects '"+t+"' and '"+e+"' are not part of the same object tree");for(var n=St(t.path),r=St(e.path),i=0;i<n.length&&n[i]===r[i];i++);return n.slice(i).map(B).join("/")+mt(r.slice(i))}function q(t,e,n){return void 0===n&&(n=!0),Q(t,St(e),n)}function Q(t,e,n){void 0===n&&(n=!0);for(var r=t,i=0;i<e.length;i++){var o=e[i];if(""!==o){if(".."===o){if(r=r.parent)continue}else{if("."===o||""===o)continue;if(r){if(r instanceof d)try{var a=r.value;Y(a)&&(r=Z(a))}catch(t){if(!n)return;throw t}if(r instanceof S)if(r.getChildType(o)&&(r=r.getChildNode(o)))continue}}return n?rt("Could not resolve '"+o+"' in path '"+(mt(e.slice(0,i))||"/")+"' while resolving '"+mt(e)+"'"):void 0}r=r.root}return r}function X(n){if(!n)return tt;var t=Object.keys(n);if(!t.length)return tt;var r=new Array(t.length);return t.forEach(function(t,e){r[e]=n[t]}),r}var tt=Object.freeze([]),et=Object.freeze({}),nt="string"==typeof l.$mobx?{deep:!1}:{deep:!1,proxy:!1};function rt(t){throw void 0===t&&(t="Illegal state"),new Error("[mobx-state-tree] "+t)}function it(t){return t}Object.freeze(nt);var ot=Number.isInteger||function(t){return"number"==typeof t&&isFinite(t)&&Math.floor(t)===t};function at(t){return!(!Array.isArray(t)&&!l.isObservableArray(t))}function st(t){return t?at(t)?t:[t]:tt}function ut(t){if(null===t||"object"!=typeof t)return!1;var e=Object.getPrototypeOf(t);return e===Object.prototype||null===e}function pt(t){return!(null===t||"object"!=typeof t||t instanceof Date||t instanceof RegExp)}function ct(t){return null==t||("string"==typeof t||"number"==typeof t||"boolean"==typeof t||t instanceof Date)}function lt(t){return t}function ht(t,e,n){Object.defineProperty(t,e,{enumerable:!1,writable:!1,configurable:!0,value:n})}function ft(r,i){return r.push(i),function(){var t,e,n;e=i,-1!==(n=(t=r).indexOf(e))&&t.splice(n,1)}}function dt(t){for(var e=new Array(t.length),n=0;n<t.length;n++)e[n]=t[n];return e}var yt=function(t,e){};function vt(t){return l=t.name,h=t,f=function(){var s=O(),u=N||rt("Not running an action!"),p=arguments;function c(t,e,n){t.$mst_middleware=f.$mst_middleware,j({name:l,type:e,id:s,args:[n],tree:u.tree,context:u.context,parentId:u.id,allParentIds:u.allParentIds.concat([u.id]),rootId:u.rootId},t)}return new Promise(function(e,n){var r,t=function(){r=h.apply(null,arguments),i(void 0)};function i(t){var e;try{c(function(t){e=r.next(t)},"flow_resume",t)}catch(e){return void setImmediate(function(){c(function(t){n(e)},"flow_throw",e)})}a(e)}function o(t){var e;try{c(function(t){e=r.throw(t)},"flow_resume_error",t)}catch(e){return void setImmediate(function(){c(function(t){n(e)},"flow_throw",e)})}a(e)}function a(t){if(!t.done)return t.value&&"function"==typeof t.value.then||rt("Only promises can be yielded to `async`, got: "+t),t.value.then(i,o);setImmediate(function(){c(function(t){e(t)},"flow_return",t.value)})}t.$mst_middleware=f.$mst_middleware,j({name:l,type:"flow_spawn",id:s,args:dt(p),tree:u.tree,context:u.context,parentId:u.id,allParentIds:u.allParentIds.concat([u.id]),rootId:u.rootId},t)})};var l,h,f}function bt(t){return!0==("number"==typeof t)?""+t:t.replace(/~/g,"~1").replace(/\//g,"~0")}function gt(t){return t.replace(/~0/g,"/").replace(/~1/g,"~")}function mt(t){return 0===t.length?"":"/"+t.map(bt).join("/")}function St(t){var e=t.split("/").map(gt);return""===e[0]?e.slice(1):e}yt.ids={};var wt,At,Pt="Map.put can only be used to store complex values that have an identifier type attribute";(At=wt||(wt={}))[At.UNKNOWN=0]="UNKNOWN",At[At.YES=1]="YES",At[At.NO=2]="NO";var It=function(n){function t(t){return n.call(this,t,l.observable.ref.enhancer)||this}return a(t,n),t.prototype.get=function(t){return n.prototype.get.call(this,""+t)},t.prototype.has=function(t){return n.prototype.has.call(this,""+t)},t.prototype.delete=function(t){return n.prototype.delete.call(this,""+t)},t.prototype.set=function(t,e){return n.prototype.set.call(this,""+t,e)},t.prototype.put=function(t){if(t||rt("Map.put cannot be used to set empty values"),Y(t)){var e=Z(t),n=e.identifier;return this.set(n,e.value),e.value}if(pt(t)){n=void 0;var r=Z(this).type;return r.identifierMode===wt.NO?rt(Pt):r.identifierMode===wt.YES?(n=""+t[r.mapIdentifierAttribute],this.set(n,t),this.get(n)):rt(Pt)}return rt("Map.put can only be used to store complex values")},t}(l.ObservableMap),_t=function(r){function t(t,e){var n=r.call(this,t)||this;return n.shouldAttachNode=!0,n.identifierMode=wt.UNKNOWN,n.mapIdentifierAttribute=void 0,n.flags=b.Map,n.subType=e,n._determineIdentifierMode(),n}return a(t,r),t.prototype.instantiate=function(t,e,n,r){return this.identifierMode===wt.UNKNOWN&&this._determineIdentifierMode(),J(this,t,e,n,r)},t.prototype._determineIdentifierMode=function(){var t=[];if(function t(e,n){if(e instanceof zt)n.push(e);else if(e instanceof Xt){if(!t(e.type,n))return!1}else if(e instanceof qt){for(var r=0;r<e.types.length;r++)if(!t(e.types[r],n))return!1}else if(e instanceof re){var i=e.getSubType(!1);if(!i)return!1;t(i,n)}return!0}(this.subType,t)){var e=void 0;t.forEach(function(t){t.identifierAttribute&&(e&&e!==t.identifierAttribute&&rt("The objects in a map should all have the same identifier attribute, expected '"+e+"', but child of type '"+t.name+"' declared attribute '"+t.identifierAttribute+"' as identifier"),e=t.identifierAttribute)}),e?(this.identifierMode=wt.YES,this.mapIdentifierAttribute=e):this.identifierMode=wt.NO}},t.prototype.initializeChildNodes=function(e,n){void 0===n&&(n={});var r=e.type.subType,i=e._environment,o={};return Object.keys(n).forEach(function(t){o[t]=r.instantiate(e,t,i,n[t])}),o},t.prototype.createNewInstance=function(t,e,n){return new It(e)},t.prototype.finalizeNewInstance=function(t,e){l._interceptReads(e,t.unbox),l.intercept(e,this.willChange),l.observe(e,this.didChange)},t.prototype.describe=function(){return"Map<string, "+this.subType.describe()+">"},t.prototype.getChildren=function(t){return l.values(t.storedValue)},t.prototype.getChildNode=function(t,e){var n=t.storedValue.get(""+e);return n||rt("Not a child "+e),n},t.prototype.willChange=function(t){var e=Z(t.object),n=t.name;e.assertWritable();var r=e.type,i=r.subType;switch(t.type){case"update":var o=t.newValue;if(o===t.object.get(n))return null;t.newValue=i.reconcile(e.getChildNode(n),t.newValue),r.processIdentifier(n,t.newValue);break;case"add":t.newValue,t.newValue=i.instantiate(e,n,void 0,t.newValue),r.processIdentifier(n,t.newValue)}return t},t.prototype.processIdentifier=function(t,e){if(this.identifierMode===wt.YES&&e instanceof S){var n=e.identifier;n!==t&&rt("A map of objects containing an identifier should always store the object under their own identifier. Trying to store key '"+n+"', but expected: '"+t+"'")}},t.prototype.getValue=function(t){return t.storedValue},t.prototype.getSnapshot=function(t){var e={};return t.getChildren().forEach(function(t){e[t.subpath]=t.snapshot}),e},t.prototype.processInitialSnapshot=function(e,t){var n={};return Object.keys(e).forEach(function(t){n[t]=e[t].getSnapshot()}),n},t.prototype.didChange=function(t){var e=Z(t.object);switch(t.type){case"update":return void e.emitPatch({op:"replace",path:bt(t.name),value:t.newValue.snapshot,oldValue:t.oldValue?t.oldValue.snapshot:void 0},e);case"add":return void e.emitPatch({op:"add",path:bt(t.name),value:t.newValue.snapshot,oldValue:void 0},e);case"delete":var n=t.oldValue.snapshot;return t.oldValue.die(),void e.emitPatch({op:"remove",path:bt(t.name),oldValue:n},e)}},t.prototype.applyPatchLocally=function(t,e,n){var r=t.storedValue;switch(n.op){case"add":case"replace":r.set(e,n.value);break;case"remove":r.delete(e)}},t.prototype.applySnapshot=function(t,e){var n=t.storedValue,r={};for(var i in Array.from(n.keys()).forEach(function(t){r[t]=!1}),e)n.set(i,e[i]),r[""+i]=!0;Object.keys(r).forEach(function(t){!1===r[t]&&n.delete(t)})},t.prototype.getChildType=function(t){return this.subType},t.prototype.isValidSnapshot=function(e,n){var r=this;return ut(e)?L(Object.keys(e).map(function(t){return r.subType.validate(e[t],M(n,t,r.subType))})):k(n,e,"Value is not a plain object")},t.prototype.getDefaultSnapshot=function(){return et},t.prototype.removeChild=function(t,e){t.storedValue.delete(e)},n([l.action],t.prototype,"applySnapshot",null),t}(w);var Vt=function(r){function t(t,e){var n=r.call(this,t)||this;return n.shouldAttachNode=!0,n.flags=b.Array,n.subType=e,n}return a(t,r),t.prototype.instantiate=function(t,e,n,r){return J(this,t,e,n,r)},t.prototype.initializeChildNodes=function(r,t){void 0===t&&(t=[]);var i=r.type.subType,o=r._environment,a={};return t.forEach(function(t,e){var n=""+e;a[n]=i.instantiate(r,n,o,t)}),a},t.prototype.createNewInstance=function(t,e,n){return l.observable.array(X(e),nt)},t.prototype.finalizeNewInstance=function(t,e){l._getAdministration(e).dehancer=t.unbox,l.intercept(e,this.willChange),l.observe(e,this.didChange)},t.prototype.describe=function(){return this.subType.describe()+"[]"},t.prototype.getChildren=function(t){return t.storedValue.slice()},t.prototype.getChildNode=function(t,e){var n=parseInt(e,10);return n<t.storedValue.length?t.storedValue[n]:rt("Not a child: "+e)},t.prototype.willChange=function(t){var e=Z(t.object);e.assertWritable();var n=e.type.subType,r=e.getChildren(),i=null;switch(t.type){case"update":if(t.newValue===t.object[t.index])return null;if(!(i=Ct(e,n,[r[t.index]],[t.newValue],[t.index])))return null;t.newValue=i[0];break;case"splice":var o=t.index,a=t.removedCount,s=t.added;if(!(i=Ct(e,n,r.slice(o,o+a),s,s.map(function(t,e){return o+e}))))return null;t.added=i;for(var u=o+a;u<r.length;u++)r[u].setParent(e,""+(u+s.length-a))}return t},t.prototype.getValue=function(t){return t.storedValue},t.prototype.getSnapshot=function(t){return t.getChildren().map(function(t){return t.snapshot})},t.prototype.processInitialSnapshot=function(e,t){var n=[];return Object.keys(e).forEach(function(t){n.push(e[t].getSnapshot())}),n},t.prototype.didChange=function(t){var e=Z(t.object);switch(t.type){case"update":return void e.emitPatch({op:"replace",path:""+t.index,value:t.newValue.snapshot,oldValue:t.oldValue?t.oldValue.snapshot:void 0},e);case"splice":for(var n=t.removedCount-1;0<=n;n--)e.emitPatch({op:"remove",path:""+(t.index+n),oldValue:t.removed[n].snapshot},e);for(n=0;n<t.addedCount;n++)e.emitPatch({op:"add",path:""+(t.index+n),value:e.getChildNode(""+(t.index+n)).snapshot,oldValue:void 0},e);return}},t.prototype.applyPatchLocally=function(t,e,n){var r=t.storedValue,i="-"===e?r.length:parseInt(e);switch(n.op){case"replace":r[i]=n.value;break;case"add":r.splice(i,0,n.value);break;case"remove":r.splice(i,1)}},t.prototype.applySnapshot=function(t,e){t.storedValue.replace(e)},t.prototype.getChildType=function(t){return this.subType},t.prototype.isValidSnapshot=function(t,n){var r=this;return at(t)?L(t.map(function(t,e){return r.subType.validate(t,M(n,""+e,r.subType))})):k(n,t,"Value is not an array")},t.prototype.getDefaultSnapshot=function(){return tt},t.prototype.removeChild=function(t,e){t.storedValue.splice(parseInt(e,10),1)},n([l.action],t.prototype,"applySnapshot",null),t}(w);function Ct(t,e,n,r,i){for(var o,a,s,u=!1,p=void 0,c=!0,l=0;u=l<=r.length-1,o=n[l],a=u?r[l]:void 0,((s=a)instanceof d||s instanceof S)&&(a=a.storedValue),o||u;l++)if(u)if(o)if(Nt(o,a))n[l]=Tt(e,t,""+i[l],a,o);else{p=void 0;for(var h=l;h<n.length;h++)if(Nt(n[h],a)){p=n.splice(h,1)[0];break}n.splice(l,0,Tt(e,t,""+i[l],a,p)),c=!1}else Y(a)&&Z(a).parent===t&&rt("Cannot add an object to a state tree if it is already part of the same or another state tree. Tried to assign an object to '"+t.path+"/"+i[l]+"', but it lives already at '"+Z(a).path+"'"),n.splice(l,0,Tt(e,t,""+i[l],a)),c=!1;else o.die(),n.splice(l,1),l--,c=!1;return c?null:n}function Tt(t,e,n,r,i){var o;if(Y(r)&&((o=Z(r)).assertAlive(),null!==o.parent&&o.parent===e))return o.setParent(e,n),i&&i!==o&&i.die(),o;return i?((o=t.reconcile(i,r)).setParent(e,n),o):t.instantiate(e,n,e._environment,r)}function Nt(t,e){return Y(e)?Z(e)===t:t.snapshot===e||!!(t instanceof S&&null!==t.identifier&&t.identifierAttribute&&ut(e)&&t.identifier===""+e[t.identifierAttribute]&&t.type.is(e))}var Ot,jt,Et="preProcessSnapshot",Dt="postProcessSnapshot";function xt(){return Z(this).toString()}(jt=Ot||(Ot={})).afterCreate="afterCreate",jt.afterAttach="afterAttach",jt.beforeDetach="beforeDetach",jt.beforeDestroy="beforeDestroy";var Rt={name:"AnonymousModel",properties:{},initializers:tt};function Mt(t){return Object.keys(t).reduce(function(t,e){var n,r,i;if(e in Ot)return rt("Hook '"+e+"' was defined as property. Hooks should be defined as part of the actions");var o=Object.getOwnPropertyDescriptor(t,e);"get"in o&&rt("Getters are not supported as properties. Please use views instead");var a=o.value;if(null==a)rt("The default value of an attribute cannot be null or undefined as the type cannot be inferred. Did you mean `types.maybe(someType)`?");else{if(ct(a))return Object.assign({},t,((n={})[e]=te(function(t){switch(typeof t){case"string":return Ft;case"number":return Ut;case"boolean":return $t;case"object":if(t instanceof Date)return Yt}return rt("Cannot determine primitive type from value "+t)}(a),a),n));if(a instanceof _t)return Object.assign({},t,((r={})[e]=te(a,{}),r));if(a instanceof Vt)return Object.assign({},t,((i={})[e]=te(a,[]),i));if(P(a))return t;rt("Invalid type definition for property '"+e+"', cannot infer a type from a value like '"+a+"' ("+typeof a+")")}},t)}var zt=function(r){function e(t){var e=r.call(this,t.name||Rt.name)||this;e.flags=b.Object,e.shouldAttachNode=!0;var n=t.name||Rt.name;return/^\w[\w\d_]*$/.test(n)||rt("Typename should be a valid identifier: "+n),Object.assign(e,Rt,t),e.properties=Mt(e.properties),lt(e.properties),e.propertyNames=Object.keys(e.properties),e.identifierAttribute=e._getIdentifierAttribute(),e}return a(e,r),e.prototype._getIdentifierAttribute=function(){var n=void 0;return this.forAllProps(function(t,e){e.flags&b.Identifier&&(n&&rt("Cannot define property '"+t+"' as object identifier, property '"+n+"' is already defined as identifier property"),n=t)}),n},e.prototype.cloneAndEnhance=function(t){return new e({name:t.name||this.name,properties:Object.assign({},this.properties,t.properties),initializers:this.initializers.concat(t.initializers||[]),preProcessor:t.preProcessor||this.preProcessor,postProcessor:t.postProcessor||this.postProcessor})},e.prototype.actions=function(e){var n=this;return this.cloneAndEnhance({initializers:[function(t){return n.instantiateActions(t,e(t)),t}]})},e.prototype.instantiateActions=function(s,u){ut(u)||rt("actions initializer should return a plain object containing actions"),Object.keys(u).forEach(function(t){t===Et&&rt("Cannot define action '"+Et+"', it should be defined using 'type.preProcessSnapshot(fn)' instead"),t===Dt&&rt("Cannot define action '"+Dt+"', it should be defined using 'type.postProcessSnapshot(fn)' instead");var e=u[t],n=s[t];if(t in Ot&&n){var r=e;e=function(){n.apply(null,arguments),r.apply(null,arguments)}}var i=e.$mst_middleware,o=e.bind(u);o.$mst_middleware=i;var a=E(s,t,o);u[t]=a,ht(s,t,a)})},e.prototype.named=function(t){return this.cloneAndEnhance({name:t})},e.prototype.props=function(t){return this.cloneAndEnhance({properties:t})},e.prototype.volatile=function(e){var n=this;return this.cloneAndEnhance({initializers:[function(t){return n.instantiateVolatileState(t,e(t)),t}]})},e.prototype.instantiateVolatileState=function(t,e){ut(e)||rt("volatile state initializer should return a plain object containing state"),l.set(t,e)},e.prototype.extend=function(s){var u=this;return this.cloneAndEnhance({initializers:[function(t){var e=s(t),n=e.actions,r=e.views,i=e.state,o=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&(n[r[i]]=t[r[i]])}return n}(e,["actions","views","state"]);for(var a in o)rt("The `extend` function should return an object with a subset of the fields 'actions', 'views' and 'state'. Found invalid key '"+a+"'");return i&&u.instantiateVolatileState(t,i),r&&u.instantiateViews(t,r),n&&u.instantiateActions(t,n),t}]})},e.prototype.views=function(e){var n=this;return this.cloneAndEnhance({initializers:[function(t){return n.instantiateViews(t,e(t)),t}]})},e.prototype.instantiateViews=function(i,o){ut(o)||rt("views initializer should return a plain object containing views"),Object.keys(o).forEach(function(t){var e=Object.getOwnPropertyDescriptor(o,t),n=e.value;if("get"in e)if(l.isComputedProp(i,t)){var r=l._getAdministration(i,t);r.derivation=e.get,r.scope=i,e.set&&(r.setter=l.action(r.name+"-setter",e.set))}else l.computed(i,t,e,!0);else"function"==typeof n?ht(i,t,n):rt("A view member should either be a function or getter based property")})},e.prototype.preProcessSnapshot=function(e){var n=this.preProcessor;return n?this.cloneAndEnhance({preProcessor:function(t){return n(e(t))}}):this.cloneAndEnhance({preProcessor:e})},e.prototype.postProcessSnapshot=function(e){var n=this.postProcessor;return n?this.cloneAndEnhance({postProcessor:function(t){return e(n(t))}}):this.cloneAndEnhance({postProcessor:e})},e.prototype.instantiate=function(t,e,n,r){return J(this,t,e,n,Y(r)?r:this.applySnapshotPreProcessor(r))},e.prototype.initializeChildNodes=function(n,r){void 0===r&&(r={});var t=n.type,i={};return t.forAllProps(function(t,e){i[t]=e.instantiate(n,t,n._environment,r[t])}),i},e.prototype.createNewInstance=function(t,e,n){return l.observable.object(e,et,nt)},e.prototype.finalizeNewInstance=function(e,n){ht(n,"toString",xt),this.forAllProps(function(t){l._interceptReads(n,t,e.unbox)}),this.initializers.reduce(function(t,e){return e(t)},n),l.intercept(n,this.willChange),l.observe(n,this.didChange)},e.prototype.willChange=function(t){var e=Z(t.object);e.assertWritable();var n=e.type.properties[t.name];return n&&(t.newValue,t.newValue=n.reconcile(e.getChildNode(t.name),t.newValue)),t},e.prototype.didChange=function(t){var e=Z(t.object);if(e.type.properties[t.name]){var n=t.oldValue?t.oldValue.snapshot:void 0;e.emitPatch({op:"replace",path:bt(t.name),value:t.newValue.snapshot,oldValue:n},e)}},e.prototype.getChildren=function(n){var r=this,i=[];return this.forAllProps(function(t,e){i.push(r.getChildNode(n,t))}),i},e.prototype.getChildNode=function(t,e){if(!(e in this.properties))return rt("Not a value property: "+e);var n=l._getAdministration(t.storedValue,e).value;return n||rt("Node not available for property "+e)},e.prototype.getValue=function(t){return t.storedValue},e.prototype.getSnapshot=function(n,t){var r=this;void 0===t&&(t=!0);var i={};return this.forAllProps(function(t,e){l.getAtom(n.storedValue,t).reportObserved(),i[t]=r.getChildNode(n,t).snapshot}),t?this.applySnapshotPostProcessor(i):i},e.prototype.processInitialSnapshot=function(e,t){var n={};return Object.keys(e).forEach(function(t){n[t]=e[t].getSnapshot()}),this.applySnapshotPostProcessor(this.applyOptionalValuesToSnapshot(n))},e.prototype.applyPatchLocally=function(t,e,n){"replace"!==n.op&&"add"!==n.op&&rt("object does not support operation "+n.op),t.storedValue[e]=n.value},e.prototype.applySnapshot=function(n,t){var r=this.applySnapshotPreProcessor(t);this.forAllProps(function(t,e){n.storedValue[t]=r[t]})},e.prototype.applySnapshotPreProcessor=function(t){var e=this.preProcessor;return e?e.call(null,t):t},e.prototype.applyOptionalValuesToSnapshot=function(r){return r&&(r=Object.assign({},r),this.forAllProps(function(t,e){if(!(t in r)){var n=kt(e);n&&(r[t]=n.getDefaultValueSnapshot())}})),r},e.prototype.applySnapshotPostProcessor=function(t){var e=this.postProcessor;return e?e.call(null,t):t},e.prototype.getChildType=function(t){return this.properties[t]},e.prototype.isValidSnapshot=function(t,e){var n=this,r=this.applySnapshotPreProcessor(t);return ut(r)?L(this.propertyNames.map(function(t){return n.properties[t].validate(r[t],M(e,t,n.properties[t]))})):k(e,r,"Value is not a plain object")},e.prototype.forAllProps=function(e){var n=this;this.propertyNames.forEach(function(t){return e(t,n.properties[t])})},e.prototype.describe=function(){var e=this;return"{ "+this.propertyNames.map(function(t){return t+": "+e.properties[t].describe()}).join("; ")+" }"},e.prototype.getDefaultSnapshot=function(){return et},e.prototype.removeChild=function(t,e){t.storedValue[e]=void 0},n([l.action],e.prototype,"applySnapshot",null),e}(w);function kt(t){if(t)return t.flags&b.Union&&t.types?t.types.find(kt):t.flags&b.Late&&t.getSubType&&t.getSubType(!1)?kt(t.subType):t.flags&b.Optional?t:void 0}var Lt=function(o){function t(t,e,n,r){void 0===r&&(r=it);var i=o.call(this,t)||this;return i.shouldAttachNode=!1,i.flags=e,i.checker=n,i.initializer=r,i}return a(t,o),t.prototype.describe=function(){return this.name},t.prototype.instantiate=function(t,e,n,r){return J(this,t,e,n,r)},t.prototype.createNewInstance=function(t,e,n){return this.initializer(n)},t.prototype.isValidSnapshot=function(t,e){return ct(t)&&this.checker(t)?z():k(e,t,"Value is not a "+("Date"===this.name?"Date or a unix milliseconds timestamp":this.name))},t}(A),Ft=new Lt("string",b.String,function(t){return"string"==typeof t}),Ut=new Lt("number",b.Number,function(t){return"number"==typeof t}),Ht=new Lt("integer",b.Integer,function(t){return ot(t)}),$t=new Lt("boolean",b.Boolean,function(t){return"boolean"==typeof t}),Wt=new Lt("null",b.Null,function(t){return null===t}),Jt=new Lt("undefined",b.Undefined,function(t){return void 0===t}),Yt=new Lt("Date",b.Date,function(t){return"number"==typeof t||t instanceof Date},function(t){return t instanceof Date?t:new Date(t)});function Zt(t){return P(t)&&0<(t.flags&(b.String|b.Number|b.Integer|b.Boolean|b.Date))}Yt.getSnapshot=function(t){return t.storedValue.getTime()};var Gt=function(n){function t(t){var e=n.call(this,JSON.stringify(t))||this;return e.shouldAttachNode=!1,e.flags=b.Literal,e.value=t,e}return a(t,n),t.prototype.instantiate=function(t,e,n,r){return J(this,t,e,n,r)},t.prototype.describe=function(){return JSON.stringify(this.value)},t.prototype.isValidSnapshot=function(t,e){return ct(t)&&t===this.value?z():k(e,t,"Value is not a literal "+JSON.stringify(this.value))},t}(A);function Bt(t){return new Gt(t)}var Kt=function(o){function t(t,e,n,r){var i=o.call(this,t)||this;return i.type=e,i.predicate=n,i.message=r,i}return a(t,o),Object.defineProperty(t.prototype,"flags",{get:function(){return this.type.flags|b.Refinement},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"shouldAttachNode",{get:function(){return this.type.shouldAttachNode},enumerable:!0,configurable:!0}),t.prototype.describe=function(){return this.name},t.prototype.instantiate=function(t,e,n,r){return this.type.instantiate(t,e,n,r)},t.prototype.isAssignableFrom=function(t){return this.type.isAssignableFrom(t)},t.prototype.isValidSnapshot=function(t,e){var n=this.type.validate(t,e);if(0<n.length)return n;var r=Y(t)?Z(t).snapshot:t;return this.predicate(r)?z():k(e,t,this.message(t))},t}(A);var qt=function(i){function t(t,e,n){var r=i.call(this,t)||this;return r.eager=!0,n=o({eager:!0,dispatcher:void 0},n),r.dispatcher=n.dispatcher,n.eager||(r.eager=!1),r.types=e,r}return a(t,i),Object.defineProperty(t.prototype,"flags",{get:function(){var e=b.Union;return this.types.forEach(function(t){e|=t.flags}),e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"shouldAttachNode",{get:function(){return this.types.some(function(t){return t.shouldAttachNode})},enumerable:!0,configurable:!0}),t.prototype.isAssignableFrom=function(e){return this.types.some(function(t){return t.isAssignableFrom(e)})},t.prototype.describe=function(){return"("+this.types.map(function(t){return t.describe()}).join(" | ")+")"},t.prototype.instantiate=function(t,e,n,r){var i=this.determineType(r,void 0);return i?i.instantiate(t,e,n,r):rt("No matching type for union "+this.describe())},t.prototype.reconcile=function(t,e){var n=this.determineType(e,t.type);return n?n.reconcile(t,e):rt("No matching type for union "+this.describe())},t.prototype.determineType=function(e,n){return this.dispatcher?this.dispatcher(e):n?n.is(e)?n:this.types.filter(function(t){return t!==n}).find(function(t){return t.is(e)}):this.types.find(function(t){return t.is(e)})},t.prototype.isValidSnapshot=function(t,e){if(this.dispatcher)return this.dispatcher(t).validate(t,e);for(var n=[],r=0,i=0;i<this.types.length;i++){var o=this.types[i].validate(t,e);if(0===o.length){if(this.eager)return z();r++}else n.push(o)}return 1===r?z():k(e,t,"No type is applicable for the union").concat(L(n))},t}(A);function Qt(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var r=P(t)?void 0:t,i=P(t)?[t].concat(e):e,o="("+i.map(function(t){return t.name}).join(" | ")+")";return new qt(o,i,r)}var Xt=function(r){function t(t,e){var n=r.call(this,t.name)||this;return n.type=t,n.defaultValue=e,n}return a(t,r),Object.defineProperty(t.prototype,"flags",{get:function(){return this.type.flags|b.Optional},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"shouldAttachNode",{get:function(){return this.type.shouldAttachNode},enumerable:!0,configurable:!0}),t.prototype.describe=function(){return this.type.describe()+"?"},t.prototype.instantiate=function(t,e,n,r){if(void 0!==r)return this.type.instantiate(t,e,n,r);var i=this.getDefaultInstanceOrSnapshot();return this.type.instantiate(t,e,n,i)},t.prototype.reconcile=function(t,e){return this.type.reconcile(t,this.type.is(e)&&void 0!==e?e:this.getDefaultInstanceOrSnapshot())},t.prototype.getDefaultInstanceOrSnapshot=function(){var t="function"==typeof this.defaultValue?this.defaultValue():this.defaultValue;return this.defaultValue,t},t.prototype.getDefaultValueSnapshot=function(){var t=this.getDefaultInstanceOrSnapshot();return Y(t)?Z(t).snapshot:t},t.prototype.isValidSnapshot=function(t,e){return void 0===t?z():this.type.validate(t,e)},t.prototype.isAssignableFrom=function(t){return this.type.isAssignableFrom(t)},t}(A);function te(t,e){return"function"!=typeof e&&Y(e)&&rt("default value cannot be an instance, pass a snapshot or a function that creates an instance/snapshot instead"),new Xt(t,e)}var ee=te(Jt,void 0),ne=te(Wt,null);var re=function(r){function t(t,e){var n=r.call(this,t)||this;return n._subType=null,n.definition=e,n}return a(t,r),Object.defineProperty(t.prototype,"flags",{get:function(){return(this._subType?this._subType.flags:0)|b.Late},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"shouldAttachNode",{get:function(){return this.getSubType(!0).shouldAttachNode},enumerable:!0,configurable:!0}),t.prototype.getSubType=function(t){if(null===this._subType){var e=void 0;try{e=this.definition()}catch(t){if(!(t instanceof ReferenceError))throw t;e=void 0}if(t&&void 0===e&&rt("Late type seems to be used too early, the definition (still) returns undefined"),e)return this._subType=e}return this._subType},t.prototype.instantiate=function(t,e,n,r){return this.getSubType(!0).instantiate(t,e,n,r)},t.prototype.reconcile=function(t,e){return this.getSubType(!0).reconcile(t,e)},t.prototype.describe=function(){var t=this.getSubType(!1);return t?t.name:"<uknown late type>"},t.prototype.isValidSnapshot=function(t,e){var n=this.getSubType(!1);return n?n.validate(t,e):z()},t.prototype.isAssignableFrom=function(t){var e=this.getSubType(!1);return!!e&&e.isAssignableFrom(t)},t}(A);var ie=function(n){function t(t){var e=n.call(this,t?"frozen("+t.name+")":"frozen")||this;return e.subType=t,e.shouldAttachNode=!1,e.flags=b.Frozen,e}return a(t,n),t.prototype.describe=function(){return"<any immutable value>"},t.prototype.instantiate=function(t,e,n,r){return J(this,t,e,n,r)},t.prototype.isValidSnapshot=function(t,e){return"function"==typeof t?k(e,t,"Value is not serializable and cannot be frozen"):this.subType?this.subType.validate(t,e):z()},t}(A),oe=new ie;var ae=function(){function t(t,e){if(this.targetType=e,"string"==typeof t||"number"==typeof t)this.identifier=t;else{if(!Y(t))return rt("Can only store references to tree nodes or identifiers, got: '"+t+"'");var n=Z(t);if(!n.identifierAttribute)return rt("Can only store references with a defined identifier attribute.");var r=n.unnormalizedIdentifier;if(null==r)return rt("Can only store references to tree nodes with a defined identifier.");this.identifier=r}}return t.prototype.updateResolvedReference=function(){var t=""+this.identifier,e=this.node,n=e.root.identifierCache.getLastCacheModificationPerId(t);if(!this.resolvedReference||this.resolvedReference.lastCacheModification!==n){var r=this.targetType,i=e.root.identifierCache.resolve(r,t);i||rt("Failed to resolve reference '"+this.identifier+"' to type '"+this.targetType.name+"' (from node: "+e.path+")"),this.resolvedReference={node:i,lastCacheModification:n}}},Object.defineProperty(t.prototype,"resolvedValue",{get:function(){return this.updateResolvedReference(),this.resolvedReference.node.value},enumerable:!0,configurable:!0}),t}(),se=function(n){function t(t){var e=n.call(this,"reference("+t.name+")")||this;return e.targetType=t,e.shouldAttachNode=!1,e.flags=b.Reference,e}return a(t,n),t.prototype.describe=function(){return this.name},t.prototype.isAssignableFrom=function(t){return this.targetType.isAssignableFrom(t)},t.prototype.isValidSnapshot=function(t,e){return"string"==typeof t||"number"==typeof t?z():k(e,t,"Value is not a valid identifier, which is a string or a number")},t}(A),ue=function(e){function t(t){return e.call(this,t)||this}return a(t,e),t.prototype.getValue=function(t){if(t.isAlive)return t.storedValue.resolvedValue},t.prototype.getSnapshot=function(t){return t.storedValue.identifier},t.prototype.instantiate=function(t,e,n,r){var i,o=J(this,t,e,n,i=new ae(r,this.targetType));return i.node=o},t.prototype.reconcile=function(t,e){if(t.type===this){var n=Y(e),r=t.storedValue;if(!n&&r.identifier===e)return t;if(n&&r.resolvedValue===e)return t}var i=this.instantiate(t.parent,t.subpath,t._environment,e);return t.die(),i},t}(se),pe=function(r){function t(t,e){var n=r.call(this,t)||this;return n.options=e,n}return a(t,r),t.prototype.getValue=function(t){if(t.isAlive)return this.options.get(t.storedValue,t.parent?t.parent.storedValue:null)},t.prototype.getSnapshot=function(t){return t.storedValue},t.prototype.instantiate=function(t,e,n,r){return J(this,t,e,n,Y(r)?this.options.set(r,t?t.storedValue:null):r)},t.prototype.reconcile=function(t,e){var n=Y(e)?this.options.set(e,t?t.storedValue:null):e;if(t.type===this&&t.storedValue===n)return t;var r=this.instantiate(t.parent,t.subpath,t._environment,n);return t.die(),r},t}(se);var ce=function(e){function t(){var t=e.call(this,"identifier")||this;return t.shouldAttachNode=!1,t.flags=b.Identifier,t}return a(t,e),t.prototype.instantiate=function(t,e,n,r){return t&&t.type instanceof zt||rt("Identifier types can only be instantiated as direct child of a model type"),J(this,t,e,n,r)},t.prototype.reconcile=function(t,e){return t.storedValue!==e?rt("Tried to change identifier from '"+t.storedValue+"' to '"+e+"'. Changing identifiers is not allowed."):t},t.prototype.describe=function(){return"identifier"},t.prototype.isValidSnapshot=function(t,e){return"string"!=typeof t?k(e,t,"Value is not a valid identifier, expected a string"):z()},t}(A),le=function(i){function t(){var t=i.call(this)||this;return t.name="identifierNumber",t}return a(t,i),t.prototype.instantiate=function(t,e,n,r){return i.prototype.instantiate.call(this,t,e,n,r)},t.prototype.isValidSnapshot=function(t,e){return"number"==typeof t?z():k(e,t,"Value is not a valid identifierNumber, expected a number")},t.prototype.reconcile=function(t,e){return i.prototype.reconcile.call(this,t,e)},t.prototype.getSnapshot=function(t){return t.storedValue},t.prototype.describe=function(){return"identifierNumber"},t}(ce),he=new ce,fe=new le;var de=function(n){function t(t){var e=n.call(this,t.name)||this;return e.options=t,e.flags=b.Reference,e.shouldAttachNode=!1,e}return a(t,n),t.prototype.describe=function(){return this.name},t.prototype.isAssignableFrom=function(t){return t===this},t.prototype.isValidSnapshot=function(t,e){if(this.options.isTargetType(t))return z();var n=this.options.getValidationMessage(t);return n?k(e,t,"Invalid value for type '"+this.name+"': "+n):z()},t.prototype.getValue=function(t){if(t.isAlive)return t.storedValue},t.prototype.getSnapshot=function(t){return this.options.toSnapshot(t.storedValue)},t.prototype.instantiate=function(t,e,n,r){return J(this,t,e,n,this.options.isTargetType(r)?r:this.options.fromSnapshot(r))},t.prototype.reconcile=function(t,e){var n=!this.options.isTargetType(e);if(t.type===this&&(n?e===t.snapshot:e===t.storedValue))return t;var r=n?this.options.fromSnapshot(e):e,i=this.instantiate(t.parent,t.subpath,t._environment,r);return t.die(),i},t}(A),ye={enumeration:function(t,e){var n=Qt.apply(void 0,("string"==typeof t?e:t).map(function(t){return Bt(""+t)}));return"string"==typeof t&&(n.name=t),n},model:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n="string"==typeof t[0]?t.shift():"AnonymousModel",r=t.shift()||{};return new zt({name:n,properties:r})},compose:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n="string"==typeof t[0]?t.shift():"AnonymousModel";return t.reduce(function(e,n){return e.cloneAndEnhance({name:e.name+"_"+n.name,properties:n.properties,initializers:n.initializers,preProcessor:function(t){return n.applySnapshotPreProcessor(e.applySnapshotPreProcessor(t))},postProcessor:function(t){return n.applySnapshotPostProcessor(e.applySnapshotPostProcessor(t))}})}).named(n)},custom:function(t){return new de(t)},reference:function(t,e){return e?new pe(t,e):new ue(t)},union:Qt,optional:te,literal:Bt,maybe:function(t){return Qt(t,ee)},maybeNull:function(t){return Qt(t,ne)},refinement:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n="string"==typeof t[0]?t.shift():P(t[0])?t[0].name:null,r=t[0],i=t[1],o=t[2]?t[2]:function(t){return"Value does not respect the refinement predicate"};return new Kt(n,r,i,o)},string:Ft,boolean:$t,number:Ut,integer:Ht,Date:Yt,map:function(t){return new _t("map<string, "+t.name+">",t)},array:function(t){return new Vt(t.name+"[]",t)},frozen:function(t){return 0===arguments.length?oe:P(t)?new ie(t):te(oe,t)},identifier:he,identifierNumber:fe,late:function(t,e){var n="string"==typeof t?t:"late("+t.toString()+")";return new re(n,"string"==typeof t?e:t)},undefined:Jt,null:Wt};t.types=ye,t.typecheck=F,t.escapeJsonPath=bt,t.unescapeJsonPath=gt,t.joinJsonPath=mt,t.splitJsonPath=St,t.decorate=function(t,e){var n={handler:t,includeHooks:!0};return e.$mst_middleware&&e.$mst_middleware.push(n),e.$mst_middleware=[n],e},t.addMiddleware=D,t.process=function(t){return yt("process","`process()` has been renamed to `flow()`. See https://github.com/mobxjs/mobx-state-tree/issues/399 for more information. Note that the middleware event types starting with `process` now start with `flow`."),vt(t)},t.isStateTreeNode=Y,t.flow=vt,t.applyAction=V,t.onAction=C,t.recordActions=function(t){var e={actions:[],stop:function(){return n()},replay:function(t){V(t,e.actions)}},n=C(t,e.actions.push.bind(e.actions));return e},t.createActionTrackingMiddleware=function(a){return function(e,t,n){switch(e.type){case"action":if(a.filter&&!0!==a.filter(e))return t(e);var r=a.onStart(e);a.onResume(e,r),I.set(e.id,{call:e,context:r,async:!1});try{var i=t(e);return a.onSuspend(e,r),!1===I.get(e.id).async&&(I.delete(e.id),a.onSuccess(e,r,i)),i}catch(t){throw I.delete(e.id),a.onFail(e,r,t),t}case"flow_spawn":return(o=I.get(e.rootId)).async=!0,t(e);case"flow_resume":case"flow_resume_error":var o=I.get(e.rootId);a.onResume(e,o.context);try{return t(e)}finally{a.onSuspend(e,o.context)}case"flow_throw":return o=I.get(e.rootId),I.delete(e.id),a.onFail(e,o.context,e.args[0]),t(e);case"flow_return":return o=I.get(e.rootId),I.delete(e.id),a.onSuccess(e,o.context,e.args[0]),t(e)}}},t.setLivelynessChecking=function(t){v=t},t.getType=u,t.getChildType=function(t,e){return Z(t).getChildType(e)},t.onPatch=i,t.onSnapshot=function(t,e){return Z(t).onSnapshot(e)},t.applyPatch=s,t.recordPatches=function(e){var t=null;function n(){t||(t=i(e,function(t,e){r.rawPatches.push([t,e])}))}var r={rawPatches:[],get patches(){return this.rawPatches.map(function(t){return t[0]})},get inversePatches(){return this.rawPatches.map(function(t){return t[0],t[1]})},stop:function(){t&&t(),t=null},resume:n,replay:function(t){s(t||e,r.patches)},undo:function(t){s(t||e,r.inversePatches.slice().reverse())}};return n(),r},t.protect=function(t){var e=Z(t);e.isRoot||rt("`protect` can only be invoked on root nodes"),e.isProtectionEnabled=!0},t.unprotect=function(t){var e=Z(t);e.isRoot||rt("`unprotect` can only be invoked on root nodes"),e.isProtectionEnabled=!1},t.isProtected=function(t){return Z(t).isProtected},t.applySnapshot=p,t.getSnapshot=function(t,e){void 0===e&&(e=!0);var n=Z(t);return e?n.snapshot:lt(n.type.getSnapshot(n,!1))},t.hasParent=function(t,e){void 0===e&&(e=1);for(var n=Z(t).parent;n;){if(0==--e)return!0;n=n.parent}return!1},t.getParent=function(t,e){void 0===e&&(e=1);for(var n=e,r=Z(t).parent;r;){if(0==--n)return r.storedValue;r=r.parent}return rt("Failed to find the parent of "+Z(t)+" at depth "+e)},t.hasParentOfType=function(t,e){for(var n=Z(t).parent;n;){if(e.is(n.storedValue))return!0;n=n.parent}return!1},t.getParentOfType=function(t,e){for(var n=Z(t).parent;n;){if(e.is(n.storedValue))return n.storedValue;n=n.parent}return rt("Failed to find the parent of "+Z(t)+" of a given type")},t.getRoot=c,t.getPath=function(t){return Z(t).path},t.getPathParts=function(t){return St(Z(t).path)},t.isRoot=function(t){return Z(t).isRoot},t.resolvePath=function(t,e){var n=q(Z(t),e);return n?n.value:void 0},t.resolveIdentifier=function(t,e,n){var r=Z(e).root.identifierCache.resolve(t,""+n);return r?r.value:void 0},t.getIdentifier=function(t){return Z(t).identifier},t.tryResolve=h,t.getRelativePath=function(t,e){return K(Z(t),Z(e))},t.clone=function(t,e){void 0===e&&(e=!0);var n=Z(t);return n.type.create(n.snapshot,!0===e?n.root._environment:!1===e?void 0:e)},t.detach=function(t){return Z(t).detach(),t},t.destroy=function(t){var e=Z(t);e.isRoot?e.die():e.parent.removeChild(e.subpath)},t.isAlive=function(t){return Z(t).isAlive},t.addDisposer=function(t,e){Z(t).addDisposer(e)},t.getEnv=function(t){var e=Z(t).root._environment;return e||et},t.walk=f,t.getMembers=function(n){var t=Z(n).type,r=o({},e(t),{actions:[],volatile:[],views:[]});return Object.getOwnPropertyNames(n).forEach(function(t){if(!(t in r.properties)){var e=Object.getOwnPropertyDescriptor(n,t);e.get?l.isComputedProp(n,t)?r.views.push(t):r.volatile.push(t):!0===e.value._isMSTAction?r.actions.push(t):l.isObservableProp(n,t)?r.volatile.push(t):r.views.push(t)}}),r},t.getPropertyMembers=e,t.cast=function(t){return t},t.isType=P,t.isArrayType=function(t){return P(t)&&0<(t.flags&b.Array)},t.isFrozenType=function(t){return P(t)&&0<(t.flags&b.Frozen)},t.isIdentifierType=function(t){return P(t)&&0<(t.flags&b.Identifier)},t.isLateType=function(t){return P(t)&&0<(t.flags&b.Late)},t.isLiteralType=function(t){return P(t)&&0<(t.flags&b.Literal)},t.isMapType=function(t){return P(t)&&0<(t.flags&b.Map)},t.isModelType=function(t){return P(t)&&0<(t.flags&b.Object)},t.isOptionalType=function(t){return P(t)&&0<(t.flags&b.Optional)},t.isPrimitiveType=Zt,t.isReferenceType=function(t){return 0<(t.flags&b.Reference)},t.isRefinementType=function(t){return 0<(t.flags&b.Refinement)},t.isUnionType=function(t){return 0<(t.flags&b.Union)},Object.defineProperty(t,"__esModule",{value:!0})}); |
{ | ||
"name": "mobx-state-tree", | ||
"version": "3.7.0", | ||
"version": "3.7.1", | ||
"description": "Opinionated, transactional, MobX powered state container", | ||
@@ -5,0 +5,0 @@ "main": "dist/mobx-state-tree.js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
665109
12408