mobx-state-tree
Advanced tools
Comparing version 0.9.2 to 0.9.3
# 0.9.3 | ||
* Fix `note that a snapshot is compatible` when assigning a type to an optional version of itself | ||
* Fix error when deleting a non existing item from a map [#255](https://github.com/mobxjs/mobx-state-tree/issues/255) | ||
* Now all required TypeScript interfaces are exported in the main mobx-state-tree package [#256](https://github.com/mobxjs/mobx-state-tree/issues/256) | ||
# 0.9.2 | ||
@@ -3,0 +9,0 @@ |
@@ -1,8 +0,8 @@ | ||
import './core/node'; | ||
import './types/type'; | ||
export { types, IType } from './types'; | ||
export * from './core/mst-operations'; | ||
export { escapeJsonPath, unescapeJsonPath, IJsonPatch } from './core/json-patch'; | ||
export { onAction } from './core/action'; | ||
export { isStateTreeNode, IStateTreeNode } from './core/node'; | ||
export { asReduxStore, IReduxStore, connectReduxDevtools } from './interop/redux'; | ||
import "./core/node"; | ||
import "./types/type"; | ||
export { types, IType, ISimpleType, IComplexType, IModelType, ISnapshottable, IExtendedObservableMap } from "./types"; | ||
export * from "./core/mst-operations"; | ||
export { escapeJsonPath, unescapeJsonPath, IJsonPatch } from "./core/json-patch"; | ||
export { onAction } from "./core/action"; | ||
export { isStateTreeNode, IStateTreeNode } from "./core/node"; | ||
export { asReduxStore, IReduxStore, connectReduxDevtools } from "./interop/redux"; |
@@ -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.mobxStateTree||{},t.mobx)}(this,function(t,e){"use strict";function n(t,e){function n(){this.constructor=t}At(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}function r(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;s>=0;s--)(i=t[s])&&(a=(o<3?i(a):o>3?i(e,n,a):i(e,n))||a);return o>3&&a&&Object.defineProperty(e,n,a),a}function i(t){throw void 0===t&&(t="Illegal state"),new Error("[mobx-state-tree] "+t)}function o(t){return t}function a(){}function s(t){return!(!Array.isArray(t)&&!e.isObservableArray(t))}function u(t){return t?s(t)?t:[t]:St}function p(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}function c(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){var a=Object.getOwnPropertyDescriptor(i,o);"get"in a?Object.defineProperty(t,o,Ct({},a,{configurable:!0})):t[o]=i[o]}}return t}function l(t){if(null===t||"object"!=typeof t)return!1;var e=Object.getPrototypeOf(t);return e===Object.prototype||null===e}function h(t){return!(null===t||"object"!=typeof t||t instanceof Date||t instanceof RegExp)}function f(t){return null===t||void 0===t||("string"==typeof t||"number"==typeof t||"boolean"==typeof t||t instanceof Date)}function d(t){return f(t)?t:Object.freeze(t)}function y(t){return d(t),l(t)&&Object.keys(t).forEach(function(e){f(t[e])||Object.isFrozen(t[e])||y(t[e])}),t}function v(t){return"function"!=typeof t}function b(t,e,n){Object.defineProperty(t,e,{enumerable:!1,writable:!1,configurable:!0,value:n})}function g(t,e,n){Object.defineProperty(t,e,{enumerable:!0,writable:!1,configurable:!0,value:n})}function m(t,e){return t.push(e),function(){var n=t.indexOf(e);-1!==n&&t.splice(n,1)}}function w(t,e){return Tt.call(t,e)}function V(t){for(var e=new Array(t.length),n=0;n<t.length;n++)e[n]=t[n];return e}function P(t){switch("oldValue"in t||i("Patches without `oldValue` field cannot be inversed"),t.op){case"add":return{op:"remove",path:t.path,oldValue:t.value};case"remove":return{op:"add",path:t.path,value:t.oldValue};case"replace":return{op:"replace",path:t.path,value:t.oldValue,oldValue:t.value}}}function j(t){var e=Ct({},t);return delete e.oldValue,e}function A(t){return t.replace(/~/g,"~1").replace(/\//g,"~0")}function C(t){return t.replace(/~0/g,"\\").replace(/~1/g,"~")}function S(t){return 0===t.length?"":"/"+t.map(A).join("/")}function T(t){var e=t.split("/").map(C);return""===e[0]?e.slice(1):e}function O(t){for(var e=t.middlewares.slice(),n=t;n.parent;)n=n.parent,e=e.concat(n.middlewares);return e}function x(t,e,n){function r(t){var o=i.shift();return o?o(t,r):n.apply(e.object,e.args)}var i=O(t);return i.length?r(e):n.apply(e.object,e.args)}function _(t,n){var r=e.action(t,n);return function(){var e=X(this);if(e.assertAlive(),e.isRunningAction())return r.apply(this,arguments);var n={name:t,object:e.storedValue,args:V(arguments)},i=e.root;i._isRunningAction=!0;try{return x(e,n,r)}finally{i._isRunningAction=!1}}}function N(t,n,r,i){if(f(i))return i;if(Q(i)){var o=X(i);if(t.root!==o.root)throw new Error("Argument "+r+" that was passed to action '"+n+"' is a model that is not part of the same state tree. Consider passing a snapshot or some representative ID instead");return{$ref:t.getRelativePathTo(X(i))}}if("function"==typeof i)throw new Error("Argument "+r+" that was passed to action '"+n+"' should be a primitive, model object or plain object, received a function");if("object"==typeof i&&!l(i)&&!s(i))throw new Error("Argument "+r+" that was passed to action '"+n+"' should be a primitive, model object or plain object, received a "+(i&&i.constructor?i.constructor.name:"Complex Object"));if(e.isObservable(i))throw new Error("Argument "+r+" that was passed to action '"+n+"' should be a primitive, model object or plain object, received an mobx observable.");try{return JSON.stringify(i),i}catch(t){throw new Error("Argument "+r+" that was passed to action '"+n+"' is not serializable.")}}function z(t,e){if("object"==typeof e){var n=Object.keys(e);if(1===n.length&&"$ref"===n[0])return q(t.storedValue,e.$ref)}return e}function D(t,e){var n=G(t,e.path||"");if(!n)return i("Invalid action path: "+(e.path||""));var r=X(n);return"@APPLY_PATCHES"===e.name?$.call(null,n,e.args[0]):"@APPLY_SNAPSHOT"===e.name?B.call(null,n,e.args[0]):("function"!=typeof n[e.name]&&i("Action '"+e.name+"' does not exist in '"+r.path+"'"),n[e.name].apply(n,e.args?e.args.map(function(t){return z(r,t)}):[]))}function I(t,e){return M(t,function(n,r){var i=X(n.object);return e({name:n.name,path:X(t).getRelativePathTo(i),args:n.args.map(function(t,e){return N(i,n.name,e,t)})}),r(n)})}function E(t){return"object"==typeof t&&t&&!0===t.isType}function R(t){return E(t)&&(t.flags&(jt.String|jt.Number|jt.Boolean|jt.Date))>0}function k(t){return E(t)&&(t.flags&jt.Object)>0}function F(t){return(t.flags&jt.Reference)>0}function L(t){return X(t).type}function M(t,e){var n=X(t);return n.isProtectionEnabled||console.warn("It is recommended to protect the state tree before attaching action middleware, as otherwise it cannot be guaranteed that all changes are passed through middleware. See `protect`"),n.addMiddleWare(e)}function H(t,e,n){return void 0===n&&(n=!1),X(t).onPatch(e,n)}function U(t,e){return X(t).onSnapshot(e)}function $(t,e){X(t).applyPatches(u(e))}function J(t,e){var n=u(e).map(P);n.reverse(),X(t).applyPatches(n)}function W(t,n){e.runInAction(function(){u(n).forEach(function(e){return D(t,e)})})}function B(t,e){return X(t).applySnapshot(e)}function Y(t){return X(t).snapshot}function q(t,e){var n=X(t).resolve(e);return n?n.value:void 0}function G(t,e){var n=X(t).resolve(e,!1);if(void 0!==n)return n?n.value:void 0}function K(t,e){var n=X(t);n.getChildren().forEach(function(t){Q(t.storedValue)&&K(t.storedValue,e)}),e(n.storedValue)}function Q(t){return!(!t||!t.$treenode)}function X(t){return Q(t)?t.$treenode:i("Value "+t+" is no MST Node")}function Z(t){return t&&"object"==typeof t&&!(t instanceof Date)&&!Q(t)&&!Object.isFrozen(t)}function tt(){return X(this).snapshot}function et(t,e,n,r,s,u,p){if(void 0===u&&(u=o),void 0===p&&(p=a),Q(s)){var c=X(s);return c.isRoot||i("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 '"+c.path+"'"),c.setParent(e,n),c}var l=u(s),h=Z(l),f=new _t(t,e,n,r,l);e||(f.identifierCache=new Ot),h&&b(l,"$treenode",f);var d=!0;try{return h&&g(l,"toJSON",tt),f._isRunningAction=!0,p(f,s),f._isRunningAction=!1,e?e.root.identifierCache.addNodeToCache(f):f.identifierCache.addNodeToCache(f),f.fireHook("afterCreate"),e&&f.fireHook("afterAttach"),d=!1,f}finally{d&&(f._isAlive=!1)}}function nt(t){return"function"==typeof t?"<function"+(t.name?" "+t.name:"")+">":Q(t)?"<"+t+">":"`"+JSON.stringify(t)+"`"}function rt(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 t.length>0}).join("/"),i=r.length>0?'at path "/'+r+'" ':"",o=Q(e)?"value of type "+X(e).type.name+":":f(e)?"value":"snapshot",a=n&&Q(e)&&n.is(X(e).snapshot);return""+i+o+" "+nt(e)+" is not assignable "+(n?"to type: `"+n.name+"`":"")+(t.message?" ("+t.message+")":"")+(n?R(n)?".":", 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 it(t,e,n){return t.concat([{path:e,type:n}])}function ot(){return St}function at(t,e,n){return[{context:t,value:e,message:n}]}function st(t){return t.reduce(function(t,e){return t.concat(e)},[])}function ut(t,e){var n=t.validate(e,[{path:"",type:t}]);n.length>0&&i("Error while converting "+nt(e)+" to `"+t.name+"`:\n"+n.map(rt).join("\n"))}function pt(){return X(this)+"("+this.size+" items)"}function ct(t){t||i("Map.put cannot be used to set empty values");var e;if(Q(t))e=X(t);else{if(!h(t))return i("Map.put can only be used to store complex values");e=X(X(this).type.subType.create(t))}return e.identifierAttribute||i("Map.put can only be used to store complex values that have an identifier type attribute"),this.set(e.identifier,e.value),this}function lt(){return X(this)+"("+this.length+" items)"}function ht(t,e,n,r,o){function a(t){for(var e in p){var n=t[e];if(("string"==typeof n||"number"==typeof n)&&p[e][n])return p[e][n]}return null}var s=new Array(r.length),u={},p={};n.forEach(function(t){t.identifierAttribute&&((p[t.identifierAttribute]||(p[t.identifierAttribute]={}))[t.identifier]=t),u[t.nodeId]=t}),r.forEach(function(n,r){var p=""+o[r];if(Q(n))(l=X(n)).assertAlive(),l.parent===t?(u[l.nodeId]||i("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+"/"+p+"', but it lives already at '"+l.path+"'"),u[l.nodeId]=void 0,l.setParent(t,p),s[r]=l):s[r]=e.instantiate(t,p,void 0,n);else if(h(n)){var c=a(n);if(c){var l=e.reconcile(c,n);u[c.nodeId]=void 0,l.setParent(t,p),s[r]=l}else s[r]=e.instantiate(t,p,void 0,n)}else s[r]=e.instantiate(t,p,void 0,n)});for(var c in u)void 0!==u[c]&&u[c].die();return s}function ft(t){switch(typeof t){case"string":return Rt;case"number":return kt;case"boolean":return Ft;case"object":if(t instanceof Date)return Lt}return i("Cannot determine primtive type from value "+t)}function dt(t,e){var n="function"==typeof e?e():e;return ut(t,Q(n)?X(n).snapshot:n),new Ht(t,e)}function yt(t){return f(t)||i("Literal types can be built only on top of primitives"),new Jt(t)}function vt(t,n){return function(){var t=this,r=arguments;return X(this).assertAlive(),e.extras.allowStateChanges(!1,function(){return n.apply(t,r)})}}function bt(){return X(this).toString()}function gt(){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()||i("types.model must specify properties"),o=t.length>1&&t.shift()||{},a=t.shift()||{};return new Qt(n,r,o,a)}function mt(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n="string"==typeof t[0]?t.shift():"AnonymousModel";if(t.every(function(t){return E(t)}))return t.reduce(function(t,e){return mt(n,t,e.properties,e.state,e.actions)});var r=t.shift(),o=t.shift()||i("types.compose must specify properties or `{}`"),a=t.length>1&&t.shift()||{},s=t.shift()||{};return k(r)?gt(n,c({},r.properties,o),c({},r.state,a),c({},r.actions,s)):i("Only model types can be composed")}function wt(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var r=E(t)?null:t,i=E(t)?e.concat(t):e,o=i.map(function(t){return t.name}).join(" | ");return new te(o,i,r)}function Vt(t){var e=p({},t);return delete e.type,{name:t.type,args:[e]}}function Pt(t,e,n){function r(t){var i=e.shift();i?i(r)(t):n(t)}r(t)}var jt,At=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])},Ct=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++){e=arguments[n];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])}return t},St=Object.freeze([]),Tt=Object.prototype.hasOwnProperty;!function(t){t[t.String=1]="String",t[t.Number=2]="Number",t[t.Boolean=4]="Boolean",t[t.Date=8]="Date",t[t.Literal=16]="Literal",t[t.Array=32]="Array",t[t.Map=64]="Map",t[t.Object=128]="Object",t[t.Frozen=256]="Frozen",t[t.Optional=512]="Optional",t[t.Reference=1024]="Reference",t[t.Identifier=2048]="Identifier",t[t.Late=4096]="Late",t[t.Refinement=8192]="Refinement",t[t.Union=16384]="Union"}(jt||(jt={}));var Ot=function(){function t(){this.cache=e.observable.map()}return t.prototype.addNodeToCache=function(t){if(t.identifierAttribute){var n=t.identifier;this.cache.has(n)||this.cache.set(n,e.observable.shallowArray());var r=this.cache.get(n);-1!==r.indexOf(t)&&i("Already registered"),r.push(t)}return this},t.prototype.mergeCache=function(t){var e=this;t.identifierCache.cache.values().forEach(function(t){return t.forEach(function(t){e.addNodeToCache(t)})})},t.prototype.notifyDied=function(t){if(t.identifierAttribute){var e=this.cache.get(t.identifier);e&&e.remove(t)}},t.prototype.splitCache=function(e){var n=new t,r=e.path;return this.cache.values().forEach(function(t){for(var e=t.length-1;e>=0;e--)0===t[e].path.indexOf(r)&&(n.addNodeToCache(t[e]),t.splice(e,1))}),n},t.prototype.resolve=function(t,e){var n=this.cache.get(e);if(!n)return null;var r=n.filter(function(e){return t.isAssignableFrom(e.type)});switch(r.length){case 0:return null;case 1:return r[0];default:return i("Cannot resolve a reference to type '"+t.name+"' with id: '"+e+"' unambigously, there are multiple candidates: "+r.map(function(t){return t.path}).join(", "))}},t}(),xt=1,_t=function(){function t(t,n,r,i,o){var a=this;this.nodeId=++xt,this._parent=null,this.subpath="",this.isProtectionEnabled=!0,this.identifierAttribute=void 0,this._environment=void 0,this._isRunningAction=!1,this._autoUnbox=!0,this._isAlive=!0,this._isDetaching=!1,this.middlewares=[],this.snapshotSubscribers=[],this.patchSubscribers=[],this.disposers=[],this.type=t,this._parent=n,this.subpath=r,this.storedValue=o,this._environment=i,this.unbox=this.unbox.bind(this),this.applyPatches=_("@APPLY_PATCHES",function(t){t.forEach(function(t){var e=T(t.path);a.resolvePath(e.slice(0,-1)).applyPatchLocally(e[e.length-1],t)})}).bind(this.storedValue),this.applySnapshot=_("@APPLY_SNAPSHOT",function(t){return a.type.applySnapshot(a,t)}).bind(this.storedValue);var s=e.reaction(function(){return a.snapshot},function(t){a.emitSnapshot(t)});s.onError(function(t){throw t}),this.addDisposer(s)}return Object.defineProperty(t.prototype,"identifier",{get:function(){return this.identifierAttribute?this.storedValue[this.identifierAttribute]:null},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"path",{get:function(){return this.parent?this.parent.path+"/"+A(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,"parent",{get:function(){return this._parent},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"root",{get:function(){for(var t,e=this;t=e.parent;)e=t;return e},enumerable:!0,configurable:!0}),t.prototype.getRelativePathTo=function(t){this.root!==t.root&&i("Cannot calculate relative path: objects '"+this+"' and '"+t+"' are not part of the same object tree");for(var e=T(this.path),n=T(t.path),r=0;r<e.length&&e[r]===n[r];r++);return e.slice(r).map(function(t){return".."}).join("/")+S(n.slice(r))},t.prototype.resolve=function(t,e){return void 0===e&&(e=!0),this.resolvePath(T(t),e)},t.prototype.resolvePath=function(t,e){void 0===e&&(e=!0);for(var n=this,r=0;r<t.length;r++){if(""===t[r])n=n.root;else if(".."===t[r])n=n.parent;else{if("."===t[r]||""===t[r])continue;if(n){n=n.getChildNode(t[r]);continue}}if(!n)return e?i("Could not resolve '"+t[r]+"' in '"+S(t.slice(0,r-1))+"', path of the patch does not resolve"):void 0}return n},Object.defineProperty(t.prototype,"value",{get:function(){if(this._isAlive)return this.type.getValue(this)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isAlive",{get:function(){return this._isAlive},enumerable:!0,configurable:!0}),t.prototype.die=function(){this._isDetaching||Q(this.storedValue)&&(K(this.storedValue,function(t){return X(t).aboutToDie()}),K(this.storedValue,function(t){return X(t).finalizeDeath()}))},t.prototype.aboutToDie=function(){this.disposers.splice(0).forEach(function(t){return t()}),this.fireHook("beforeDestroy")},t.prototype.finalizeDeath=function(){this.root.identifierCache.notifyDied(this);var t=this,e=this.path;g(this,"snapshot",this.snapshot),this.patchSubscribers.splice(0),this.snapshotSubscribers.splice(0),this.patchSubscribers.splice(0),this._isAlive=!1,this._parent=null,this.subpath="",Object.defineProperty(this.storedValue,"$mobx",{get:function(){i("This object has died and is no longer part of a state tree. It cannot be used anymore. The object (of type '"+t.type.name+"') used to live at '"+e+"'. It is possible to access the last snapshot of this object using 'getSnapshot', or to create a fresh copy using 'clone'. If you want to remove an object from the tree without killing it, use 'detach' instead.")}})},t.prototype.assertAlive=function(){this._isAlive||i(this+" cannot be used anymore as it has died; it has been removed from a state tree. If you want to remove an element from a tree and let it live on, use 'detach' or 'clone' the value")},Object.defineProperty(t.prototype,"snapshot",{get:function(){if(this._isAlive)return d(this.type.getSnapshot(this))},enumerable:!0,configurable:!0}),t.prototype.onSnapshot=function(t){return m(this.snapshotSubscribers,t)},t.prototype.emitSnapshot=function(t){this.snapshotSubscribers.forEach(function(e){return e(t)})},t.prototype.applyPatchLocally=function(t,e){this.assertWritable(),this.type.applyPatchLocally(this,t,e)},t.prototype.onPatch=function(t,e){return m(this.patchSubscribers,e?t:function(e){return t(j(e))})},t.prototype.emitPatch=function(t,e){if(this.patchSubscribers.length){var n=p({},t,{path:e.path.substr(this.path.length)+"/"+t.path});this.patchSubscribers.forEach(function(t){return t(n)})}this.parent&&this.parent.emitPatch(t,e)},t.prototype.setParent=function(t,e){void 0===e&&(e=null),this.parent===t&&this.subpath===e||(this._parent&&t&&t!==this._parent&&i("A node cannot exists twice in the state tree. Failed to add "+this+" to path '"+t.path+"/"+e+"'."),!this._parent&&t&&t.root===this&&i("A state tree is not allowed to contain itself. Cannot assign "+this+" to path '"+t.path+"/"+e+"'"),!this._parent&&this._environment&&i("A state tree that has been initialized with an environment cannot be made part of another state tree."),this.parent&&!t?this.die():(this.subpath=e||"",t&&t!==this._parent&&(t.root.identifierCache.mergeCache(this),this._parent=t,this.fireHook("afterAttach"))))},t.prototype.addDisposer=function(t){this.disposers.unshift(t)},t.prototype.isRunningAction=function(){return!!this._isRunningAction||!this.isRoot&&this.parent.isRunningAction()},t.prototype.addMiddleWare=function(t){return m(this.middlewares,t)},t.prototype.getChildNode=function(t){this.assertAlive(),this._autoUnbox=!1;var e=this.type.getChildNode(this,t);return this._autoUnbox=!0,e},t.prototype.getChildren=function(){this.assertAlive(),this._autoUnbox=!1;var t=this.type.getChildren(this);return this._autoUnbox=!0,t},t.prototype.getChildType=function(t){return this.type.getChildType(t)},Object.defineProperty(t.prototype,"isProtected",{get:function(){return this.root.isProtectionEnabled},enumerable:!0,configurable:!0}),t.prototype.assertWritable=function(){this.assertAlive(),!this.isRunningAction()&&this.isProtected&&i("Cannot modify '"+this+"', the object is protected and can only be modified by using an action.")},t.prototype.removeChild=function(t){this.type.removeChild(this,t)},t.prototype.detach=function(){this._isAlive||i("Error while detaching, node is not alive."),this.isRoot||(this.fireHook("beforeDetach"),this._environment=this.root._environment,this._isDetaching=!0,this.identifierCache=this.root.identifierCache.splitCache(this),this.parent.removeChild(this.subpath),this._parent=null,this.subpath="",this._isDetaching=!1)},t.prototype.unbox=function(t){return t&&!0===this._autoUnbox?t.value:t},t.prototype.fireHook=function(t){var e=this.storedValue&&"object"==typeof this.storedValue&&this.storedValue[t];"function"==typeof e&&e.apply(this.storedValue)},t.prototype.toString=function(){var t=this.identifier?"(id: "+this.identifier+")":"";return this.type.name+"@"+(this.path||"<root>")+t+(this.isAlive?"":"[dead]")},r([e.observable],t.prototype,"_parent",void 0),r([e.observable],t.prototype,"subpath",void 0),r([e.computed],t.prototype,"path",null),r([e.computed],t.prototype,"value",null),r([e.computed],t.prototype,"snapshot",null),t}(),Nt=function(){function t(t){this.isType=!0,this.name=t}return t.prototype.create=function(t,e){return void 0===t&&(t=this.getDefaultSnapshot()),ut(this,t),this.instantiate(null,"",e,t).value},t.prototype.isAssignableFrom=function(t){return t===this},t.prototype.validate=function(t,e){return Q(t)?L(t)===this||this.isAssignableFrom(L(t))?ot():at(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){var n=t.parent,r=t.subpath;if(Q(e)&&X(e)===t)return t;if(t.type===this&&h(e)&&!Q(e)&&(!t.identifierAttribute||t.identifier===e[t.identifierAttribute]))return t.applySnapshot(e),t;if(t.die(),Q(e)&&this.isAssignableFrom(L(e))){var i=X(e);return i.setParent(n,r),i}return this.instantiate(n,r,t._environment,e)},Object.defineProperty(t.prototype,"Type",{get:function(){return i("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 i("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}),r([e.action],t.prototype,"create",null),t}(),zt=function(t){function e(e){return t.call(this,e)||this}return n(e,t),e.prototype.getValue=function(t){return t.storedValue},e.prototype.getSnapshot=function(t){return t.storedValue},e.prototype.getDefaultSnapshot=function(){},e.prototype.applySnapshot=function(t,e){i("Immutable types do not support applying snapshots")},e.prototype.applyPatchLocally=function(t,e,n){i("Immutable types do not support applying patches")},e.prototype.getChildren=function(t){return St},e.prototype.getChildNode=function(t,e){return i("No child '"+e+"' available in type: "+this.name)},e.prototype.getChildType=function(t){return i("No child '"+t+"' available in type: "+this.name)},e.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},e.prototype.removeChild=function(t,e){return i("No child '"+e+"' available in type: "+this.name)},e}(Nt),Dt=function(t){function o(n,r){var i=t.call(this,n)||this;return i.shouldAttachNode=!0,i.flags=jt.Map,i.createNewInstance=function(){var t=e.observable.shallowMap();return b(t,"put",ct),b(t,"toString",pt),t},i.finalizeNewInstance=function(t,n){var r=t.storedValue;e.extras.interceptReads(r,t.unbox),e.intercept(r,function(t){return i.willChange(t)}),t.applySnapshot(n),e.observe(r,i.didChange)},i.subType=r,i}return n(o,t),o.prototype.instantiate=function(t,e,n,r){return et(this,t,e,n,r,this.createNewInstance,this.finalizeNewInstance)},o.prototype.describe=function(){return"Map<string, "+this.subType.describe()+">"},o.prototype.getChildren=function(t){return t.storedValue.values()},o.prototype.getChildNode=function(t,e){var n=t.storedValue.get(e);return n||i("Not a child "+e),n},o.prototype.willChange=function(t){var e=X(t.object);switch(e.assertWritable(),t.type){case"update":var n=t.newValue;if(n===t.object.get(t.name))return null;ut(this.subType,n),t.newValue=this.subType.reconcile(e.getChildNode(t.name),t.newValue),this.verifyIdentifier(t.name,t.newValue);break;case"add":ut(this.subType,t.newValue),t.newValue=this.subType.instantiate(e,t.name,void 0,t.newValue),this.verifyIdentifier(t.name,t.newValue);break;case"delete":e.getChildNode(t.name).die()}return t},o.prototype.verifyIdentifier=function(t,e){var n=e.identifier;null!==n&&""+n!=""+t&&i("A map of objects containing an identifier should always store the object under their own identifier. Trying to store key '"+n+"', but expected: '"+t+"'")},o.prototype.getValue=function(t){return t.storedValue},o.prototype.getSnapshot=function(t){var e={};return t.getChildren().forEach(function(t){e[t.subpath]=t.snapshot}),e},o.prototype.didChange=function(t){var e=X(t.object);switch(t.type){case"update":return void e.emitPatch({op:"replace",path:A(t.name),value:t.newValue.snapshot,oldValue:t.oldValue?t.oldValue.snapshot:void 0},e);case"add":return void e.emitPatch({op:"add",path:A(t.name),value:t.newValue.snapshot,oldValue:void 0},e);case"delete":return void e.emitPatch({op:"remove",path:A(t.name),oldValue:t.oldValue.snapshot},e)}},o.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)}},o.prototype.applySnapshot=function(t,e){ut(this,e);var n=t.storedValue,r={};n.keys().forEach(function(t){r[t]=!1}),Object.keys(e).forEach(function(t){n.set(t,e[t]),r[t]=!0}),Object.keys(r).forEach(function(t){!1===r[t]&&n.delete(t)})},o.prototype.getChildType=function(t){return this.subType},o.prototype.isValidSnapshot=function(t,e){var n=this;return l(t)?st(Object.keys(t).map(function(r){return n.subType.validate(t[r],it(e,r,n.subType))})):at(e,t)},o.prototype.getDefaultSnapshot=function(){return{}},o.prototype.removeChild=function(t,e){t.storedValue.delete(e)},r([e.action],o.prototype,"applySnapshot",null),o}(Nt),It=function(t){function o(n,r){var i=t.call(this,n)||this;return i.shouldAttachNode=!0,i.flags=jt.Array,i.createNewInstance=function(){var t=e.observable.shallowArray();return b(t,"toString",lt),t},i.finalizeNewInstance=function(t,n){var r=t.storedValue;e.extras.getAdministration(r).dehancer=t.unbox,e.intercept(r,function(t){return i.willChange(t)}),t.applySnapshot(n),e.observe(r,i.didChange)},i.subType=r,i}return n(o,t),o.prototype.describe=function(){return this.subType.describe()+"[]"},o.prototype.instantiate=function(t,e,n,r){return et(this,t,e,n,r,this.createNewInstance,this.finalizeNewInstance)},o.prototype.getChildren=function(t){return t.storedValue.peek()},o.prototype.getChildNode=function(t,e){var n=parseInt(e,10);return n<t.storedValue.length?t.storedValue[n]:i("Not a child: "+e)},o.prototype.willChange=function(t){var e=X(t.object);e.assertWritable();var n=e.getChildren();switch(t.type){case"update":if(t.newValue===t.object[t.index])return null;t.newValue=ht(e,this.subType,[n[t.index]],[t.newValue],[t.index])[0];break;case"splice":var r=t.index,i=t.removedCount,o=t.added;t.added=ht(e,this.subType,n.slice(r,r+i),o,o.map(function(t,e){return r+e}));for(var a=r+i;a<n.length;a++)n[a].setParent(e,""+(a+o.length-i))}return t},o.prototype.getValue=function(t){return t.storedValue},o.prototype.getSnapshot=function(t){return t.getChildren().map(function(t){return t.snapshot})},o.prototype.didChange=function(t){var e=X(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(n=t.removedCount-1;n>=0;n--)e.emitPatch({op:"remove",path:""+(t.index+n),oldValue:t.removed[n].snapshot},e);for(var 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}},o.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)}},o.prototype.applySnapshot=function(t,e){ut(this,e),t.storedValue.replace(e)},o.prototype.getChildType=function(t){return this.subType},o.prototype.isValidSnapshot=function(t,e){var n=this;return s(t)?st(t.map(function(t,r){return n.subType.validate(t,it(e,""+r,n.subType))})):at(e,t)},o.prototype.getDefaultSnapshot=function(){return[]},o.prototype.removeChild=function(t,e){t.storedValue.splice(parseInt(e,10),1)},r([e.action],o.prototype,"applySnapshot",null),o}(Nt),Et=function(t){function e(e,n,r,i){void 0===i&&(i=o);var a=t.call(this,e)||this;return a.flags=n,a.checker=r,a.initializer=i,a}return n(e,t),e.prototype.describe=function(){return this.name},e.prototype.instantiate=function(t,e,n,r){return et(this,t,e,n,r,this.initializer)},e.prototype.isValidSnapshot=function(t,e){return f(t)&&this.checker(t)?ot():at(e,t)},e}(zt),Rt=new Et("string",jt.String,function(t){return"string"==typeof t}),kt=new Et("number",jt.Number,function(t){return"number"==typeof t}),Ft=new Et("boolean",jt.Boolean,function(t){return"boolean"==typeof t}),Lt=new Et("Date",jt.Date,function(t){return"number"==typeof t||t instanceof Date},function(t){return t instanceof Date?t:new Date(t)});Lt.getSnapshot=function(t){return t.storedValue.getTime()};var Mt=function(t){function e(e){var n=t.call(this,"identifier("+e.name+")")||this;return n.identifierType=e,n.flags=jt.Identifier,n}return n(e,t),e.prototype.instantiate=function(t,e,n,r){return t&&Q(t.storedValue)?(t.identifierAttribute&&i("Cannot define property '"+e+"' as object identifier, property '"+t.identifierAttribute+"' is already defined as identifier property"),t.identifierAttribute=e,et(this,t,e,n,r)):i("Identifier types can only be instantiated as direct child of a model type")},e.prototype.reconcile=function(t,e){return t.storedValue!==e?i("Tried to change identifier from '"+t.storedValue+"' to '"+e+"'. Changing identifiers is not allowed."):t},e.prototype.describe=function(){return"identifier("+this.identifierType.describe()+")"},e.prototype.isValidSnapshot=function(t,e){return void 0===t||null===t||"string"==typeof t||"number"==typeof t?this.identifierType.validate(t,e):at(e,t,"References should be a primitive value")},e}(zt),Ht=function(t){function e(e,n){var r=t.call(this,e.name)||this;return r.type=e,r.defaultValue=n,r}return n(e,t),Object.defineProperty(e.prototype,"flags",{get:function(){return this.type.flags|jt.Optional},enumerable:!0,configurable:!0}),e.prototype.describe=function(){return this.type.describe()+"?"},e.prototype.instantiate=function(t,e,n,r){if(void 0===r){var i=this.getDefaultValue(),o=Q(i)?X(i).snapshot:i;return this.type.instantiate(t,e,n,o)}return this.type.instantiate(t,e,n,r)},e.prototype.reconcile=function(t,e){return this.type.reconcile(t,this.type.is(e)?e:this.getDefaultValue())},e.prototype.getDefaultValue=function(){var t="function"==typeof this.defaultValue?this.defaultValue():this.defaultValue;return"function"==typeof this.defaultValue&&ut(this,t),t},e.prototype.isValidSnapshot=function(t,e){return void 0===t?ot():this.type.validate(t,e)},e}(zt),Ut=function(){function t(t){this.name=t}return t.prototype.initializePrototype=function(t){},t.prototype.initialize=function(t,e){},t.prototype.willChange=function(t){return null},t.prototype.didChange=function(t){},t.prototype.serialize=function(t,e){},t.prototype.deserialize=function(t,e){},t}(),$t=function(t){function r(e,n,r){var i=t.call(this,e)||this;return i.getter=n,i.setter=r,i}return n(r,t),r.prototype.initializePrototype=function(t){Object.defineProperty(t,this.name,e.computed(t,this.name,{get:this.getter,set:this.setter,configurable:!0,enumerable:!1}))},r.prototype.validate=function(t,e){return this.name in t?at(it(e,this.name),t[this.name],"Computed properties should not be provided in the snapshot"):ot()},r}(Ut),Jt=function(t){function e(e){var n=t.call(this,""+e)||this;return n.flags=jt.Literal,n.value=e,n}return n(e,t),e.prototype.instantiate=function(t,e,n,r){return et(this,t,e,n,r)},e.prototype.describe=function(){return JSON.stringify(this.value)},e.prototype.isValidSnapshot=function(t,e){return f(t)&&t===this.value?ot():at(e,t)},e}(zt),Wt=yt(void 0),Bt=function(t){function r(e,n){var r=t.call(this,e)||this;return r.type=n,r}return n(r,t),r.prototype.initializePrototype=function(t){e.observable.ref(t,this.name,{value:Wt.instantiate(null,"",null,void 0)})},r.prototype.initialize=function(t,n){var r=X(t);t[this.name]=this.type.instantiate(r,this.name,r._environment,n[this.name]),e.extras.interceptReads(t,this.name,r.unbox)},r.prototype.getValueNode=function(t){var e=t.$mobx.values[this.name].value;return e||i("Node not available for property "+this.name)},r.prototype.willChange=function(t){var e=X(t.object);return ut(this.type,t.newValue),t.newValue=this.type.reconcile(e.getChildNode(t.name),t.newValue),t},r.prototype.didChange=function(t){var e=X(t.object);e.emitPatch({op:"replace",path:A(this.name),value:t.newValue.snapshot,oldValue:t.oldValue?t.oldValue.snapshot:void 0},e)},r.prototype.serialize=function(t,n){e.extras.getAtom(t,this.name).reportObserved(),n[this.name]=this.getValueNode(t).snapshot},r.prototype.deserialize=function(t,e){t[this.name]=e[this.name]},r.prototype.validate=function(t,e){return this.type.validate(t[this.name],it(e,this.name,this.type))},r}(Ut),Yt=function(t){function e(e,n){var r=t.call(this,e)||this;return r.invokeAction=_(e,n),r}return n(e,t),e.prototype.initialize=function(t){b(t,this.name,this.invokeAction.bind(t))},e.prototype.validate=function(t,e){return this.name in t?at(it(e,this.name),t[this.name],"Action properties should not be provided in the snapshot"):ot()},e}(Ut),qt=function(t){function e(e,n){var r=t.call(this,e)||this;return r.invokeView=vt(e,n),r}return n(e,t),e.prototype.initialize=function(t){b(t,this.name,this.invokeView.bind(t))},e.prototype.validate=function(t,e){return this.name in t?at(it(e,this.name),t[this.name],"View properties should not be provided in the snapshot"):ot()},e}(Ut),Gt=function(t){function r(e,n){var r=t.call(this,e)||this;return r.initialValue=n,null!==n&&"object"==typeof n?i("Trying to declare property "+e+" with a non-primitive value. Please provide an initializer function to avoid accidental sharing of local state, like `"+e+": () => initialValue`"):r}return n(r,t),r.prototype.initialize=function(t,n){var r="function"==typeof this.initialValue?this.initialValue.call(t,t):this.initialValue;e.extendObservable(t,(i={},i[this.name]=r,i));var i},r.prototype.willChange=function(t){return t},r.prototype.validate=function(t,e){return this.name in t?at(it(e,this.name),t[this.name],"volatile state should not be provided in the snapshot"):ot()},r}(Ut),Kt=["preProcessSnapshot","afterCreate","afterAttach","postProcessSnapshot","beforeDetach","beforeDestroy"],Qt=function(t){function o(n,r,o,a){var s=t.call(this,n)||this;return s.shouldAttachNode=!0,s.flags=jt.Object,s.props={},s.createNewInstance=function(){var t=new s.modelConstructor;return e.extendShallowObservable(t,{}),t},s.finalizeNewInstance=function(t,n){var r=t.storedValue;s.forAllProps(function(t){return t.initialize(r,n)}),e.intercept(r,function(t){return s.willChange(t)}),e.observe(r,s.didChange)},s.didChange=function(t){s.props[t.name].didChange(t)},Object.freeze(r),Object.freeze(a),s.properties=r,s.state=o,s.actions=a,/^\w[\w\d_]*$/.test(n)||i("Typename should be a valid identifier: "+n),s.modelConstructor=new Function("return function "+n+" (){}")(),s.modelConstructor.prototype.toString=bt,s.parseModelProps(),s.forAllProps(function(t){return t.initializePrototype(s.modelConstructor.prototype)}),s}return n(o,t),o.prototype.instantiate=function(t,e,n,r){return et(this,t,e,n,this.preProcessSnapshot(r),this.createNewInstance,this.finalizeNewInstance)},o.prototype.willChange=function(t){return X(t.object).assertWritable(),this.props[t.name].willChange(t)},o.prototype.parseModelProps=function(){var t=this,e=t.properties,n=t.state,r=t.actions;for(var o in e)if(w(e,o)){-1!==Kt.indexOf(o)&&console.warn("Hook '"+o+"' was defined as property. Hooks should be defined as part of the actions");var a=Object.getOwnPropertyDescriptor(e,o);if("get"in a){this.props[o]=new $t(o,a.get,a.set);continue}if(null===(u=a.value))i("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(f(u)){var s=ft(u);this.props[o]=new Bt(o,dt(s,u))}else E(u)?this.props[o]=new Bt(o,u):"function"==typeof u?this.props[o]=new qt(o,u):i("object"==typeof u?"In property '"+o+"': base model's should not contain complex values: '"+u+"'":"Unexpected value for property '"+o+"'")}for(var o in n)if(w(n,o)){-1!==Kt.indexOf(o)&&console.warn("Hook '"+o+"' was defined as local state. Hooks should be defined as part of the actions");u=n[o];o in this.properties&&i("Property '"+o+"' was also defined as local state. Local state fields and properties should not collide"),this.props[o]=new Gt(o,u)}for(var o in r)if(w(r,o)){var u=r[o];o in this.properties&&i("Property '"+o+"' was also defined as action. Actions and properties should not collide"),o in this.state&&i("Property '"+o+"' was also defined as local state. Actions and state should not collide"),"function"==typeof u?this.props[o]=new Yt(o,u):i("Unexpected value for action '"+o+"'. Expected function, got "+typeof u)}},o.prototype.getChildren=function(t){var e=[];return this.forAllProps(function(n){n instanceof Bt&&e.push(n.getValueNode(t.storedValue))}),e},o.prototype.getChildNode=function(t,e){return this.props[e]instanceof Bt?this.props[e].getValueNode(t.storedValue):i("Not a value property: "+e)},o.prototype.getValue=function(t){return t.storedValue},o.prototype.getSnapshot=function(t){var e={};return this.forAllProps(function(n){return n.serialize(t.storedValue,e)}),this.postProcessSnapshot(e)},o.prototype.applyPatchLocally=function(t,e,n){"replace"!==n.op&&"add"!==n.op&&i("object does not support operation "+n.op),t.storedValue[e]=n.value},o.prototype.applySnapshot=function(t,e){var n=this.preProcessSnapshot(e);ut(this,n);for(var r in this.props)this.props[r].deserialize(t.storedValue,n)},o.prototype.preProcessSnapshot=function(t){return"function"==typeof this.actions.preProcessSnapshot?this.actions.preProcessSnapshot.call(null,t):t},o.prototype.postProcessSnapshot=function(t){return"function"==typeof this.actions.postProcessSnapshot?this.actions.postProcessSnapshot.call(null,t):t},o.prototype.getChildType=function(t){return this.props[t].type},o.prototype.isValidSnapshot=function(t,e){var n=this,r=this.preProcessSnapshot(t);return l(r)?st(Object.keys(this.props).map(function(t){return n.props[t].validate(r,e)})):at(e,r)},o.prototype.forAllProps=function(t){var e=this;Object.keys(this.props).forEach(function(n){return t(e.props[n])})},o.prototype.describe=function(){var t=this;return"{ "+Object.keys(this.props).map(function(e){var n=t.props[e];return n instanceof Bt?e+": "+n.type.describe():""}).filter(Boolean).join("; ")+" }"},o.prototype.getDefaultSnapshot=function(){return{}},o.prototype.removeChild=function(t,e){t.storedValue[e]=null},r([e.action],o.prototype,"applySnapshot",null),o}(Nt),Xt=function(){return function(t,e){if(this.mode=t,this.value=e,"object"===t){if(!Q(e))return i("Can only store references to tree nodes, got: '"+e+"'");if(!X(e).identifierAttribute)return i("Can only store references with a defined identifier attribute.")}}}(),Zt=function(t){function e(e){var n=t.call(this,"reference("+e.name+")")||this;return n.targetType=e,n.flags=jt.Reference,n}return n(e,t),e.prototype.describe=function(){return this.name},e.prototype.getValue=function(t){var e=t.storedValue;if("object"===e.mode)return e.value;if(t.isAlive){var n=t.root.identifierCache.resolve(this.targetType,e.value);return n?n.value:i("Failed to resolve reference of type "+this.targetType.name+": '"+e.value+"' (in: "+t.path+")")}},e.prototype.getSnapshot=function(t){var e=t.storedValue;switch(e.mode){case"identifier":return e.value;case"object":return X(e.value).identifier}},e.prototype.instantiate=function(t,e,n,r){var i=Q(r);return et(this,t,e,n,new Xt(i?"object":"identifier",r))},e.prototype.reconcile=function(t,e){var n=Q(e)?"object":"identifier";if(F(t.type)){var 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},e.prototype.isAssignableFrom=function(t){return this.targetType.isAssignableFrom(t)},e.prototype.isValidSnapshot=function(t,e){return"string"==typeof t||"number"==typeof t?ot():at(e,t,"Value '"+nt(t)+"' is not a valid reference. Expected a string or number.")},e}(zt),te=function(t){function e(e,n,r){var i=t.call(this,e)||this;return i.dispatcher=null,i.dispatcher=r,i.types=n,i}return n(e,t),Object.defineProperty(e.prototype,"flags",{get:function(){var t=jt.Union;return this.types.forEach(function(e){t|=e.flags}),t},enumerable:!0,configurable:!0}),e.prototype.isAssignableFrom=function(t){return this.types.some(function(e){return e.isAssignableFrom(t)})},e.prototype.describe=function(){return"("+this.types.map(function(t){return t.describe()}).join(" | ")+")"},e.prototype.instantiate=function(t,e,n,r){return this.determineType(r).instantiate(t,e,n,r)},e.prototype.reconcile=function(t,e){return this.determineType(e).reconcile(t,e)},e.prototype.determineType=function(t){if(null!==this.dispatcher)return this.dispatcher(t);var e=this.types.filter(function(e){return e.is(t)});return e.length>1?i("Ambiguos snapshot "+JSON.stringify(t)+" for union "+this.name+". Please provide a dispatch in the union declaration."):e[0]},e.prototype.isValidSnapshot=function(t,e){if(null!==this.dispatcher)return this.dispatcher(t).validate(t,e);var n=this.types.map(function(n){return n.validate(t,e)}),r=n.filter(function(t){return 0===t.length});return r.length>1?at(e,t,"Multiple types are applicable and no dispatch method is defined for the union"):r.length<1?at(e,t,"No type is applicable and no dispatch method is defined for the union").concat(st(n)):ot()},e}(zt),ee=new(function(t){function e(){var e=t.call(this,"frozen")||this;return e.flags=jt.Frozen,e}return n(e,t),e.prototype.describe=function(){return"<any immutable value>"},e.prototype.instantiate=function(t,e,n,r){return et(this,t,e,n,y(r))},e.prototype.isValidSnapshot=function(t,e){return v(t)?ot():at(e,t)},e}(zt)),ne=dt(yt(null),null),re=function(t){function e(e,n,r){var i=t.call(this,e)||this;return i.type=n,i.predicate=r,i}return n(e,t),Object.defineProperty(e.prototype,"flags",{get:function(){return this.type.flags|jt.Refinement},enumerable:!0,configurable:!0}),e.prototype.describe=function(){return this.name},e.prototype.instantiate=function(t,e,n,r){return this.type.instantiate(t,e,n,r)},e.prototype.isAssignableFrom=function(t){return this.type.isAssignableFrom(t)},e.prototype.isValidSnapshot=function(t,e){if(this.type.is(t)){var n=Q(t)?X(t).snapshot:t;if(this.predicate(n))return ot()}return at(e,t)},e}(zt),ie=function(t){function e(e,n){var r=t.call(this,e)||this;return r._subType=null,"function"==typeof n&&0===n.length||i("Invalid late type, expected a function with zero arguments that returns a type, got: "+n),r.definition=n,r}return n(e,t),Object.defineProperty(e.prototype,"flags",{get:function(){return this.subType.flags|jt.Late},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"subType",{get:function(){return null===this._subType&&(this._subType=this.definition()),this._subType},enumerable:!0,configurable:!0}),e.prototype.instantiate=function(t,e,n,r){return this.subType.instantiate(t,e,n,r)},e.prototype.reconcile=function(t,e){return this.subType.reconcile(t,e)},e.prototype.describe=function(){return this.subType.name},e.prototype.isValidSnapshot=function(t,e){return this.subType.validate(t,e)},e.prototype.isAssignableFrom=function(t){return this.subType.isAssignableFrom(t)},e}(zt),oe={model:gt,compose:mt,reference:function(t){return 2===arguments.length&&"string"==typeof arguments[1]&&i("References with base path are no longer supported. Please remove the base path."),new Zt(t)},union:wt,optional:dt,literal:yt,maybe:function(t){return t===ee&&i("Unable to declare `types.maybe(types.frozen)`. Frozen already accepts `null`. Consider using `types.optional(types.frozen, null)` instead."),wt(ne,t)},refinement:function(t,e,n){return new re(t,e,n)},string:Rt,boolean:Ft,number:kt,Date:Lt,map:function(t){return new Dt("map<string, "+t.name+">",t)},array:function(t){return new It(t.name+"[]",t)},frozen:ee,identifier:function(t){return void 0===t&&(t=Rt),new Mt(t)},late:function(t,e){var n="string"==typeof t?t:"late("+t.toString()+")";return new ie(n,"string"==typeof t?e:t)}};t.types=oe,t.escapeJsonPath=A,t.unescapeJsonPath=C,t.onAction=I,t.isStateTreeNode=Q,t.asReduxStore=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];Q(t)||i("Expected model object");var r={getState:function(){return Y(t)},dispatch:function(e){Pt(e,o.slice(),function(e){return D(t,Vt(e))})},subscribe:function(e){return U(t,e)}},o=e.map(function(t){return t(r)});return r},t.connectReduxDevtools=function(t,e){var n=t.connectViaExtension(),r=!1;n.subscribe(function(n){var i=t.extractState(n);i&&(r=!0,B(e,i),r=!1)}),I(e,function(t){if(!r){var i={};i.type=t.name,t.args&&t.args.forEach(function(t,e){return i[e]=t}),n.send(i,Y(e))}})},t.getType=L,t.getChildType=function(t,e){return X(t).getChildType(e)},t.addMiddleware=M,t.onPatch=H,t.onSnapshot=U,t.applyPatch=$,t.revertPatch=J,t.recordPatches=function(t){var e={patches:[],get cleanPatches(){return this.patches.map(j)},stop:function(){n()},replay:function(n){$(n||t,e.patches)},undo:function(e){J(t||t,this.patches)}},n=H(t,function(t){e.patches.push(t)},!0);return e},t.applyAction=W,t.recordActions=function(t){var e={actions:[],stop:function(){return n()},replay:function(t){W(t,e.actions)}},n=I(t,e.actions.push.bind(e.actions));return e},t.protect=function(t){var e=X(t);e.isRoot||i("`protect` can only be invoked on root nodes"),e.isProtectionEnabled=!0},t.unprotect=function(t){var e=X(t);e.isRoot||i("`unprotect` can only be invoked on root nodes"),e.isProtectionEnabled=!1},t.isProtected=function(t){return X(t).isProtected},t.applySnapshot=B,t.getSnapshot=Y,t.hasParent=function(t,e){void 0===e&&(e=1),e<0&&i("Invalid depth: "+e+", should be >= 1");for(var n=X(t).parent;n;){if(0==--e)return!0;n=n.parent}return!1},t.getParent=function(t,e){void 0===e&&(e=1),e<0&&i("Invalid depth: "+e+", should be >= 1");for(var n=e,r=X(t).parent;r;){if(0==--n)return r.storedValue;r=r.parent}return i("Failed to find the parent of "+X(t)+" at depth "+e)},t.getRoot=function(t){return X(t).root.storedValue},t.getPath=function(t){return X(t).path},t.getPathParts=function(t){return T(X(t).path)},t.isRoot=function(t){return X(t).isRoot},t.resolvePath=q,t.resolveIdentifier=function(t,e,n){E(t)||i("Expected a type as first argument");var r=X(e).root.identifierCache.resolve(t,""+n);return r?r.value:void 0},t.tryResolve=G,t.getRelativePath=function(t,e){return X(t).getRelativePathTo(X(e))},t.clone=function(t,e){void 0===e&&(e=!0);var n=X(t);return n.type.create(n.snapshot,!0===e?n.root._environment:!1===e?void 0:e)},t.detach=function(t){return X(t).detach(),t},t.destroy=function(t){var e=X(t);e.isRoot?e.die():e.parent.removeChild(e.subpath)},t.isAlive=function(t){return X(t).isAlive},t.addDisposer=function(t,e){X(t).addDisposer(e)},t.getEnv=function(t){var e=X(t),n=e.root._environment;return n||i("Node '"+e+"' is not part of state tree that was initialized with an environment. Environment can be passed as second argumentt to .create()"),n},t.walk=K,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.mobxStateTree||{},t.mobx)}(this,function(t,e){"use strict";function n(t,e){function n(){this.constructor=t}At(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}function r(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;s>=0;s--)(i=t[s])&&(a=(o<3?i(a):o>3?i(e,n,a):i(e,n))||a);return o>3&&a&&Object.defineProperty(e,n,a),a}function i(t){throw void 0===t&&(t="Illegal state"),new Error("[mobx-state-tree] "+t)}function o(t){return t}function a(){}function s(t){return!(!Array.isArray(t)&&!e.isObservableArray(t))}function u(t){return t?s(t)?t:[t]:St}function p(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}function c(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){var a=Object.getOwnPropertyDescriptor(i,o);"get"in a?Object.defineProperty(t,o,Ct({},a,{configurable:!0})):t[o]=i[o]}}return t}function l(t){if(null===t||"object"!=typeof t)return!1;var e=Object.getPrototypeOf(t);return e===Object.prototype||null===e}function h(t){return!(null===t||"object"!=typeof t||t instanceof Date||t instanceof RegExp)}function f(t){return null===t||void 0===t||("string"==typeof t||"number"==typeof t||"boolean"==typeof t||t instanceof Date)}function d(t){return f(t)?t:Object.freeze(t)}function y(t){return d(t),l(t)&&Object.keys(t).forEach(function(e){f(t[e])||Object.isFrozen(t[e])||y(t[e])}),t}function v(t){return"function"!=typeof t}function b(t,e,n){Object.defineProperty(t,e,{enumerable:!1,writable:!1,configurable:!0,value:n})}function g(t,e,n){Object.defineProperty(t,e,{enumerable:!0,writable:!1,configurable:!0,value:n})}function m(t,e){return t.push(e),function(){var n=t.indexOf(e);-1!==n&&t.splice(n,1)}}function w(t,e){return Tt.call(t,e)}function V(t){for(var e=new Array(t.length),n=0;n<t.length;n++)e[n]=t[n];return e}function P(t){switch("oldValue"in t||i("Patches without `oldValue` field cannot be inversed"),t.op){case"add":return{op:"remove",path:t.path,oldValue:t.value};case"remove":return{op:"add",path:t.path,value:t.oldValue};case"replace":return{op:"replace",path:t.path,value:t.oldValue,oldValue:t.value}}}function j(t){var e=Ct({},t);return delete e.oldValue,e}function A(t){return t.replace(/~/g,"~1").replace(/\//g,"~0")}function C(t){return t.replace(/~0/g,"\\").replace(/~1/g,"~")}function S(t){return 0===t.length?"":"/"+t.map(A).join("/")}function T(t){var e=t.split("/").map(C);return""===e[0]?e.slice(1):e}function O(t){for(var e=t.middlewares.slice(),n=t;n.parent;)n=n.parent,e=e.concat(n.middlewares);return e}function x(t,e,n){function r(t){var o=i.shift();return o?o(t,r):n.apply(e.object,e.args)}var i=O(t);return i.length?r(e):n.apply(e.object,e.args)}function _(t,n){var r=e.action(t,n);return function(){var e=X(this);if(e.assertAlive(),e.isRunningAction())return r.apply(this,arguments);var n={name:t,object:e.storedValue,args:V(arguments)},i=e.root;i._isRunningAction=!0;try{return x(e,n,r)}finally{i._isRunningAction=!1}}}function N(t,n,r,i){if(f(i))return i;if(Q(i)){var o=X(i);if(t.root!==o.root)throw new Error("Argument "+r+" that was passed to action '"+n+"' is a model that is not part of the same state tree. Consider passing a snapshot or some representative ID instead");return{$ref:t.getRelativePathTo(X(i))}}if("function"==typeof i)throw new Error("Argument "+r+" that was passed to action '"+n+"' should be a primitive, model object or plain object, received a function");if("object"==typeof i&&!l(i)&&!s(i))throw new Error("Argument "+r+" that was passed to action '"+n+"' should be a primitive, model object or plain object, received a "+(i&&i.constructor?i.constructor.name:"Complex Object"));if(e.isObservable(i))throw new Error("Argument "+r+" that was passed to action '"+n+"' should be a primitive, model object or plain object, received an mobx observable.");try{return JSON.stringify(i),i}catch(t){throw new Error("Argument "+r+" that was passed to action '"+n+"' is not serializable.")}}function z(t,e){if("object"==typeof e){var n=Object.keys(e);if(1===n.length&&"$ref"===n[0])return q(t.storedValue,e.$ref)}return e}function D(t,e){var n=G(t,e.path||"");if(!n)return i("Invalid action path: "+(e.path||""));var r=X(n);return"@APPLY_PATCHES"===e.name?$.call(null,n,e.args[0]):"@APPLY_SNAPSHOT"===e.name?B.call(null,n,e.args[0]):("function"!=typeof n[e.name]&&i("Action '"+e.name+"' does not exist in '"+r.path+"'"),n[e.name].apply(n,e.args?e.args.map(function(t){return z(r,t)}):[]))}function I(t,e){return M(t,function(n,r){var i=X(n.object);return e({name:n.name,path:X(t).getRelativePathTo(i),args:n.args.map(function(t,e){return N(i,n.name,e,t)})}),r(n)})}function E(t){return"object"==typeof t&&t&&!0===t.isType}function R(t){return E(t)&&(t.flags&(jt.String|jt.Number|jt.Boolean|jt.Date))>0}function k(t){return E(t)&&(t.flags&jt.Object)>0}function F(t){return(t.flags&jt.Reference)>0}function L(t){return X(t).type}function M(t,e){var n=X(t);return n.isProtectionEnabled||console.warn("It is recommended to protect the state tree before attaching action middleware, as otherwise it cannot be guaranteed that all changes are passed through middleware. See `protect`"),n.addMiddleWare(e)}function H(t,e,n){return void 0===n&&(n=!1),X(t).onPatch(e,n)}function U(t,e){return X(t).onSnapshot(e)}function $(t,e){X(t).applyPatches(u(e))}function J(t,e){var n=u(e).map(P);n.reverse(),X(t).applyPatches(n)}function W(t,n){e.runInAction(function(){u(n).forEach(function(e){return D(t,e)})})}function B(t,e){return X(t).applySnapshot(e)}function Y(t){return X(t).snapshot}function q(t,e){var n=X(t).resolve(e);return n?n.value:void 0}function G(t,e){var n=X(t).resolve(e,!1);if(void 0!==n)return n?n.value:void 0}function K(t,e){var n=X(t);n.getChildren().forEach(function(t){Q(t.storedValue)&&K(t.storedValue,e)}),e(n.storedValue)}function Q(t){return!(!t||!t.$treenode)}function X(t){return Q(t)?t.$treenode:i("Value "+t+" is no MST Node")}function Z(t){return t&&"object"==typeof t&&!(t instanceof Date)&&!Q(t)&&!Object.isFrozen(t)}function tt(){return X(this).snapshot}function et(t,e,n,r,s,u,p){if(void 0===u&&(u=o),void 0===p&&(p=a),Q(s)){var c=X(s);return c.isRoot||i("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 '"+c.path+"'"),c.setParent(e,n),c}var l=u(s),h=Z(l),f=new _t(t,e,n,r,l);e||(f.identifierCache=new Ot),h&&b(l,"$treenode",f);var d=!0;try{return h&&g(l,"toJSON",tt),f._isRunningAction=!0,p(f,s),f._isRunningAction=!1,e?e.root.identifierCache.addNodeToCache(f):f.identifierCache.addNodeToCache(f),f.fireHook("afterCreate"),e&&f.fireHook("afterAttach"),d=!1,f}finally{d&&(f._isAlive=!1)}}function nt(t){return"function"==typeof t?"<function"+(t.name?" "+t.name:"")+">":Q(t)?"<"+t+">":"`"+JSON.stringify(t)+"`"}function rt(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 t.length>0}).join("/"),i=r.length>0?'at path "/'+r+'" ':"",o=Q(e)?"value of type "+X(e).type.name+":":f(e)?"value":"snapshot",a=n&&Q(e)&&n.is(X(e).snapshot);return""+i+o+" "+nt(e)+" is not assignable "+(n?"to type: `"+n.name+"`":"")+(t.message?" ("+t.message+")":"")+(n?R(n)?".":", 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 it(t,e,n){return t.concat([{path:e,type:n}])}function ot(){return St}function at(t,e,n){return[{context:t,value:e,message:n}]}function st(t){return t.reduce(function(t,e){return t.concat(e)},[])}function ut(t,e){var n=t.validate(e,[{path:"",type:t}]);n.length>0&&i("Error while converting "+nt(e)+" to `"+t.name+"`:\n"+n.map(rt).join("\n"))}function pt(){return X(this)+"("+this.size+" items)"}function ct(t){t||i("Map.put cannot be used to set empty values");var e;if(Q(t))e=X(t);else{if(!h(t))return i("Map.put can only be used to store complex values");e=X(X(this).type.subType.create(t))}return e.identifierAttribute||i("Map.put can only be used to store complex values that have an identifier type attribute"),this.set(e.identifier,e.value),this}function lt(){return X(this)+"("+this.length+" items)"}function ht(t,e,n,r,o){function a(t){for(var e in p){var n=t[e];if(("string"==typeof n||"number"==typeof n)&&p[e][n])return p[e][n]}return null}var s=new Array(r.length),u={},p={};n.forEach(function(t){t.identifierAttribute&&((p[t.identifierAttribute]||(p[t.identifierAttribute]={}))[t.identifier]=t),u[t.nodeId]=t}),r.forEach(function(n,r){var p=""+o[r];if(Q(n))(l=X(n)).assertAlive(),l.parent===t?(u[l.nodeId]||i("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+"/"+p+"', but it lives already at '"+l.path+"'"),u[l.nodeId]=void 0,l.setParent(t,p),s[r]=l):s[r]=e.instantiate(t,p,void 0,n);else if(h(n)){var c=a(n);if(c){var l=e.reconcile(c,n);u[c.nodeId]=void 0,l.setParent(t,p),s[r]=l}else s[r]=e.instantiate(t,p,void 0,n)}else s[r]=e.instantiate(t,p,void 0,n)});for(var c in u)void 0!==u[c]&&u[c].die();return s}function ft(t){switch(typeof t){case"string":return Rt;case"number":return kt;case"boolean":return Ft;case"object":if(t instanceof Date)return Lt}return i("Cannot determine primtive type from value "+t)}function dt(t,e){var n="function"==typeof e?e():e;return ut(t,Q(n)?X(n).snapshot:n),new Ht(t,e)}function yt(t){return f(t)||i("Literal types can be built only on top of primitives"),new Jt(t)}function vt(t,n){return function(){var t=this,r=arguments;return X(this).assertAlive(),e.extras.allowStateChanges(!1,function(){return n.apply(t,r)})}}function bt(){return X(this).toString()}function gt(){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()||i("types.model must specify properties"),o=t.length>1&&t.shift()||{},a=t.shift()||{};return new Qt(n,r,o,a)}function mt(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n="string"==typeof t[0]?t.shift():"AnonymousModel";if(t.every(function(t){return E(t)}))return t.reduce(function(t,e){return mt(n,t,e.properties,e.state,e.actions)});var r=t.shift(),o=t.shift()||i("types.compose must specify properties or `{}`"),a=t.length>1&&t.shift()||{},s=t.shift()||{};return k(r)?gt(n,c({},r.properties,o),c({},r.state,a),c({},r.actions,s)):i("Only model types can be composed")}function wt(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var r=E(t)?null:t,i=E(t)?e.concat(t):e,o=i.map(function(t){return t.name}).join(" | ");return new te(o,i,r)}function Vt(t){var e=p({},t);return delete e.type,{name:t.type,args:[e]}}function Pt(t,e,n){function r(t){var i=e.shift();i?i(r)(t):n(t)}r(t)}var jt,At=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])},Ct=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++){e=arguments[n];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])}return t},St=Object.freeze([]),Tt=Object.prototype.hasOwnProperty;!function(t){t[t.String=1]="String",t[t.Number=2]="Number",t[t.Boolean=4]="Boolean",t[t.Date=8]="Date",t[t.Literal=16]="Literal",t[t.Array=32]="Array",t[t.Map=64]="Map",t[t.Object=128]="Object",t[t.Frozen=256]="Frozen",t[t.Optional=512]="Optional",t[t.Reference=1024]="Reference",t[t.Identifier=2048]="Identifier",t[t.Late=4096]="Late",t[t.Refinement=8192]="Refinement",t[t.Union=16384]="Union"}(jt||(jt={}));var Ot=function(){function t(){this.cache=e.observable.map()}return t.prototype.addNodeToCache=function(t){if(t.identifierAttribute){var n=t.identifier;this.cache.has(n)||this.cache.set(n,e.observable.shallowArray());var r=this.cache.get(n);-1!==r.indexOf(t)&&i("Already registered"),r.push(t)}return this},t.prototype.mergeCache=function(t){var e=this;t.identifierCache.cache.values().forEach(function(t){return t.forEach(function(t){e.addNodeToCache(t)})})},t.prototype.notifyDied=function(t){if(t.identifierAttribute){var e=this.cache.get(t.identifier);e&&e.remove(t)}},t.prototype.splitCache=function(e){var n=new t,r=e.path;return this.cache.values().forEach(function(t){for(var e=t.length-1;e>=0;e--)0===t[e].path.indexOf(r)&&(n.addNodeToCache(t[e]),t.splice(e,1))}),n},t.prototype.resolve=function(t,e){var n=this.cache.get(e);if(!n)return null;var r=n.filter(function(e){return t.isAssignableFrom(e.type)});switch(r.length){case 0:return null;case 1:return r[0];default:return i("Cannot resolve a reference to type '"+t.name+"' with id: '"+e+"' unambigously, there are multiple candidates: "+r.map(function(t){return t.path}).join(", "))}},t}(),xt=1,_t=function(){function t(t,n,r,i,o){var a=this;this.nodeId=++xt,this._parent=null,this.subpath="",this.isProtectionEnabled=!0,this.identifierAttribute=void 0,this._environment=void 0,this._isRunningAction=!1,this._autoUnbox=!0,this._isAlive=!0,this._isDetaching=!1,this.middlewares=[],this.snapshotSubscribers=[],this.patchSubscribers=[],this.disposers=[],this.type=t,this._parent=n,this.subpath=r,this.storedValue=o,this._environment=i,this.unbox=this.unbox.bind(this),this.applyPatches=_("@APPLY_PATCHES",function(t){t.forEach(function(t){var e=T(t.path);a.resolvePath(e.slice(0,-1)).applyPatchLocally(e[e.length-1],t)})}).bind(this.storedValue),this.applySnapshot=_("@APPLY_SNAPSHOT",function(t){if(t!==a.snapshot)return a.type.applySnapshot(a,t)}).bind(this.storedValue);var s=e.reaction(function(){return a.snapshot},function(t){a.emitSnapshot(t)});s.onError(function(t){throw t}),this.addDisposer(s)}return Object.defineProperty(t.prototype,"identifier",{get:function(){return this.identifierAttribute?this.storedValue[this.identifierAttribute]:null},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"path",{get:function(){return this.parent?this.parent.path+"/"+A(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,"parent",{get:function(){return this._parent},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"root",{get:function(){for(var t,e=this;t=e.parent;)e=t;return e},enumerable:!0,configurable:!0}),t.prototype.getRelativePathTo=function(t){this.root!==t.root&&i("Cannot calculate relative path: objects '"+this+"' and '"+t+"' are not part of the same object tree");for(var e=T(this.path),n=T(t.path),r=0;r<e.length&&e[r]===n[r];r++);return e.slice(r).map(function(t){return".."}).join("/")+S(n.slice(r))},t.prototype.resolve=function(t,e){return void 0===e&&(e=!0),this.resolvePath(T(t),e)},t.prototype.resolvePath=function(t,e){void 0===e&&(e=!0);for(var n=this,r=0;r<t.length;r++){if(""===t[r])n=n.root;else if(".."===t[r])n=n.parent;else{if("."===t[r]||""===t[r])continue;if(n){n=n.getChildNode(t[r]);continue}}if(!n)return e?i("Could not resolve '"+t[r]+"' in '"+S(t.slice(0,r-1))+"', path of the patch does not resolve"):void 0}return n},Object.defineProperty(t.prototype,"value",{get:function(){if(this._isAlive)return this.type.getValue(this)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isAlive",{get:function(){return this._isAlive},enumerable:!0,configurable:!0}),t.prototype.die=function(){this._isDetaching||Q(this.storedValue)&&(K(this.storedValue,function(t){return X(t).aboutToDie()}),K(this.storedValue,function(t){return X(t).finalizeDeath()}))},t.prototype.aboutToDie=function(){this.disposers.splice(0).forEach(function(t){return t()}),this.fireHook("beforeDestroy")},t.prototype.finalizeDeath=function(){this.root.identifierCache.notifyDied(this);var t=this,e=this.path;g(this,"snapshot",this.snapshot),this.patchSubscribers.splice(0),this.snapshotSubscribers.splice(0),this.patchSubscribers.splice(0),this._isAlive=!1,this._parent=null,this.subpath="",Object.defineProperty(this.storedValue,"$mobx",{get:function(){i("This object has died and is no longer part of a state tree. It cannot be used anymore. The object (of type '"+t.type.name+"') used to live at '"+e+"'. It is possible to access the last snapshot of this object using 'getSnapshot', or to create a fresh copy using 'clone'. If you want to remove an object from the tree without killing it, use 'detach' instead.")}})},t.prototype.assertAlive=function(){this._isAlive||i(this+" cannot be used anymore as it has died; it has been removed from a state tree. If you want to remove an element from a tree and let it live on, use 'detach' or 'clone' the value")},Object.defineProperty(t.prototype,"snapshot",{get:function(){if(this._isAlive)return d(this.type.getSnapshot(this))},enumerable:!0,configurable:!0}),t.prototype.onSnapshot=function(t){return m(this.snapshotSubscribers,t)},t.prototype.emitSnapshot=function(t){this.snapshotSubscribers.forEach(function(e){return e(t)})},t.prototype.applyPatchLocally=function(t,e){this.assertWritable(),this.type.applyPatchLocally(this,t,e)},t.prototype.onPatch=function(t,e){return m(this.patchSubscribers,e?t:function(e){return t(j(e))})},t.prototype.emitPatch=function(t,e){if(this.patchSubscribers.length){var n=p({},t,{path:e.path.substr(this.path.length)+"/"+t.path});this.patchSubscribers.forEach(function(t){return t(n)})}this.parent&&this.parent.emitPatch(t,e)},t.prototype.setParent=function(t,e){void 0===e&&(e=null),this.parent===t&&this.subpath===e||(this._parent&&t&&t!==this._parent&&i("A node cannot exists twice in the state tree. Failed to add "+this+" to path '"+t.path+"/"+e+"'."),!this._parent&&t&&t.root===this&&i("A state tree is not allowed to contain itself. Cannot assign "+this+" to path '"+t.path+"/"+e+"'"),!this._parent&&this._environment&&i("A state tree that has been initialized with an environment cannot be made part of another state tree."),this.parent&&!t?this.die():(this.subpath=e||"",t&&t!==this._parent&&(t.root.identifierCache.mergeCache(this),this._parent=t,this.fireHook("afterAttach"))))},t.prototype.addDisposer=function(t){this.disposers.unshift(t)},t.prototype.isRunningAction=function(){return!!this._isRunningAction||!this.isRoot&&this.parent.isRunningAction()},t.prototype.addMiddleWare=function(t){return m(this.middlewares,t)},t.prototype.getChildNode=function(t){this.assertAlive(),this._autoUnbox=!1;var e=this.type.getChildNode(this,t);return this._autoUnbox=!0,e},t.prototype.getChildren=function(){this.assertAlive(),this._autoUnbox=!1;var t=this.type.getChildren(this);return this._autoUnbox=!0,t},t.prototype.getChildType=function(t){return this.type.getChildType(t)},Object.defineProperty(t.prototype,"isProtected",{get:function(){return this.root.isProtectionEnabled},enumerable:!0,configurable:!0}),t.prototype.assertWritable=function(){this.assertAlive(),!this.isRunningAction()&&this.isProtected&&i("Cannot modify '"+this+"', the object is protected and can only be modified by using an action.")},t.prototype.removeChild=function(t){this.type.removeChild(this,t)},t.prototype.detach=function(){this._isAlive||i("Error while detaching, node is not alive."),this.isRoot||(this.fireHook("beforeDetach"),this._environment=this.root._environment,this._isDetaching=!0,this.identifierCache=this.root.identifierCache.splitCache(this),this.parent.removeChild(this.subpath),this._parent=null,this.subpath="",this._isDetaching=!1)},t.prototype.unbox=function(t){return t&&!0===this._autoUnbox?t.value:t},t.prototype.fireHook=function(t){var e=this.storedValue&&"object"==typeof this.storedValue&&this.storedValue[t];"function"==typeof e&&e.apply(this.storedValue)},t.prototype.toString=function(){var t=this.identifier?"(id: "+this.identifier+")":"";return this.type.name+"@"+(this.path||"<root>")+t+(this.isAlive?"":"[dead]")},r([e.observable],t.prototype,"_parent",void 0),r([e.observable],t.prototype,"subpath",void 0),r([e.computed],t.prototype,"path",null),r([e.computed],t.prototype,"value",null),r([e.computed],t.prototype,"snapshot",null),t}(),Nt=function(){function t(t){this.isType=!0,this.name=t}return t.prototype.create=function(t,e){return void 0===t&&(t=this.getDefaultSnapshot()),ut(this,t),this.instantiate(null,"",e,t).value},t.prototype.isAssignableFrom=function(t){return t===this},t.prototype.validate=function(t,e){return Q(t)?L(t)===this||this.isAssignableFrom(L(t))?ot():at(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(Q(e)&&X(e)===t)return t;if(t.type===this&&h(e)&&!Q(e)&&(!t.identifierAttribute||t.identifier===e[t.identifierAttribute]))return t.applySnapshot(e),t;var n=t.parent,r=t.subpath;if(t.die(),Q(e)&&this.isAssignableFrom(L(e))){var i=X(e);return i.setParent(n,r),i}return this.instantiate(n,r,t._environment,e)},Object.defineProperty(t.prototype,"Type",{get:function(){return i("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 i("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}),r([e.action],t.prototype,"create",null),t}(),zt=function(t){function e(e){return t.call(this,e)||this}return n(e,t),e.prototype.getValue=function(t){return t.storedValue},e.prototype.getSnapshot=function(t){return t.storedValue},e.prototype.getDefaultSnapshot=function(){},e.prototype.applySnapshot=function(t,e){i("Immutable types do not support applying snapshots")},e.prototype.applyPatchLocally=function(t,e,n){i("Immutable types do not support applying patches")},e.prototype.getChildren=function(t){return St},e.prototype.getChildNode=function(t,e){return i("No child '"+e+"' available in type: "+this.name)},e.prototype.getChildType=function(t){return i("No child '"+t+"' available in type: "+this.name)},e.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},e.prototype.removeChild=function(t,e){return i("No child '"+e+"' available in type: "+this.name)},e}(Nt),Dt=function(t){function o(n,r){var i=t.call(this,n)||this;return i.shouldAttachNode=!0,i.flags=jt.Map,i.createNewInstance=function(){var t=e.observable.shallowMap();return b(t,"put",ct),b(t,"toString",pt),t},i.finalizeNewInstance=function(t,n){var r=t.storedValue;e.extras.interceptReads(r,t.unbox),e.intercept(r,function(t){return i.willChange(t)}),t.applySnapshot(n),e.observe(r,i.didChange)},i.subType=r,i}return n(o,t),o.prototype.instantiate=function(t,e,n,r){return et(this,t,e,n,r,this.createNewInstance,this.finalizeNewInstance)},o.prototype.describe=function(){return"Map<string, "+this.subType.describe()+">"},o.prototype.getChildren=function(t){return t.storedValue.values()},o.prototype.getChildNode=function(t,e){var n=t.storedValue.get(e);return n||i("Not a child "+e),n},o.prototype.willChange=function(t){var e=X(t.object);switch(e.assertWritable(),t.type){case"update":var n=t.newValue;if(n===t.object.get(t.name))return null;ut(this.subType,n),t.newValue=this.subType.reconcile(e.getChildNode(t.name),t.newValue),this.verifyIdentifier(t.name,t.newValue);break;case"add":ut(this.subType,t.newValue),t.newValue=this.subType.instantiate(e,t.name,void 0,t.newValue),this.verifyIdentifier(t.name,t.newValue);break;case"delete":e.storedValue.has(t.name)&&e.getChildNode(t.name).die()}return t},o.prototype.verifyIdentifier=function(t,e){var n=e.identifier;null!==n&&""+n!=""+t&&i("A map of objects containing an identifier should always store the object under their own identifier. Trying to store key '"+n+"', but expected: '"+t+"'")},o.prototype.getValue=function(t){return t.storedValue},o.prototype.getSnapshot=function(t){var e={};return t.getChildren().forEach(function(t){e[t.subpath]=t.snapshot}),e},o.prototype.didChange=function(t){var e=X(t.object);switch(t.type){case"update":return void e.emitPatch({op:"replace",path:A(t.name),value:t.newValue.snapshot,oldValue:t.oldValue?t.oldValue.snapshot:void 0},e);case"add":return void e.emitPatch({op:"add",path:A(t.name),value:t.newValue.snapshot,oldValue:void 0},e);case"delete":return void e.emitPatch({op:"remove",path:A(t.name),oldValue:t.oldValue.snapshot},e)}},o.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)}},o.prototype.applySnapshot=function(t,e){ut(this,e);var n=t.storedValue,r={};n.keys().forEach(function(t){r[t]=!1}),Object.keys(e).forEach(function(t){n.set(t,e[t]),r[t]=!0}),Object.keys(r).forEach(function(t){!1===r[t]&&n.delete(t)})},o.prototype.getChildType=function(t){return this.subType},o.prototype.isValidSnapshot=function(t,e){var n=this;return l(t)?st(Object.keys(t).map(function(r){return n.subType.validate(t[r],it(e,r,n.subType))})):at(e,t)},o.prototype.getDefaultSnapshot=function(){return{}},o.prototype.removeChild=function(t,e){t.storedValue.delete(e)},r([e.action],o.prototype,"applySnapshot",null),o}(Nt),It=function(t){function o(n,r){var i=t.call(this,n)||this;return i.shouldAttachNode=!0,i.flags=jt.Array,i.createNewInstance=function(){var t=e.observable.shallowArray();return b(t,"toString",lt),t},i.finalizeNewInstance=function(t,n){var r=t.storedValue;e.extras.getAdministration(r).dehancer=t.unbox,e.intercept(r,function(t){return i.willChange(t)}),t.applySnapshot(n),e.observe(r,i.didChange)},i.subType=r,i}return n(o,t),o.prototype.describe=function(){return this.subType.describe()+"[]"},o.prototype.instantiate=function(t,e,n,r){return et(this,t,e,n,r,this.createNewInstance,this.finalizeNewInstance)},o.prototype.getChildren=function(t){return t.storedValue.peek()},o.prototype.getChildNode=function(t,e){var n=parseInt(e,10);return n<t.storedValue.length?t.storedValue[n]:i("Not a child: "+e)},o.prototype.willChange=function(t){var e=X(t.object);e.assertWritable();var n=e.getChildren();switch(t.type){case"update":if(t.newValue===t.object[t.index])return null;t.newValue=ht(e,this.subType,[n[t.index]],[t.newValue],[t.index])[0];break;case"splice":var r=t.index,i=t.removedCount,o=t.added;t.added=ht(e,this.subType,n.slice(r,r+i),o,o.map(function(t,e){return r+e}));for(var a=r+i;a<n.length;a++)n[a].setParent(e,""+(a+o.length-i))}return t},o.prototype.getValue=function(t){return t.storedValue},o.prototype.getSnapshot=function(t){return t.getChildren().map(function(t){return t.snapshot})},o.prototype.didChange=function(t){var e=X(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(n=t.removedCount-1;n>=0;n--)e.emitPatch({op:"remove",path:""+(t.index+n),oldValue:t.removed[n].snapshot},e);for(var 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}},o.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)}},o.prototype.applySnapshot=function(t,e){ut(this,e),t.storedValue.replace(e)},o.prototype.getChildType=function(t){return this.subType},o.prototype.isValidSnapshot=function(t,e){var n=this;return s(t)?st(t.map(function(t,r){return n.subType.validate(t,it(e,""+r,n.subType))})):at(e,t)},o.prototype.getDefaultSnapshot=function(){return[]},o.prototype.removeChild=function(t,e){t.storedValue.splice(parseInt(e,10),1)},r([e.action],o.prototype,"applySnapshot",null),o}(Nt),Et=function(t){function e(e,n,r,i){void 0===i&&(i=o);var a=t.call(this,e)||this;return a.flags=n,a.checker=r,a.initializer=i,a}return n(e,t),e.prototype.describe=function(){return this.name},e.prototype.instantiate=function(t,e,n,r){return et(this,t,e,n,r,this.initializer)},e.prototype.isValidSnapshot=function(t,e){return f(t)&&this.checker(t)?ot():at(e,t)},e}(zt),Rt=new Et("string",jt.String,function(t){return"string"==typeof t}),kt=new Et("number",jt.Number,function(t){return"number"==typeof t}),Ft=new Et("boolean",jt.Boolean,function(t){return"boolean"==typeof t}),Lt=new Et("Date",jt.Date,function(t){return"number"==typeof t||t instanceof Date},function(t){return t instanceof Date?t:new Date(t)});Lt.getSnapshot=function(t){return t.storedValue.getTime()};var Mt=function(t){function e(e){var n=t.call(this,"identifier("+e.name+")")||this;return n.identifierType=e,n.flags=jt.Identifier,n}return n(e,t),e.prototype.instantiate=function(t,e,n,r){return t&&Q(t.storedValue)?(t.identifierAttribute&&i("Cannot define property '"+e+"' as object identifier, property '"+t.identifierAttribute+"' is already defined as identifier property"),t.identifierAttribute=e,et(this,t,e,n,r)):i("Identifier types can only be instantiated as direct child of a model type")},e.prototype.reconcile=function(t,e){return t.storedValue!==e?i("Tried to change identifier from '"+t.storedValue+"' to '"+e+"'. Changing identifiers is not allowed."):t},e.prototype.describe=function(){return"identifier("+this.identifierType.describe()+")"},e.prototype.isValidSnapshot=function(t,e){return void 0===t||null===t||"string"==typeof t||"number"==typeof t?this.identifierType.validate(t,e):at(e,t,"References should be a primitive value")},e}(zt),Ht=function(t){function e(e,n){var r=t.call(this,e.name)||this;return r.type=e,r.defaultValue=n,r}return n(e,t),Object.defineProperty(e.prototype,"flags",{get:function(){return this.type.flags|jt.Optional},enumerable:!0,configurable:!0}),e.prototype.describe=function(){return this.type.describe()+"?"},e.prototype.instantiate=function(t,e,n,r){if(void 0===r){var i=this.getDefaultValue(),o=Q(i)?X(i).snapshot:i;return this.type.instantiate(t,e,n,o)}return this.type.instantiate(t,e,n,r)},e.prototype.reconcile=function(t,e){return this.type.reconcile(t,this.type.is(e)?e:this.getDefaultValue())},e.prototype.getDefaultValue=function(){var t="function"==typeof this.defaultValue?this.defaultValue():this.defaultValue;return"function"==typeof this.defaultValue&&ut(this,t),t},e.prototype.isValidSnapshot=function(t,e){return void 0===t?ot():this.type.validate(t,e)},e.prototype.isAssignableFrom=function(t){return this.type.isAssignableFrom(t)},e}(zt),Ut=function(){function t(t){this.name=t}return t.prototype.initializePrototype=function(t){},t.prototype.initialize=function(t,e){},t.prototype.willChange=function(t){return null},t.prototype.didChange=function(t){},t.prototype.serialize=function(t,e){},t.prototype.deserialize=function(t,e){},t}(),$t=function(t){function r(e,n,r){var i=t.call(this,e)||this;return i.getter=n,i.setter=r,i}return n(r,t),r.prototype.initializePrototype=function(t){Object.defineProperty(t,this.name,e.computed(t,this.name,{get:this.getter,set:this.setter,configurable:!0,enumerable:!1}))},r.prototype.validate=function(t,e){return this.name in t?at(it(e,this.name),t[this.name],"Computed properties should not be provided in the snapshot"):ot()},r}(Ut),Jt=function(t){function e(e){var n=t.call(this,""+e)||this;return n.flags=jt.Literal,n.value=e,n}return n(e,t),e.prototype.instantiate=function(t,e,n,r){return et(this,t,e,n,r)},e.prototype.describe=function(){return JSON.stringify(this.value)},e.prototype.isValidSnapshot=function(t,e){return f(t)&&t===this.value?ot():at(e,t)},e}(zt),Wt=yt(void 0),Bt=function(t){function r(e,n){var r=t.call(this,e)||this;return r.type=n,r}return n(r,t),r.prototype.initializePrototype=function(t){e.observable.ref(t,this.name,{value:Wt.instantiate(null,"",null,void 0)})},r.prototype.initialize=function(t,n){var r=X(t);t[this.name]=this.type.instantiate(r,this.name,r._environment,n[this.name]),e.extras.interceptReads(t,this.name,r.unbox)},r.prototype.getValueNode=function(t){var e=t.$mobx.values[this.name].value;return e||i("Node not available for property "+this.name)},r.prototype.willChange=function(t){var e=X(t.object);return ut(this.type,t.newValue),t.newValue=this.type.reconcile(e.getChildNode(t.name),t.newValue),t},r.prototype.didChange=function(t){var e=X(t.object);e.emitPatch({op:"replace",path:A(this.name),value:t.newValue.snapshot,oldValue:t.oldValue?t.oldValue.snapshot:void 0},e)},r.prototype.serialize=function(t,n){e.extras.getAtom(t,this.name).reportObserved(),n[this.name]=this.getValueNode(t).snapshot},r.prototype.deserialize=function(t,e){t[this.name]=e[this.name]},r.prototype.validate=function(t,e){return this.type.validate(t[this.name],it(e,this.name,this.type))},r}(Ut),Yt=function(t){function e(e,n){var r=t.call(this,e)||this;return r.invokeAction=_(e,n),r}return n(e,t),e.prototype.initialize=function(t){b(t,this.name,this.invokeAction.bind(t))},e.prototype.validate=function(t,e){return this.name in t?at(it(e,this.name),t[this.name],"Action properties should not be provided in the snapshot"):ot()},e}(Ut),qt=function(t){function e(e,n){var r=t.call(this,e)||this;return r.invokeView=vt(e,n),r}return n(e,t),e.prototype.initialize=function(t){b(t,this.name,this.invokeView.bind(t))},e.prototype.validate=function(t,e){return this.name in t?at(it(e,this.name),t[this.name],"View properties should not be provided in the snapshot"):ot()},e}(Ut),Gt=function(t){function r(e,n){var r=t.call(this,e)||this;return r.initialValue=n,null!==n&&"object"==typeof n?i("Trying to declare property "+e+" with a non-primitive value. Please provide an initializer function to avoid accidental sharing of local state, like `"+e+": () => initialValue`"):r}return n(r,t),r.prototype.initialize=function(t,n){var r="function"==typeof this.initialValue?this.initialValue.call(t,t):this.initialValue;e.extendObservable(t,(i={},i[this.name]=r,i));var i},r.prototype.willChange=function(t){return t},r.prototype.validate=function(t,e){return this.name in t?at(it(e,this.name),t[this.name],"volatile state should not be provided in the snapshot"):ot()},r}(Ut),Kt=["preProcessSnapshot","afterCreate","afterAttach","postProcessSnapshot","beforeDetach","beforeDestroy"],Qt=function(t){function o(n,r,o,a){var s=t.call(this,n)||this;return s.shouldAttachNode=!0,s.flags=jt.Object,s.props={},s.createNewInstance=function(){var t=new s.modelConstructor;return e.extendShallowObservable(t,{}),t},s.finalizeNewInstance=function(t,n){var r=t.storedValue;s.forAllProps(function(t){return t.initialize(r,n)}),e.intercept(r,function(t){return s.willChange(t)}),e.observe(r,s.didChange)},s.didChange=function(t){s.props[t.name].didChange(t)},Object.freeze(r),Object.freeze(a),s.properties=r,s.state=o,s.actions=a,/^\w[\w\d_]*$/.test(n)||i("Typename should be a valid identifier: "+n),s.modelConstructor=new Function("return function "+n+" (){}")(),s.modelConstructor.prototype.toString=bt,s.parseModelProps(),s.forAllProps(function(t){return t.initializePrototype(s.modelConstructor.prototype)}),s}return n(o,t),o.prototype.instantiate=function(t,e,n,r){return et(this,t,e,n,this.preProcessSnapshot(r),this.createNewInstance,this.finalizeNewInstance)},o.prototype.willChange=function(t){return X(t.object).assertWritable(),this.props[t.name].willChange(t)},o.prototype.parseModelProps=function(){var t=this,e=t.properties,n=t.state,r=t.actions;for(var o in e)if(w(e,o)){-1!==Kt.indexOf(o)&&console.warn("Hook '"+o+"' was defined as property. Hooks should be defined as part of the actions");var a=Object.getOwnPropertyDescriptor(e,o);if("get"in a){this.props[o]=new $t(o,a.get,a.set);continue}if(null===(u=a.value))i("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(f(u)){var s=ft(u);this.props[o]=new Bt(o,dt(s,u))}else E(u)?this.props[o]=new Bt(o,u):"function"==typeof u?this.props[o]=new qt(o,u):i("object"==typeof u?"In property '"+o+"': base model's should not contain complex values: '"+u+"'":"Unexpected value for property '"+o+"'")}for(var o in n)if(w(n,o)){-1!==Kt.indexOf(o)&&console.warn("Hook '"+o+"' was defined as local state. Hooks should be defined as part of the actions");u=n[o];o in this.properties&&i("Property '"+o+"' was also defined as local state. Local state fields and properties should not collide"),this.props[o]=new Gt(o,u)}for(var o in r)if(w(r,o)){var u=r[o];o in this.properties&&i("Property '"+o+"' was also defined as action. Actions and properties should not collide"),o in this.state&&i("Property '"+o+"' was also defined as local state. Actions and state should not collide"),"function"==typeof u?this.props[o]=new Yt(o,u):i("Unexpected value for action '"+o+"'. Expected function, got "+typeof u)}},o.prototype.getChildren=function(t){var e=[];return this.forAllProps(function(n){n instanceof Bt&&e.push(n.getValueNode(t.storedValue))}),e},o.prototype.getChildNode=function(t,e){return this.props[e]instanceof Bt?this.props[e].getValueNode(t.storedValue):i("Not a value property: "+e)},o.prototype.getValue=function(t){return t.storedValue},o.prototype.getSnapshot=function(t){var e={};return this.forAllProps(function(n){return n.serialize(t.storedValue,e)}),this.postProcessSnapshot(e)},o.prototype.applyPatchLocally=function(t,e,n){"replace"!==n.op&&"add"!==n.op&&i("object does not support operation "+n.op),t.storedValue[e]=n.value},o.prototype.applySnapshot=function(t,e){var n=this.preProcessSnapshot(e);ut(this,n);for(var r in this.props)this.props[r].deserialize(t.storedValue,n)},o.prototype.preProcessSnapshot=function(t){return"function"==typeof this.actions.preProcessSnapshot?this.actions.preProcessSnapshot.call(null,t):t},o.prototype.postProcessSnapshot=function(t){return"function"==typeof this.actions.postProcessSnapshot?this.actions.postProcessSnapshot.call(null,t):t},o.prototype.getChildType=function(t){return this.props[t].type},o.prototype.isValidSnapshot=function(t,e){var n=this,r=this.preProcessSnapshot(t);return l(r)?st(Object.keys(this.props).map(function(t){return n.props[t].validate(r,e)})):at(e,r)},o.prototype.forAllProps=function(t){var e=this;Object.keys(this.props).forEach(function(n){return t(e.props[n])})},o.prototype.describe=function(){var t=this;return"{ "+Object.keys(this.props).map(function(e){var n=t.props[e];return n instanceof Bt?e+": "+n.type.describe():""}).filter(Boolean).join("; ")+" }"},o.prototype.getDefaultSnapshot=function(){return{}},o.prototype.removeChild=function(t,e){t.storedValue[e]=null},r([e.action],o.prototype,"applySnapshot",null),o}(Nt),Xt=function(){return function(t,e){if(this.mode=t,this.value=e,"object"===t){if(!Q(e))return i("Can only store references to tree nodes, got: '"+e+"'");if(!X(e).identifierAttribute)return i("Can only store references with a defined identifier attribute.")}}}(),Zt=function(t){function e(e){var n=t.call(this,"reference("+e.name+")")||this;return n.targetType=e,n.flags=jt.Reference,n}return n(e,t),e.prototype.describe=function(){return this.name},e.prototype.getValue=function(t){var e=t.storedValue;if("object"===e.mode)return e.value;if(t.isAlive){var n=t.root.identifierCache.resolve(this.targetType,e.value);return n?n.value:i("Failed to resolve reference of type "+this.targetType.name+": '"+e.value+"' (in: "+t.path+")")}},e.prototype.getSnapshot=function(t){var e=t.storedValue;switch(e.mode){case"identifier":return e.value;case"object":return X(e.value).identifier}},e.prototype.instantiate=function(t,e,n,r){var i=Q(r);return et(this,t,e,n,new Xt(i?"object":"identifier",r))},e.prototype.reconcile=function(t,e){var n=Q(e)?"object":"identifier";if(F(t.type)){var 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},e.prototype.isAssignableFrom=function(t){return this.targetType.isAssignableFrom(t)},e.prototype.isValidSnapshot=function(t,e){return"string"==typeof t||"number"==typeof t?ot():at(e,t,"Value '"+nt(t)+"' is not a valid reference. Expected a string or number.")},e}(zt),te=function(t){function e(e,n,r){var i=t.call(this,e)||this;return i.dispatcher=null,i.dispatcher=r,i.types=n,i}return n(e,t),Object.defineProperty(e.prototype,"flags",{get:function(){var t=jt.Union;return this.types.forEach(function(e){t|=e.flags}),t},enumerable:!0,configurable:!0}),e.prototype.isAssignableFrom=function(t){return this.types.some(function(e){return e.isAssignableFrom(t)})},e.prototype.describe=function(){return"("+this.types.map(function(t){return t.describe()}).join(" | ")+")"},e.prototype.instantiate=function(t,e,n,r){return this.determineType(r).instantiate(t,e,n,r)},e.prototype.reconcile=function(t,e){return this.determineType(e).reconcile(t,e)},e.prototype.determineType=function(t){if(null!==this.dispatcher)return this.dispatcher(t);var e=this.types.filter(function(e){return e.is(t)});return e.length>1?i("Ambiguos snapshot "+JSON.stringify(t)+" for union "+this.name+". Please provide a dispatch in the union declaration."):e[0]},e.prototype.isValidSnapshot=function(t,e){if(null!==this.dispatcher)return this.dispatcher(t).validate(t,e);var n=this.types.map(function(n){return n.validate(t,e)}),r=n.filter(function(t){return 0===t.length});return r.length>1?at(e,t,"Multiple types are applicable and no dispatch method is defined for the union"):r.length<1?at(e,t,"No type is applicable and no dispatch method is defined for the union").concat(st(n)):ot()},e}(zt),ee=new(function(t){function e(){var e=t.call(this,"frozen")||this;return e.flags=jt.Frozen,e}return n(e,t),e.prototype.describe=function(){return"<any immutable value>"},e.prototype.instantiate=function(t,e,n,r){return et(this,t,e,n,y(r))},e.prototype.isValidSnapshot=function(t,e){return v(t)?ot():at(e,t)},e}(zt)),ne=dt(yt(null),null),re=function(t){function e(e,n,r){var i=t.call(this,e)||this;return i.type=n,i.predicate=r,i}return n(e,t),Object.defineProperty(e.prototype,"flags",{get:function(){return this.type.flags|jt.Refinement},enumerable:!0,configurable:!0}),e.prototype.describe=function(){return this.name},e.prototype.instantiate=function(t,e,n,r){return this.type.instantiate(t,e,n,r)},e.prototype.isAssignableFrom=function(t){return this.type.isAssignableFrom(t)},e.prototype.isValidSnapshot=function(t,e){if(this.type.is(t)){var n=Q(t)?X(t).snapshot:t;if(this.predicate(n))return ot()}return at(e,t)},e}(zt),ie=function(t){function e(e,n){var r=t.call(this,e)||this;return r._subType=null,"function"==typeof n&&0===n.length||i("Invalid late type, expected a function with zero arguments that returns a type, got: "+n),r.definition=n,r}return n(e,t),Object.defineProperty(e.prototype,"flags",{get:function(){return this.subType.flags|jt.Late},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"subType",{get:function(){return null===this._subType&&(this._subType=this.definition()),this._subType},enumerable:!0,configurable:!0}),e.prototype.instantiate=function(t,e,n,r){return this.subType.instantiate(t,e,n,r)},e.prototype.reconcile=function(t,e){return this.subType.reconcile(t,e)},e.prototype.describe=function(){return this.subType.name},e.prototype.isValidSnapshot=function(t,e){return this.subType.validate(t,e)},e.prototype.isAssignableFrom=function(t){return this.subType.isAssignableFrom(t)},e}(zt),oe={model:gt,compose:mt,reference:function(t){return 2===arguments.length&&"string"==typeof arguments[1]&&i("References with base path are no longer supported. Please remove the base path."),new Zt(t)},union:wt,optional:dt,literal:yt,maybe:function(t){return t===ee&&i("Unable to declare `types.maybe(types.frozen)`. Frozen already accepts `null`. Consider using `types.optional(types.frozen, null)` instead."),wt(ne,t)},refinement:function(t,e,n){return new re(t,e,n)},string:Rt,boolean:Ft,number:kt,Date:Lt,map:function(t){return new Dt("map<string, "+t.name+">",t)},array:function(t){return new It(t.name+"[]",t)},frozen:ee,identifier:function(t){return void 0===t&&(t=Rt),new Mt(t)},late:function(t,e){var n="string"==typeof t?t:"late("+t.toString()+")";return new ie(n,"string"==typeof t?e:t)}};t.types=oe,t.escapeJsonPath=A,t.unescapeJsonPath=C,t.onAction=I,t.isStateTreeNode=Q,t.asReduxStore=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];Q(t)||i("Expected model object");var r={getState:function(){return Y(t)},dispatch:function(e){Pt(e,o.slice(),function(e){return D(t,Vt(e))})},subscribe:function(e){return U(t,e)}},o=e.map(function(t){return t(r)});return r},t.connectReduxDevtools=function(t,e){var n=t.connectViaExtension(),r=!1;n.subscribe(function(n){var i=t.extractState(n);i&&(r=!0,B(e,i),r=!1)}),I(e,function(t){if(!r){var i={};i.type=t.name,t.args&&t.args.forEach(function(t,e){return i[e]=t}),n.send(i,Y(e))}})},t.getType=L,t.getChildType=function(t,e){return X(t).getChildType(e)},t.addMiddleware=M,t.onPatch=H,t.onSnapshot=U,t.applyPatch=$,t.revertPatch=J,t.recordPatches=function(t){var e={patches:[],get cleanPatches(){return this.patches.map(j)},stop:function(){n()},replay:function(n){$(n||t,e.patches)},undo:function(e){J(t||t,this.patches)}},n=H(t,function(t){e.patches.push(t)},!0);return e},t.applyAction=W,t.recordActions=function(t){var e={actions:[],stop:function(){return n()},replay:function(t){W(t,e.actions)}},n=I(t,e.actions.push.bind(e.actions));return e},t.protect=function(t){var e=X(t);e.isRoot||i("`protect` can only be invoked on root nodes"),e.isProtectionEnabled=!0},t.unprotect=function(t){var e=X(t);e.isRoot||i("`unprotect` can only be invoked on root nodes"),e.isProtectionEnabled=!1},t.isProtected=function(t){return X(t).isProtected},t.applySnapshot=B,t.getSnapshot=Y,t.hasParent=function(t,e){void 0===e&&(e=1),e<0&&i("Invalid depth: "+e+", should be >= 1");for(var n=X(t).parent;n;){if(0==--e)return!0;n=n.parent}return!1},t.getParent=function(t,e){void 0===e&&(e=1),e<0&&i("Invalid depth: "+e+", should be >= 1");for(var n=e,r=X(t).parent;r;){if(0==--n)return r.storedValue;r=r.parent}return i("Failed to find the parent of "+X(t)+" at depth "+e)},t.getRoot=function(t){return X(t).root.storedValue},t.getPath=function(t){return X(t).path},t.getPathParts=function(t){return T(X(t).path)},t.isRoot=function(t){return X(t).isRoot},t.resolvePath=q,t.resolveIdentifier=function(t,e,n){E(t)||i("Expected a type as first argument");var r=X(e).root.identifierCache.resolve(t,""+n);return r?r.value:void 0},t.tryResolve=G,t.getRelativePath=function(t,e){return X(t).getRelativePathTo(X(e))},t.clone=function(t,e){void 0===e&&(e=!0);var n=X(t);return n.type.create(n.snapshot,!0===e?n.root._environment:!1===e?void 0:e)},t.detach=function(t){return X(t).detach(),t},t.destroy=function(t){var e=X(t);e.isRoot?e.die():e.parent.removeChild(e.subpath)},t.isAlive=function(t){return X(t).isAlive},t.addDisposer=function(t,e){X(t).addDisposer(e)},t.getEnv=function(t){var e=X(t),n=e.root._environment;return n||i("Node '"+e+"' is not part of state tree that was initialized with an environment. Environment can be passed as second argumentt to .create()"),n},t.walk=K,Object.defineProperty(t,"__esModule",{value:!0})}); |
import { IObservableArray } from "mobx"; | ||
import { IType, ISimpleType, IComplexType } from "./type"; | ||
import { IType, ISimpleType, IComplexType, ISnapshottable } from "./type"; | ||
import { TypeFlags } from "./type-flags"; | ||
import { IExtendedObservableMap } from "./complex-types/map"; | ||
import { IModelType } from "./complex-types/object"; | ||
export { IType, TypeFlags }; | ||
export { IType, ISimpleType, IComplexType, IModelType, ISnapshottable, IExtendedObservableMap, TypeFlags }; | ||
export declare const types: { | ||
@@ -8,0 +8,0 @@ model: { |
@@ -16,2 +16,3 @@ import { Type, IType } from "../type"; | ||
isValidSnapshot(value: any, context: IContext): IValidationResult; | ||
isAssignableFrom(type: IType<any, any>): boolean; | ||
} | ||
@@ -18,0 +19,0 @@ export declare function optional<S, T>(type: IType<S, T>, defaultValueOrFunction: S): IType<S, T>; |
{ | ||
"name": "mobx-state-tree", | ||
"version": "0.9.2", | ||
"version": "0.9.3", | ||
"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
398839
7159