mobx-state-tree
Advanced tools
Comparing version 0.10.1 to 0.10.2
@@ -0,8 +1,12 @@ | ||
# 0.10.2 | ||
* Object model instances no longer share a prototype. | ||
# 0.10.1 | ||
Removed accidental dependency on the codemod | ||
* Removed accidental dependency on the codemod | ||
# 0.10.0 | ||
* **BREAKING** the syntax to define model types has been updated. See the [updated docs] (https://github.com/mobxjs/mobx-state-tree#creating-models) or the original proposal:[#282](https://github.com/mobxjs/mobx-state-tree/pull/286), but no worries, theres a codemod! :D | ||
* **BREAKING** the syntax to define model types has been updated. See the [updated docs](https://github.com/mobxjs/mobx-state-tree#creating-models) or the original proposal:[#282](https://github.com/mobxjs/mobx-state-tree/pull/286), but no worries, theres a codemod! :D | ||
* **BREAKING** `preProcessSnapshot` hook is no longer a normal hook that can be defined as action. Instead, it should be defined on the type using `types.model(...).preProcessSnapshot(value => value)` | ||
@@ -9,0 +13,0 @@ * **BREAKING** Asynchronous process should now be defined using `process`. See this [example](https://github.com/mobxjs/mobx-state-tree/blob/adba1943af263898678fe148a80d3d2b9f8dbe63/examples/bookshop/src/stores/BookStore.js#L25) or the [asynchronous action docs](https://github.com/mobxjs/mobx-state-tree/blob/master/docs/async-actions.md). |
@@ -21,3 +21,3 @@ export declare class Node { | ||
applySnapshot: (snapshot: any) => void; | ||
constructor(type: IType<any, any>, parent: Node | null, subpath: string, environment: any, storedValue: any); | ||
constructor(type: IType<any, any>, parent: Node | null, subpath: string, environment: any, initialValue: any, createNewInstance?: (initialValue: any) => any, finalizeNewInstance?: (node: Node, initialValue: any) => void); | ||
readonly identifier: string | null; | ||
@@ -24,0 +24,0 @@ readonly path: string; |
@@ -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}Ct(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]:Tt}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){if(null===t||"object"!=typeof t)return!1;var e=Object.getPrototypeOf(t);return e===Object.prototype||null===e}function l(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 h(t){return f(t)?t:Object.freeze(t)}function d(t){return h(t),c(t)&&Object.keys(t).forEach(function(e){f(t[e])||Object.isFrozen(t[e])||d(t[e])}),t}function y(t){return"function"!=typeof t}function v(t,e,n){Object.defineProperty(t,e,{enumerable:!1,writable:!1,configurable:!0,value:n})}function b(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 g(t,e){return xt.call(t,e)}function w(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 V(t){var e=St({},t);return delete e.oldValue,e}function j(t){return t.replace(/~/g,"~1").replace(/\//g,"~0")}function A(t){return t.replace(/~0/g,"\\").replace(/~1/g,"~")}function C(t){return 0===t.length?"":"/"+t.map(j).join("/")}function S(t){var e=t.split("/").map(A);return""===e[0]?e.slice(1):e}function T(){return Ot++}function x(t,e){var n=et(t.context),r=n._isRunningAction,i=_t;n.assertAlive(),n._isRunningAction=!0,_t=t;try{return I(n,t,e)}finally{_t=i,n._isRunningAction=r}}function O(){return _t||i("Not running an action!")}function _(t,n,r){return e.action(n,function(){var e=T();return x({type:"action",name:n,id:e,args:w(arguments),context:t,rootId:_t?_t.rootId:e},r)})}function N(t){for(var e=t.middlewares.slice(),n=t;n.parent;)n=n.parent,e=e.concat(n.middlewares);return e}function I(t,e,n){function r(t){var o=i.shift();return o?o(t,r):n.apply(e.context,e.args)}var i=N(t);return i.length?r(e):n.apply(e.context,e.args)}function z(t,n,r,i){if(f(i))return i;if(tt(i)){var o=et(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(et(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&&!c(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 D(t,e){if(e&&"object"==typeof e){var n=Object.keys(e);if(1===n.length&&"$ref"===n[0])return Q(t.storedValue,e.$ref)}return e}function E(t,e){var n=X(t,e.path||"");if(!n)return i("Invalid action path: "+(e.path||""));var r=et(n);return"@APPLY_PATCHES"===e.name?J.call(null,n,e.args[0]):"@APPLY_SNAPSHOT"===e.name?q.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 D(r,t)}):[]))}function R(t,e){return K(t)||console.warn("[mobx-state-tree] Warning: Attaching onAction listeners to non root nodes is dangerous: No events will be emitted for actions initiated higher up in the tree."),Y(t)||console.warn("[mobx-state-tree] Warning: Attaching onAction listeners to non protected nodes is dangerous: No events will be emitted for direct modifications without action."),U(t,function(n,r){var i=et(n.context);return"action"===n.type&&n.id===n.rootId&&e({name:n.name,path:et(t).getRelativePathTo(i),args:n.args.map(function(t,e){return z(i,n.name,e,t)})}),r(n)})}function k(t){return"object"==typeof t&&t&&!0===t.isType}function F(t){return k(t)&&(t.flags&(At.String|At.Number|At.Boolean|At.Date))>0}function M(t){return(t.flags&At.Reference)>0}function L(t){return et(t).type}function U(t,e){var n=et(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),et(t).onPatch(e,n)}function $(t,e){return et(t).onSnapshot(e)}function J(t,e){et(t).applyPatches(u(e))}function W(t,e){var n=u(e).map(P);n.reverse(),et(t).applyPatches(n)}function B(t,n){e.runInAction(function(){u(n).forEach(function(e){return E(t,e)})})}function Y(t){return et(t).isProtected}function q(t,e){return et(t).applySnapshot(e)}function G(t){return et(t).snapshot}function K(t){return et(t).isRoot}function Q(t,e){var n=et(t).resolve(e);return n?n.value:void 0}function X(t,e){var n=et(t).resolve(e,!1);if(void 0!==n)return n?n.value:void 0}function Z(t,e){var n=et(t);n.getChildren().forEach(function(t){tt(t.storedValue)&&Z(t.storedValue,e)}),e(n.storedValue)}function tt(t){return!(!t||!t.$treenode)}function et(t){return tt(t)?t.$treenode:i("Value "+t+" is no MST Node")}function nt(t){return t&&"object"==typeof t&&!(t instanceof Date)&&!tt(t)&&!Object.isFrozen(t)}function rt(){return et(this).snapshot}function it(t,e,n,r,s,u,p){if(void 0===u&&(u=o),void 0===p&&(p=a),tt(s)){var c=et(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),f=nt(l),h=new zt(t,e,n,r,l);e||(h.identifierCache=new Nt),f&&v(l,"$treenode",h);var d=!0;try{return f&&b(l,"toJSON",rt),h._isRunningAction=!0,p(h,s),h._isRunningAction=!1,e?e.root.identifierCache.addNodeToCache(h):h.identifierCache.addNodeToCache(h),h.fireHook("afterCreate"),e&&h.fireHook("afterAttach"),d=!1,h}finally{d&&(h._isAlive=!1)}}function ot(t){return"function"==typeof t?"<function"+(t.name?" "+t.name:"")+">":tt(t)?"<"+t+">":"`"+JSON.stringify(t)+"`"}function at(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=tt(e)?"value of type "+et(e).type.name+":":f(e)?"value":"snapshot",a=n&&tt(e)&&n.is(et(e).snapshot);return""+i+o+" "+ot(e)+" is not assignable "+(n?"to type: `"+n.name+"`":"")+(t.message?" ("+t.message+")":"")+(n?F(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 st(t,e,n){return t.concat([{path:e,type:n}])}function ut(){return Tt}function pt(t,e,n){return[{context:t,value:e,message:n}]}function ct(t){return t.reduce(function(t,e){return t.concat(e)},[])}function lt(t,e){var n=t.validate(e,[{path:"",type:t}]);n.length>0&&i("Error while converting "+ot(e)+" to `"+t.name+"`:\n"+n.map(at).join("\n"))}function ft(){return et(this)+"("+this.size+" items)"}function ht(t){t||i("Map.put cannot be used to set empty values");var e;if(tt(t))e=et(t);else{if(!l(t))return i("Map.put can only be used to store complex values");e=et(et(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 dt(){return et(this)+"("+this.length+" items)"}function yt(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(tt(n))(f=et(n)).assertAlive(),f.parent===t?(u[f.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 '"+f.path+"'"),u[f.nodeId]=void 0,f.setParent(t,p),s[r]=f):s[r]=e.instantiate(t,p,void 0,n);else if(l(n)){var c=a(n);if(c){var f=e.reconcile(c,n);u[c.nodeId]=void 0,f.setParent(t,p),s[r]=f}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 vt(t){switch(typeof t){case"string":return Mt;case"number":return Lt;case"boolean":return Ut;case"object":if(t instanceof Date)return Jt}return i("Cannot determine primtive type from value "+t)}function bt(t,e){var n="function"==typeof e?e():e;return lt(t,tt(n)?et(n).snapshot:n),new Bt(t,e)}function mt(t){return f(t)||i("Literal types can be built only on top of primitives"),new qt(t)}function gt(){return et(this).toString()}function wt(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var r=k(t)?null:t,i=k(t)?e.concat(t):e,o=i.map(function(t){return t.name}).join(" | ");return new ne(o,i,r)}function Pt(t,e){return function(){function n(e,n,i){x({name:t,type:n,id:r,args:[i],context:o.context,rootId:o.rootId},e)}var r=T(),o=O(),a=arguments;return new Promise(function(s,u){function p(t,e){void 0===e&&(e=!0);var r;try{e?n(function(t){r=f.next(t)},"process_yield",t):r=f.next(t)}catch(t){return void setImmediate(function(){n(function(e){u(t)},"process_throw",t)})}l(r)}function c(t){var e;try{n(function(t){e=f.throw(t)},"process_yield_error",t)}catch(t){return void setImmediate(function(){n(function(e){u(t)},"process_throw",t)})}l(e)}function l(t){if(!t.done)return t.value&&"function"==typeof t.value.then||i("Only promises can be yielded to `async`, got: "+t),t.value.then(p,c);setImmediate(function(){n(function(t){s(t)},"process_return",t.value)})}var f;x({name:t,type:"process_spawn",id:r,args:w(a),context:o.context,rootId:o.rootId},function(){f=e.apply(null,arguments),p(void 0,!1)})})}}function Vt(t){var e=p({},t);return delete e.type,{name:t.type,args:[e]}}function jt(t,e,n){function r(t){var i=e.shift();i?i(r)(t):n(t)}r(t)}var At,Ct=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])},St=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},Tt=Object.freeze([]),xt=Object.prototype.hasOwnProperty,Ot=1,_t=null;!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",t[t.Null=32768]="Null",t[t.Undefined=65536]="Undefined"}(At||(At={}));var Nt=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}(),It=1,zt=function(){function t(t,n,r,i,o){var a=this;this.nodeId=++It,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=_(this.storedValue,"@APPLY_PATCHES",function(t){t.forEach(function(t){var e=S(t.path);a.resolvePath(e.slice(0,-1)).applyPatchLocally(e[e.length-1],t)})}).bind(this.storedValue),this.applySnapshot=_(this.storedValue,"@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+"/"+j(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=S(this.path),n=S(t.path),r=0;r<e.length&&e[r]===n[r];r++);return e.slice(r).map(function(t){return".."}).join("/")+C(n.slice(r))},t.prototype.resolve=function(t,e){return void 0===e&&(e=!0),this.resolvePath(S(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 '"+C(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||tt(this.storedValue)&&(Z(this.storedValue,function(t){return et(t).aboutToDie()}),Z(this.storedValue,function(t){return et(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;b(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 h(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(V(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}(),Dt=function(){function t(t){this.isType=!0,this.name=t}return t.prototype.create=function(t,e){return void 0===t&&(t=this.getDefaultSnapshot()),lt(this,t),this.instantiate(null,"",e,t).value},t.prototype.isAssignableFrom=function(t){return t===this},t.prototype.validate=function(t,e){return tt(t)?L(t)===this||this.isAssignableFrom(L(t))?ut():pt(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(tt(e)&&et(e)===t)return t;if(t.type===this&&l(e)&&!tt(e)&&(!t.identifierAttribute||t.identifier===e[t.identifierAttribute]))return t.applySnapshot(e),t;var n=t.parent,r=t.subpath;if(t.die(),tt(e)&&this.isAssignableFrom(L(e))){var i=et(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}(),Et=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 Tt},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}(Dt),Rt=function(t){function o(n,r){var i=t.call(this,n)||this;return i.shouldAttachNode=!0,i.flags=At.Map,i.createNewInstance=function(){var t=e.observable.shallowMap();return v(t,"put",ht),v(t,"toString",ft),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 it(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=et(t.object);switch(e.assertWritable(),t.type){case"update":var n=t.newValue;if(n===t.object.get(t.name))return null;lt(this.subType,n),t.newValue=this.subType.reconcile(e.getChildNode(t.name),t.newValue),this.verifyIdentifier(t.name,t.newValue);break;case"add":lt(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=et(t.object);switch(t.type){case"update":return void e.emitPatch({op:"replace",path:j(t.name),value:t.newValue.snapshot,oldValue:t.oldValue?t.oldValue.snapshot:void 0},e);case"add":return void e.emitPatch({op:"add",path:j(t.name),value:t.newValue.snapshot,oldValue:void 0},e);case"delete":return void e.emitPatch({op:"remove",path:j(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){lt(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 c(t)?ct(Object.keys(t).map(function(r){return n.subType.validate(t[r],st(e,r,n.subType))})):pt(e,t,"Value is not a plain object")},o.prototype.getDefaultSnapshot=function(){return{}},o.prototype.removeChild=function(t,e){t.storedValue.delete(e)},r([e.action],o.prototype,"applySnapshot",null),o}(Dt),kt=function(t){function o(n,r){var i=t.call(this,n)||this;return i.shouldAttachNode=!0,i.flags=At.Array,i.createNewInstance=function(){var t=e.observable.shallowArray();return v(t,"toString",dt),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 it(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=et(t.object);e.assertWritable();var n=e.getChildren();switch(t.type){case"update":if(t.newValue===t.object[t.index])return null;t.newValue=yt(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=yt(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=et(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){lt(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)?ct(t.map(function(t,r){return n.subType.validate(t,st(e,""+r,n.subType))})):pt(e,t,"Value is not an array")},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}(Dt),Ft=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 it(this,t,e,n,r,this.initializer)},e.prototype.isValidSnapshot=function(t,e){return f(t)&&this.checker(t)?ut():pt(e,t,"Value is not a "+("Date"===this.name?"Date or a unix milliseconds timestamp":this.name))},e}(Et),Mt=new Ft("string",At.String,function(t){return"string"==typeof t}),Lt=new Ft("number",At.Number,function(t){return"number"==typeof t}),Ut=new Ft("boolean",At.Boolean,function(t){return"boolean"==typeof t}),Ht=new Ft("null",At.Null,function(t){return null===t}),$t=new Ft("undefined",At.Undefined,function(t){return void 0===t}),Jt=new Ft("Date",At.Date,function(t){return"number"==typeof t||t instanceof Date},function(t){return t instanceof Date?t:new Date(t)});Jt.getSnapshot=function(t){return t.storedValue.getTime()};var Wt=function(t){function e(e){var n=t.call(this,"identifier("+e.name+")")||this;return n.identifierType=e,n.flags=At.Identifier,n}return n(e,t),e.prototype.instantiate=function(t,e,n,r){return t&&tt(t.storedValue)?(t.identifierAttribute&&i("Cannot define property '"+e+"' as object identifier, property '"+t.identifierAttribute+"' is already defined as identifier property"),t.identifierAttribute=e,it(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):pt(e,t,"Value is not a valid identifier, which is a string or a number")},e}(Et),Bt=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|At.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=tt(i)?et(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&<(this,t),t},e.prototype.isValidSnapshot=function(t,e){return void 0===t?ut():this.type.validate(t,e)},e.prototype.isAssignableFrom=function(t){return this.type.isAssignableFrom(t)},e}(Et),Yt=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}(),qt=function(t){function e(e){var n=t.call(this,JSON.stringify(e))||this;return n.flags=At.Literal,n.value=e,n}return n(e,t),e.prototype.instantiate=function(t,e,n,r){return it(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?ut():pt(e,t,"Value is not a literal "+JSON.stringify(this.value))},e}(Et),Gt=mt(void 0),Kt=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:Gt.instantiate(null,"",null,void 0)})},r.prototype.initialize=function(t,n){var r=et(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=et(t.object);return lt(this.type,t.newValue),t.newValue=this.type.reconcile(e.getChildNode(t.name),t.newValue),t},r.prototype.didChange=function(t){var e=et(t.object);e.emitPatch({op:"replace",path:j(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],st(e,this.name,this.type))},r}(Yt),Qt=["afterCreate","afterAttach","postProcessSnapshot","beforeDetach","beforeDestroy"],Xt={name:"AnonymousModel",properties:{},initializers:Tt},Zt=function(t){function o(n){var r=t.call(this,n.name||Xt.name)||this;r.flags=At.Object,r.parsedProperties={},r.createNewInstance=function(){var t=new r.modelConstructor;return e.extendShallowObservable(t,{}),t},r.finalizeNewInstance=function(t,n){var i=t.storedValue;r.forAllProps(function(t){return t.initialize(i,n)}),r.initializers.reduce(function(t,e){return e(t)},i),e.intercept(i,function(t){return r.willChange(t)}),e.observe(i,r.didChange)},r.didChange=function(t){r.parsedProperties[t.name].didChange(t)};var o=n.name||Xt.name;return/^\w[\w\d_]*$/.test(o)||i("Typename should be a valid identifier: "+o),Object.assign(r,Xt,n),Object.freeze(r.properties),r.createModelConstructor(),r}return n(o,t),o.prototype.extend=function(t){return new o({name:t.name||this.name,properties:Object.assign({},this.properties,t.properties),initializers:this.initializers.concat(t.initializers||[]),preProcessor:t.preProcessor||this.preProcessor})},o.prototype.createModelConstructor=function(){var t=this;this.modelConstructor=function(){return function(){}}(),Object.defineProperty(this.modelConstructor,"name",{value:this.name,writable:!1}),this.modelConstructor.prototype.toString=gt,this.parseModelProps(),this.forAllProps(function(e){return e.initializePrototype(t.modelConstructor.prototype)})},o.prototype.actions=function(t){return this.extend({initializers:[function(e){var n=t(e);return c(n)||i("actions initializer should return a plain object containing actions"),Object.keys(n).forEach(function(t){"preProcessSnapshot"===t&&i("Cannot define action 'preProcessSnapshot', it should be defined using 'type.preProcessSnapshot(fn)' instead"),v(e,t,_(e,t,n[t]))}),e}]})},o.prototype.named=function(t){return this.extend({name:t})},o.prototype.props=function(t){return this.extend({properties:t})},o.prototype.views=function(t){return this.extend({initializers:[function(n){var r=t(n);return Object.keys(r).forEach(function(t){var o=Object.getOwnPropertyDescriptor(r,t),a=o.value;if("get"in o)if(e.isComputed(n.$mobx.values[t]))n.$mobx.values[t]=e.computed(o.get,{name:t,setter:o.set,context:n});else{var s={};Object.defineProperty(s,t,{get:o.get,set:o.set,enumerable:!0}),e.extendShallowObservable(n,s)}else"function"==typeof a?v(n,t,a):i("A view member should either be a function or getter based property")}),n}]})},o.prototype.preProcessSnapshot=function(t){return this.extend({preProcessor:t})},o.prototype.instantiate=function(t,e,n,r){return it(this,t,e,n,this.applySnapshotPreProcessor(r),this.createNewInstance,this.finalizeNewInstance)},o.prototype.willChange=function(t){return et(t.object).assertWritable(),this.parsedProperties[t.name].willChange(t)},o.prototype.parseModelProps=function(){var t=this.properties;for(var e in t)if(g(t,e)){-1!==Qt.indexOf(e)&&console.warn("Hook '"+e+"' was defined as property. Hooks should be defined as part of the actions");var n=Object.getOwnPropertyDescriptor(t,e);"get"in n&&i("Getters are not supported as properties. Please use views instead");var r=n.value;if(null===r)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(r)){var o=vt(r);this.parsedProperties[e]=new Kt(e,bt(o,r))}else k(r)?this.parsedProperties[e]=new Kt(e,r):i("function"==typeof r?"Functions are not supported as properties, use views instead":"object"==typeof r?"In property '"+e+"': base model's should not contain complex values: '"+r+"'":"Unexpected value for property '"+e+"'")}},o.prototype.getChildren=function(t){var e=[];return this.forAllProps(function(n){n instanceof Kt&&e.push(n.getValueNode(t.storedValue))}),e},o.prototype.getChildNode=function(t,e){return this.parsedProperties[e]instanceof Kt?this.parsedProperties[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)}),"function"==typeof t.storedValue.postProcessSnapshot?t.storedValue.postProcessSnapshot.call(null,e):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.applySnapshotPreProcessor(e);lt(this,n),this.forAllProps(function(e){e.deserialize(t.storedValue,n)})},o.prototype.applySnapshotPreProcessor=function(t){return this.preProcessor?this.preProcessor.call(null,t):t},o.prototype.getChildType=function(t){return this.parsedProperties[t].type},o.prototype.isValidSnapshot=function(t,e){var n=this,r=this.applySnapshotPreProcessor(t);return c(r)?ct(Object.keys(this.parsedProperties).map(function(t){return n.parsedProperties[t].validate(r,e)})):pt(e,r,"Value is not a plain object")},o.prototype.forAllProps=function(t){var e=this;Object.keys(this.parsedProperties).forEach(function(n){return t(e.parsedProperties[n])})},o.prototype.describe=function(){var t=this;return"{ "+Object.keys(this.parsedProperties).map(function(e){var n=t.parsedProperties[e];return n instanceof Kt?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}(Dt),te=function(){return function(t,e){if(this.mode=t,this.value=e,"object"===t){if(!tt(e))return i("Can only store references to tree nodes, got: '"+e+"'");if(!et(e).identifierAttribute)return i("Can only store references with a defined identifier attribute.")}}}(),ee=function(t){function e(e){var n=t.call(this,"reference("+e.name+")")||this;return n.targetType=e,n.flags=At.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 et(e.value).identifier}},e.prototype.instantiate=function(t,e,n,r){var i=tt(r);return it(this,t,e,n,new te(i?"object":"identifier",r))},e.prototype.reconcile=function(t,e){var n=tt(e)?"object":"identifier";if(M(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?ut():pt(e,t,"Value is not a valid identifier, which is a string or a number")},e}(Et),ne=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=At.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?pt(e,t,"Multiple types are applicable for the union (hint: provide a dispatch function)"):0===r.length?pt(e,t,"No type is applicable for the union").concat(ct(n)):ut()},e}(Et),re=new(function(t){function e(){var e=t.call(this,"frozen")||this;return e.flags=At.Frozen,e}return n(e,t),e.prototype.describe=function(){return"<any immutable value>"},e.prototype.instantiate=function(t,e,n,r){return it(this,t,e,n,d(r))},e.prototype.isValidSnapshot=function(t,e){return y(t)?ut():pt(e,t,"Value is not serializable and cannot be frozen")},e}(Et)),ie=bt(Ht,null),oe=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|At.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){var n=this.type.validate(t,e);if(n.length>0)return n;var r=tt(t)?et(t).snapshot:t;return this.predicate(r)?ut():pt(e,t,"Value does not respect the refinement predicate")},e}(Et),ae=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|At.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}(Et),se={enumeration:function(t,e){var n="string"==typeof t?e:t,r=wt.apply(void 0,n.map(function(t){return mt(""+t)}));return"string"==typeof t&&(r.name=t),r},model:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n="string"==typeof t[0]?t.shift():"AnonymousModel",r=t.shift()||{};return new Zt({name:n,properties:r})},compose:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n="string"==typeof t[0]?t.shift():"AnonymousModel";return t.reduce(function(t,e){return t.extend({name:t.name+"_"+e.name,properties:e.properties,initializers:e.initializers})}).named(n)},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 ee(t)},union:wt,optional:bt,literal:mt,maybe:function(t){return t===re&&i("Unable to declare `types.maybe(types.frozen)`. Frozen already accepts `null`. Consider using `types.optional(types.frozen, null)` instead."),wt(ie,t)},refinement:function(t,e,n){return new oe(t,e,n)},string:Mt,boolean:Ut,number:Lt,Date:Jt,map:function(t){return new Rt("map<string, "+t.name+">",t)},array:function(t){return new kt(t.name+"[]",t)},frozen:re,identifier:function(t){return void 0===t&&(t=Mt),new Wt(t)},late:function(t,e){var n="string"==typeof t?t:"late("+t.toString()+")";return new ae(n,"string"==typeof t?e:t)},undefined:$t,null:Ht};t.types=se,t.escapeJsonPath=j,t.unescapeJsonPath=A,t.onAction=R,t.process=function(t){return Pt(t.name,t)},t.isStateTreeNode=tt,t.asReduxStore=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];tt(t)||i("Expected model object");var r={getState:function(){return G(t)},dispatch:function(e){jt(e,o.slice(),function(e){return E(t,Vt(e))})},subscribe:function(e){return $(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,q(e,i),r=!1)}),R(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,G(e))}})},t.getType=L,t.getChildType=function(t,e){return et(t).getChildType(e)},t.addMiddleware=U,t.onPatch=H,t.onSnapshot=$,t.applyPatch=J,t.revertPatch=W,t.recordPatches=function(t){var e={patches:[],get cleanPatches(){return this.patches.map(V)},stop:function(){n()},replay:function(n){J(n||t,e.patches)},undo:function(e){W(t||t,this.patches)}},n=H(t,function(t){e.patches.push(t)},!0);return e},t.applyAction=B,t.recordActions=function(t){var e={actions:[],stop:function(){return n()},replay:function(t){B(t,e.actions)}},n=R(t,e.actions.push.bind(e.actions));return e},t.protect=function(t){var e=et(t);e.isRoot||i("`protect` can only be invoked on root nodes"),e.isProtectionEnabled=!0},t.unprotect=function(t){var e=et(t);e.isRoot||i("`unprotect` can only be invoked on root nodes"),e.isProtectionEnabled=!1},t.isProtected=Y,t.applySnapshot=q,t.getSnapshot=G,t.hasParent=function(t,e){void 0===e&&(e=1),e<0&&i("Invalid depth: "+e+", should be >= 1");for(var n=et(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=et(t).parent;r;){if(0==--n)return r.storedValue;r=r.parent}return i("Failed to find the parent of "+et(t)+" at depth "+e)},t.getRoot=function(t){return et(t).root.storedValue},t.getPath=function(t){return et(t).path},t.getPathParts=function(t){return S(et(t).path)},t.isRoot=K,t.resolvePath=Q,t.resolveIdentifier=function(t,e,n){k(t)||i("Expected a type as first argument");var r=et(e).root.identifierCache.resolve(t,""+n);return r?r.value:void 0},t.tryResolve=X,t.getRelativePath=function(t,e){return et(t).getRelativePathTo(et(e))},t.clone=function(t,e){void 0===e&&(e=!0);var n=et(t);return n.type.create(n.snapshot,!0===e?n.root._environment:!1===e?void 0:e)},t.detach=function(t){return et(t).detach(),t},t.destroy=function(t){var e=et(t);e.isRoot?e.die():e.parent.removeChild(e.subpath)},t.isAlive=function(t){return et(t).isAlive},t.addDisposer=function(t,e){et(t).addDisposer(e)},t.getEnv=function(t){var e=et(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=Z,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}St(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]:Tt}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){if(null===t||"object"!=typeof t)return!1;var e=Object.getPrototypeOf(t);return e===Object.prototype||null===e}function l(t){return!(null===t||"object"!=typeof t||t instanceof Date||t instanceof RegExp)}function h(t){return null===t||void 0===t||("string"==typeof t||"number"==typeof t||"boolean"==typeof t||t instanceof Date)}function f(t){return h(t)?t:Object.freeze(t)}function d(t){return f(t),c(t)&&Object.keys(t).forEach(function(e){h(t[e])||Object.isFrozen(t[e])||d(t[e])}),t}function y(t){return"function"!=typeof t}function v(t,e,n){Object.defineProperty(t,e,{enumerable:!1,writable:!1,configurable:!0,value:n})}function b(t,e,n){Object.defineProperty(t,e,{enumerable:!0,writable:!1,configurable:!0,value:n})}function g(t,e){return t.push(e),function(){var n=t.indexOf(e);-1!==n&&t.splice(n,1)}}function m(t){for(var e=new Array(t.length),n=0;n<t.length;n++)e[n]=t[n];return e}function w(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 V(t){var e=Ct({},t);return delete e.oldValue,e}function P(t){return t.replace(/~/g,"~1").replace(/\//g,"~0")}function j(t){return t.replace(/~0/g,"\\").replace(/~1/g,"~")}function A(t){return 0===t.length?"":"/"+t.map(P).join("/")}function S(t){var e=t.split("/").map(j);return""===e[0]?e.slice(1):e}function C(){return Ot++}function T(t,e){var n=tt(t.context),r=n._isRunningAction,i=_t;n.assertAlive(),n._isRunningAction=!0,_t=t;try{return N(n,t,e)}finally{_t=i,n._isRunningAction=r}}function x(){return _t||i("Not running an action!")}function O(t,n,r){return e.action(n,function(){var e=C();return T({type:"action",name:n,id:e,args:m(arguments),context:t,rootId:_t?_t.rootId:e},r)})}function _(t){for(var e=t.middlewares.slice(),n=t;n.parent;)n=n.parent,e=e.concat(n.middlewares);return e}function N(t,e,n){function r(t){var o=i.shift();return o?o(t,r):n.apply(e.context,e.args)}var i=_(t);return i.length?r(e):n.apply(e.context,e.args)}function I(t,n,r,i){if(h(i))return i;if(Z(i)){var o=tt(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(tt(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&&!c(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 D(t,e){if(e&&"object"==typeof e){var n=Object.keys(e);if(1===n.length&&"$ref"===n[0])return K(t.storedValue,e.$ref)}return e}function E(t,e){var n=Q(t,e.path||"");if(!n)return i("Invalid action path: "+(e.path||""));var r=tt(n);return"@APPLY_PATCHES"===e.name?$.call(null,n,e.args[0]):"@APPLY_SNAPSHOT"===e.name?Y.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 D(r,t)}):[]))}function z(t,e){return G(t)||console.warn("[mobx-state-tree] Warning: Attaching onAction listeners to non root nodes is dangerous: No events will be emitted for actions initiated higher up in the tree."),B(t)||console.warn("[mobx-state-tree] Warning: Attaching onAction listeners to non protected nodes is dangerous: No events will be emitted for direct modifications without action."),M(t,function(n,r){var i=tt(n.context);return"action"===n.type&&n.id===n.rootId&&e({name:n.name,path:tt(t).getRelativePathTo(i),args:n.args.map(function(t,e){return I(i,n.name,e,t)})}),r(n)})}function R(t){return"object"==typeof t&&t&&!0===t.isType}function k(t){return R(t)&&(t.flags&(At.String|At.Number|At.Boolean|At.Date))>0}function F(t){return(t.flags&At.Reference)>0}function L(t){return tt(t).type}function M(t,e){var n=tt(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 U(t,e,n){return void 0===n&&(n=!1),tt(t).onPatch(e,n)}function H(t,e){return tt(t).onSnapshot(e)}function $(t,e){tt(t).applyPatches(u(e))}function J(t,e){var n=u(e).map(w);n.reverse(),tt(t).applyPatches(n)}function W(t,n){e.runInAction(function(){u(n).forEach(function(e){return E(t,e)})})}function B(t){return tt(t).isProtected}function Y(t,e){return tt(t).applySnapshot(e)}function q(t){return tt(t).snapshot}function G(t){return tt(t).isRoot}function K(t,e){var n=tt(t).resolve(e);return n?n.value:void 0}function Q(t,e){var n=tt(t).resolve(e,!1);if(void 0!==n)return n?n.value:void 0}function X(t,e){var n=tt(t);n.getChildren().forEach(function(t){Z(t.storedValue)&&X(t.storedValue,e)}),e(n.storedValue)}function Z(t){return!(!t||!t.$treenode)}function tt(t){return Z(t)?t.$treenode:i("Value "+t+" is no MST Node")}function et(t){return t&&"object"==typeof t&&!(t instanceof Date)&&!Z(t)&&!Object.isFrozen(t)}function nt(){return tt(this).snapshot}function rt(t,e,n,r,s,u,p){if(void 0===u&&(u=o),void 0===p&&(p=a),Z(s)){var c=tt(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}return new Dt(t,e,n,r,s,u,p)}function it(t){return"function"==typeof t?"<function"+(t.name?" "+t.name:"")+">":Z(t)?"<"+t+">":"`"+JSON.stringify(t)+"`"}function ot(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=Z(e)?"value of type "+tt(e).type.name+":":h(e)?"value":"snapshot",a=n&&Z(e)&&n.is(tt(e).snapshot);return""+i+o+" "+it(e)+" is not assignable "+(n?"to type: `"+n.name+"`":"")+(t.message?" ("+t.message+")":"")+(n?k(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 at(t,e,n){return t.concat([{path:e,type:n}])}function st(){return Tt}function ut(t,e,n){return[{context:t,value:e,message:n}]}function pt(t){return t.reduce(function(t,e){return t.concat(e)},[])}function ct(t,e){var n=t.validate(e,[{path:"",type:t}]);n.length>0&&i("Error while converting "+it(e)+" to `"+t.name+"`:\n"+n.map(ot).join("\n"))}function lt(){return tt(this)+"("+this.size+" items)"}function ht(t){t||i("Map.put cannot be used to set empty values");var e;if(Z(t))e=tt(t);else{if(!l(t))return i("Map.put can only be used to store complex values");e=tt(tt(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 ft(){return tt(this)+"("+this.length+" items)"}function dt(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(Z(n))(h=tt(n)).assertAlive(),h.parent===t?(u[h.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 '"+h.path+"'"),u[h.nodeId]=void 0,h.setParent(t,p),s[r]=h):s[r]=e.instantiate(t,p,void 0,n);else if(l(n)){var c=a(n);if(c){var h=e.reconcile(c,n);u[c.nodeId]=void 0,h.setParent(t,p),s[r]=h}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 yt(t){switch(typeof t){case"string":return Lt;case"number":return Mt;case"boolean":return Ut;case"object":if(t instanceof Date)return Jt}return i("Cannot determine primtive type from value "+t)}function vt(t,e){var n="function"==typeof e?e():e;return ct(t,Z(n)?tt(n).snapshot:n),new Bt(t,e)}function bt(){return tt(this).toString()}function gt(t){return Object.keys(t).reduce(function(t,e){-1!==Yt.indexOf(e)&&console.warn("Hook '"+e+"' was defined as property. Hooks should be defined as part of the actions");var n=Object.getOwnPropertyDescriptor(t,e);"get"in n&&i("Getters are not supported as properties. Please use views instead");var r=n.value;if(null===r)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(h(r))return Object.assign({},t,(o={},o[e]=vt(yt(r),r),o));if(R(r))return t;i("function"==typeof r?"Functions are not supported as properties, use views instead":"object"==typeof r?"In property '"+e+"': base model's should not contain complex values: '"+r+"'":"Unexpected value for property '"+e+"'")}var o},t)}function mt(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var r=R(t)?null:t,i=R(t)?e.concat(t):e,o=i.map(function(t){return t.name}).join(" | ");return new Xt(o,i,r)}function wt(t){return h(t)||i("Literal types can be built only on top of primitives"),new Zt(t)}function Vt(t,e){return function(){function n(e,n,i){T({name:t,type:n,id:r,args:[i],context:o.context,rootId:o.rootId},e)}var r=C(),o=x(),a=arguments;return new Promise(function(s,u){function p(t,e){void 0===e&&(e=!0);var r;try{e?n(function(t){r=h.next(t)},"process_yield",t):r=h.next(t)}catch(t){return void setImmediate(function(){n(function(e){u(t)},"process_throw",t)})}l(r)}function c(t){var e;try{n(function(t){e=h.throw(t)},"process_yield_error",t)}catch(t){return void setImmediate(function(){n(function(e){u(t)},"process_throw",t)})}l(e)}function l(t){if(!t.done)return t.value&&"function"==typeof t.value.then||i("Only promises can be yielded to `async`, got: "+t),t.value.then(p,c);setImmediate(function(){n(function(t){s(t)},"process_return",t.value)})}var h;T({name:t,type:"process_spawn",id:r,args:m(a),context:o.context,rootId:o.rootId},function(){h=e.apply(null,arguments),p(void 0,!1)})})}}function Pt(t){var e=p({},t);return delete e.type,{name:t.type,args:[e]}}function jt(t,e,n){function r(t){var i=e.shift();i?i(r)(t):n(t)}r(t)}var At,St=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},Tt=Object.freeze([]),xt=Object.freeze({}),Ot=1,_t=null;!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",t[t.Null=32768]="Null",t[t.Undefined=65536]="Undefined"}(At||(At={}));var Nt=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}(),It=1,Dt=function(){function t(t,n,r,i,s,u,p){void 0===u&&(u=o),void 0===p&&(p=a);var c=this;this.nodeId=++It,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._environment=i,this.unbox=this.unbox.bind(this),this.storedValue=u(s);var l=et(this.storedValue);this.applyPatches=O(this.storedValue,"@APPLY_PATCHES",function(t){t.forEach(function(t){var e=S(t.path);c.resolvePath(e.slice(0,-1)).applyPatchLocally(e[e.length-1],t)})}).bind(this.storedValue),this.applySnapshot=O(this.storedValue,"@APPLY_SNAPSHOT",function(t){if(t!==c.snapshot)return c.type.applySnapshot(c,t)}).bind(this.storedValue),n||(this.identifierCache=new Nt),l&&v(this.storedValue,"$treenode",this);var h=!0;try{l&&v(this.storedValue,"toJSON",nt),this._isRunningAction=!0,p(this,s),this._isRunningAction=!1,n?n.root.identifierCache.addNodeToCache(this):this.identifierCache.addNodeToCache(this),this.fireHook("afterCreate"),n&&this.fireHook("afterAttach"),h=!1}finally{h&&(this._isAlive=!1)}var f=e.reaction(function(){return c.snapshot},function(t){c.emitSnapshot(t)});f.onError(function(t){throw t}),this.addDisposer(f)}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+"/"+P(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=S(this.path),n=S(t.path),r=0;r<e.length&&e[r]===n[r];r++);return e.slice(r).map(function(t){return".."}).join("/")+A(n.slice(r))},t.prototype.resolve=function(t,e){return void 0===e&&(e=!0),this.resolvePath(S(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 '"+A(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||Z(this.storedValue)&&(X(this.storedValue,function(t){return tt(t).aboutToDie()}),X(this.storedValue,function(t){return tt(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;b(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 f(this.type.getSnapshot(this))},enumerable:!0,configurable:!0}),t.prototype.onSnapshot=function(t){return g(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 g(this.patchSubscribers,e?t:function(e){return t(V(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 g(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}(),Et=function(){function t(t){this.isType=!0,this.name=t}return t.prototype.create=function(t,e){return void 0===t&&(t=this.getDefaultSnapshot()),ct(this,t),this.instantiate(null,"",e,t).value},t.prototype.isAssignableFrom=function(t){return t===this},t.prototype.validate=function(t,e){return Z(t)?L(t)===this||this.isAssignableFrom(L(t))?st():ut(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(Z(e)&&tt(e)===t)return t;if(t.type===this&&l(e)&&!Z(e)&&(!t.identifierAttribute||t.identifier===e[t.identifierAttribute]))return t.applySnapshot(e),t;var n=t.parent,r=t.subpath;if(t.die(),Z(e)&&this.isAssignableFrom(L(e))){var i=tt(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 Tt},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}(Et),Rt=function(t){function o(n,r){var i=t.call(this,n)||this;return i.shouldAttachNode=!0,i.flags=At.Map,i.createNewInstance=function(){var t=e.observable.shallowMap();return v(t,"put",ht),v(t,"toString",lt),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 rt(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=tt(t.object);switch(e.assertWritable(),t.type){case"update":var n=t.newValue;if(n===t.object.get(t.name))return null;ct(this.subType,n),t.newValue=this.subType.reconcile(e.getChildNode(t.name),t.newValue),this.verifyIdentifier(t.name,t.newValue);break;case"add":ct(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=tt(t.object);switch(t.type){case"update":return void e.emitPatch({op:"replace",path:P(t.name),value:t.newValue.snapshot,oldValue:t.oldValue?t.oldValue.snapshot:void 0},e);case"add":return void e.emitPatch({op:"add",path:P(t.name),value:t.newValue.snapshot,oldValue:void 0},e);case"delete":return void e.emitPatch({op:"remove",path:P(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){ct(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 c(t)?pt(Object.keys(t).map(function(r){return n.subType.validate(t[r],at(e,r,n.subType))})):ut(e,t,"Value is not a plain object")},o.prototype.getDefaultSnapshot=function(){return{}},o.prototype.removeChild=function(t,e){t.storedValue.delete(e)},r([e.action],o.prototype,"applySnapshot",null),o}(Et),kt=function(t){function o(n,r){var i=t.call(this,n)||this;return i.shouldAttachNode=!0,i.flags=At.Array,i.createNewInstance=function(){var t=e.observable.shallowArray();return v(t,"toString",ft),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 rt(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=tt(t.object);e.assertWritable();var n=e.getChildren();switch(t.type){case"update":if(t.newValue===t.object[t.index])return null;t.newValue=dt(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=dt(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=tt(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){ct(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)?pt(t.map(function(t,r){return n.subType.validate(t,at(e,""+r,n.subType))})):ut(e,t,"Value is not an array")},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}(Et),Ft=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 rt(this,t,e,n,r,this.initializer)},e.prototype.isValidSnapshot=function(t,e){return h(t)&&this.checker(t)?st():ut(e,t,"Value is not a "+("Date"===this.name?"Date or a unix milliseconds timestamp":this.name))},e}(zt),Lt=new Ft("string",At.String,function(t){return"string"==typeof t}),Mt=new Ft("number",At.Number,function(t){return"number"==typeof t}),Ut=new Ft("boolean",At.Boolean,function(t){return"boolean"==typeof t}),Ht=new Ft("null",At.Null,function(t){return null===t}),$t=new Ft("undefined",At.Undefined,function(t){return void 0===t}),Jt=new Ft("Date",At.Date,function(t){return"number"==typeof t||t instanceof Date},function(t){return t instanceof Date?t:new Date(t)});Jt.getSnapshot=function(t){return t.storedValue.getTime()};var Wt=function(t){function e(e){var n=t.call(this,"identifier("+e.name+")")||this;return n.identifierType=e,n.flags=At.Identifier,n}return n(e,t),e.prototype.instantiate=function(t,e,n,r){return t&&Z(t.storedValue)?(t.identifierAttribute&&i("Cannot define property '"+e+"' as object identifier, property '"+t.identifierAttribute+"' is already defined as identifier property"),t.identifierAttribute=e,rt(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):ut(e,t,"Value is not a valid identifier, which is a string or a number")},e}(zt),Bt=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|At.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=Z(i)?tt(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&&ct(this,t),t},e.prototype.isValidSnapshot=function(t,e){return void 0===t?st():this.type.validate(t,e)},e.prototype.isAssignableFrom=function(t){return this.type.isAssignableFrom(t)},e}(zt),Yt=["afterCreate","afterAttach","postProcessSnapshot","beforeDetach","beforeDestroy"],qt={name:"AnonymousModel",properties:{},initializers:Tt},Gt=function(t){function o(n){var r=t.call(this,n.name||qt.name)||this;r.flags=At.Object,r.createNewInstance=function(){var t=e.observable.shallowObject(xt);return v(t,"toString",bt),t},r.finalizeNewInstance=function(t,n){var i=t.storedValue;r.forAllProps(function(r,o){e.extendShallowObservable(i,(a={},a[r]=e.observable.ref(o.instantiate(t,r,t._environment,n[r])),a)),e.extras.interceptReads(t.storedValue,r,t.unbox);var a}),r.initializers.reduce(function(t,e){return e(t)},i),e.intercept(i,function(t){return r.willChange(t)}),e.observe(i,r.didChange)},r.didChange=function(t){var e=tt(t.object);e.emitPatch({op:"replace",path:P(t.name),value:t.newValue.snapshot,oldValue:t.oldValue?t.oldValue.snapshot:void 0},e)};var o=n.name||qt.name;return/^\w[\w\d_]*$/.test(o)||i("Typename should be a valid identifier: "+o),Object.assign(r,qt,n),r.properties=gt(r.properties),r.propertiesNames=Object.keys(r.properties),Object.freeze(r.properties),r}return n(o,t),o.prototype.extend=function(t){return new o({name:t.name||this.name,properties:Object.assign({},this.properties,t.properties),initializers:this.initializers.concat(t.initializers||[]),preProcessor:t.preProcessor||this.preProcessor})},o.prototype.actions=function(t){return this.extend({initializers:[function(e){var n=t(e);return c(n)||i("actions initializer should return a plain object containing actions"),Object.keys(n).forEach(function(t){"preProcessSnapshot"===t&&i("Cannot define action 'preProcessSnapshot', it should be defined using 'type.preProcessSnapshot(fn)' instead"),v(e,t,O(e,t,n[t]))}),e}]})},o.prototype.named=function(t){return this.extend({name:t})},o.prototype.props=function(t){return this.extend({properties:t})},o.prototype.views=function(t){return this.extend({initializers:[function(n){var r=t(n);return c(r)||i("views initializer should return a plain object containing views"),Object.keys(r).forEach(function(t){var o=Object.getOwnPropertyDescriptor(r,t),a=o.value;if("get"in o)if(e.isComputed(n.$mobx.values[t]))n.$mobx.values[t]=e.computed(o.get,{name:t,setter:o.set,context:n});else{var s={};Object.defineProperty(s,t,{get:o.get,set:o.set,enumerable:!0}),e.extendShallowObservable(n,s)}else"function"==typeof a?v(n,t,a):i("A view member should either be a function or getter based property")}),n}]})},o.prototype.preProcessSnapshot=function(t){return this.extend({preProcessor:t})},o.prototype.instantiate=function(t,e,n,r){return rt(this,t,e,n,this.applySnapshotPreProcessor(r),this.createNewInstance,this.finalizeNewInstance)},o.prototype.willChange=function(t){var e=tt(t.object),n=this.properties[t.name];return e.assertWritable(),ct(n,t.newValue),t.newValue=n.reconcile(e.getChildNode(t.name),t.newValue),t},o.prototype.getChildren=function(t){var e=this,n=[];return this.forAllProps(function(r,i){n.push(e.getChildNode(t,r))}),n},o.prototype.getChildNode=function(t,e){if(!(e in this.properties))return i("Not a value property: "+e);var n=t.storedValue.$mobx.values[e].value;return n||i("Node not available for property "+e)},o.prototype.getValue=function(t){return t.storedValue},o.prototype.getSnapshot=function(t){var n=this,r={};return this.forAllProps(function(i,o){e.extras.getAtom(t.storedValue,i).reportObserved(),r[i]=n.getChildNode(t,i).snapshot}),"function"==typeof t.storedValue.postProcessSnapshot?t.storedValue.postProcessSnapshot.call(null,r):r},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.applySnapshotPreProcessor(e);ct(this,n),this.forAllProps(function(e,r){t.storedValue[e]=n[e]})},o.prototype.applySnapshotPreProcessor=function(t){return this.preProcessor?this.preProcessor.call(null,t):t},o.prototype.getChildType=function(t){return this.properties[t]},o.prototype.isValidSnapshot=function(t,e){var n=this,r=this.applySnapshotPreProcessor(t);return c(r)?pt(this.propertiesNames.map(function(t){return n.properties[t].validate(r[t],at(e,t,n.properties[t]))})):ut(e,r,"Value is not a plain object")},o.prototype.forAllProps=function(t){var e=this;this.propertiesNames.forEach(function(n){return t(n,e.properties[n])})},o.prototype.describe=function(){var t=this;return"{ "+this.propertiesNames.map(function(e){return e+": "+t.properties[e].describe()}).join("; ")+" }"},o.prototype.getDefaultSnapshot=function(){return{}},o.prototype.removeChild=function(t,e){t.storedValue[e]=null},r([e.action],o.prototype,"applySnapshot",null),o}(Et),Kt=function(){return function(t,e){if(this.mode=t,this.value=e,"object"===t){if(!Z(e))return i("Can only store references to tree nodes, got: '"+e+"'");if(!tt(e).identifierAttribute)return i("Can only store references with a defined identifier attribute.")}}}(),Qt=function(t){function e(e){var n=t.call(this,"reference("+e.name+")")||this;return n.targetType=e,n.flags=At.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 tt(e.value).identifier}},e.prototype.instantiate=function(t,e,n,r){var i=Z(r);return rt(this,t,e,n,new Kt(i?"object":"identifier",r))},e.prototype.reconcile=function(t,e){var n=Z(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?st():ut(e,t,"Value is not a valid identifier, which is a string or a number")},e}(zt),Xt=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=At.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?ut(e,t,"Multiple types are applicable for the union (hint: provide a dispatch function)"):0===r.length?ut(e,t,"No type is applicable for the union").concat(pt(n)):st()},e}(zt),Zt=function(t){function e(e){var n=t.call(this,JSON.stringify(e))||this;return n.flags=At.Literal,n.value=e,n}return n(e,t),e.prototype.instantiate=function(t,e,n,r){return rt(this,t,e,n,r)},e.prototype.describe=function(){return JSON.stringify(this.value)},e.prototype.isValidSnapshot=function(t,e){return h(t)&&t===this.value?st():ut(e,t,"Value is not a literal "+JSON.stringify(this.value))},e}(zt),te=new(function(t){function e(){var e=t.call(this,"frozen")||this;return e.flags=At.Frozen,e}return n(e,t),e.prototype.describe=function(){return"<any immutable value>"},e.prototype.instantiate=function(t,e,n,r){return rt(this,t,e,n,d(r))},e.prototype.isValidSnapshot=function(t,e){return y(t)?st():ut(e,t,"Value is not serializable and cannot be frozen")},e}(zt)),ee=vt(Ht,null),ne=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|At.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){var n=this.type.validate(t,e);if(n.length>0)return n;var r=Z(t)?tt(t).snapshot:t;return this.predicate(r)?st():ut(e,t,"Value does not respect the refinement predicate")},e}(zt),re=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|At.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),ie={enumeration:function(t,e){var n="string"==typeof t?e:t,r=mt.apply(void 0,n.map(function(t){return wt(""+t)}));return"string"==typeof t&&(r.name=t),r},model:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n="string"==typeof t[0]?t.shift():"AnonymousModel",r=t.shift()||{};return new Gt({name:n,properties:r})},compose:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n="string"==typeof t[0]?t.shift():"AnonymousModel";return t.reduce(function(t,e){return t.extend({name:t.name+"_"+e.name,properties:e.properties,initializers:e.initializers})}).named(n)},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 Qt(t)},union:mt,optional:vt,literal:wt,maybe:function(t){return t===te&&i("Unable to declare `types.maybe(types.frozen)`. Frozen already accepts `null`. Consider using `types.optional(types.frozen, null)` instead."),mt(ee,t)},refinement:function(t,e,n){return new ne(t,e,n)},string:Lt,boolean:Ut,number:Mt,Date:Jt,map:function(t){return new Rt("map<string, "+t.name+">",t)},array:function(t){return new kt(t.name+"[]",t)},frozen:te,identifier:function(t){return void 0===t&&(t=Lt),new Wt(t)},late:function(t,e){var n="string"==typeof t?t:"late("+t.toString()+")";return new re(n,"string"==typeof t?e:t)},undefined:$t,null:Ht};t.types=ie,t.escapeJsonPath=P,t.unescapeJsonPath=j,t.onAction=z,t.process=function(t){return Vt(t.name,t)},t.isStateTreeNode=Z,t.asReduxStore=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];Z(t)||i("Expected model object");var r={getState:function(){return q(t)},dispatch:function(e){jt(e,o.slice(),function(e){return E(t,Pt(e))})},subscribe:function(e){return H(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,Y(e,i),r=!1)}),z(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,q(e))}})},t.getType=L,t.getChildType=function(t,e){return tt(t).getChildType(e)},t.addMiddleware=M,t.onPatch=U,t.onSnapshot=H,t.applyPatch=$,t.revertPatch=J,t.recordPatches=function(t){var e={patches:[],get cleanPatches(){return this.patches.map(V)},stop:function(){n()},replay:function(n){$(n||t,e.patches)},undo:function(e){J(t||t,this.patches)}},n=U(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=z(t,e.actions.push.bind(e.actions));return e},t.protect=function(t){var e=tt(t);e.isRoot||i("`protect` can only be invoked on root nodes"),e.isProtectionEnabled=!0},t.unprotect=function(t){var e=tt(t);e.isRoot||i("`unprotect` can only be invoked on root nodes"),e.isProtectionEnabled=!1},t.isProtected=B,t.applySnapshot=Y,t.getSnapshot=q,t.hasParent=function(t,e){void 0===e&&(e=1),e<0&&i("Invalid depth: "+e+", should be >= 1");for(var n=tt(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=tt(t).parent;r;){if(0==--n)return r.storedValue;r=r.parent}return i("Failed to find the parent of "+tt(t)+" at depth "+e)},t.getRoot=function(t){return tt(t).root.storedValue},t.getPath=function(t){return tt(t).path},t.getPathParts=function(t){return S(tt(t).path)},t.isRoot=G,t.resolvePath=K,t.resolveIdentifier=function(t,e,n){R(t)||i("Expected a type as first argument");var r=tt(e).root.identifierCache.resolve(t,""+n);return r?r.value:void 0},t.tryResolve=Q,t.getRelativePath=function(t,e){return tt(t).getRelativePathTo(tt(e))},t.clone=function(t,e){void 0===e&&(e=!0);var n=tt(t);return n.type.create(n.snapshot,!0===e?n.root._environment:!1===e?void 0:e)},t.detach=function(t){return tt(t).detach(),t},t.destroy=function(t){var e=tt(t);e.isRoot?e.die():e.parent.removeChild(e.subpath)},t.isAlive=function(t){return tt(t).isAlive},t.addDisposer=function(t,e){tt(t).addDisposer(e)},t.getEnv=function(t){var e=tt(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=X,Object.defineProperty(t,"__esModule",{value:!0})}); |
@@ -20,8 +20,6 @@ import { IObjectChange, IObjectWillChange } from "mobx"; | ||
}; | ||
private readonly parsedProperties; | ||
private preProcessor; | ||
modelConstructor: new () => any; | ||
private readonly propertiesNames; | ||
constructor(opts: ObjectTypeConfig); | ||
extend(opts: ObjectTypeConfig): ObjectType<any, any>; | ||
private createModelConstructor(); | ||
actions<A extends { | ||
@@ -43,3 +41,2 @@ [name: string]: Function; | ||
didChange: (change: IObjectChange) => void; | ||
parseModelProps(): void; | ||
getChildren(node: Node): Node[]; | ||
@@ -46,0 +43,0 @@ getChildNode(node: Node, key: string): Node; |
export declare const EMPTY_ARRAY: ReadonlyArray<any>; | ||
export declare const EMPTY_OBJECT: {}; | ||
export declare type IDisposer = () => void; | ||
@@ -3,0 +4,0 @@ export declare function fail(message?: string): never; |
{ | ||
"name": "mobx-state-tree", | ||
"version": "0.10.1", | ||
"version": "0.10.2", | ||
"description": "Opinionated, transactional, MobX powered state container", | ||
@@ -5,0 +5,0 @@ "main": "dist/mobx-state-tree.js", |
@@ -46,3 +46,2 @@ <p align="center"> | ||
* CodeSandbox [TodoList demo](https://codesandbox.io/s/nZ26kGMD) fork for testing and bug reporting | ||
* JSBin [playground](http://jsbin.com/petoxeheta/edit?html,js,console) (for non console based fiddles) | ||
@@ -582,3 +581,3 @@ Typescript typings are included in the packages. Use `module: "commonjs"` or `moduleResolution: "node"` to make sure they are picked up automatically in any consuming project. | ||
MST models primarily aid in storing _persistable_ state. State that can be persisted, serialized, transferred, patched, replaced etc. | ||
However, sometimes you need to keep track of temporary, non persistable state. This is called _volatile_ state in MST. Examples include promises, sockets, DOM elements etc - state which is needed for local purposes as long as the object is alive. | ||
However, sometimes you need to keep track of temporary, non persistable state. This is called _volatile_ state in MST. Examples include promises, sockets, DOM elements etc. - state which is needed for local purposes as long as the object is alive. | ||
@@ -673,4 +672,4 @@ Volatile state (which is also private) can be introduced by creating variables inside any of the action initializer functions. | ||
* `types.model(properties, actions)` Defines a "class like" type, with properties and actions to operate on the object. | ||
* `types.array(type)` Declares an array of the specified type | ||
* `types.map(type)` Declares an map of the specified type | ||
* `types.array(type)` Declares an array of the specified type. | ||
* `types.map(type)` Declares a map of the specified type. | ||
@@ -697,3 +696,2 @@ ## Primitive types | ||
* `types.compose(name?, type1...typeX)`, creates a new model type by taking a bunch of existing types and combining them into a new one | ||
* `types.compose(name?, baseType, props, volatileState?, actions?)`, creates a new model type by taking an existing type and introducing additional properties, state and actions | ||
@@ -803,3 +801,3 @@ ## Property types | ||
`types.optional` can takes as default function also a function, which will be invoked each time the default value is needed. This is useful to generate timestamps, identifiers or even complex objects: | ||
`types.optional` can take an optional function parameter which will be invoked each time a default value is needed. This is useful to generate timestamps, identifiers or even complex objects, for example: | ||
@@ -909,3 +907,3 @@ `createdDate: types.optional(types.date, () => new Date())` | ||
* If no identifier is specified, but the type of the snapshot is correct, MST will reconcile objects as well if they are stored in a specific model property or under the same map key. | ||
* In arrays, items without identifier are never reconciled | ||
* In arrays, items without an identifier are never reconciled. | ||
@@ -920,3 +918,3 @@ If an object is reconciled, the consequence is that localState is preserved and `postCreate` / `attach` life-cycle hooks are not fired because applying a snapshot results just in an existing tree node being updated. | ||
Yep, perfectly fine. No problem. Go on. `observer`, `autorun` etc will work as expected. | ||
Yep, perfectly fine. No problem. Go on. `observer`, `autorun` etc. will work as expected. | ||
@@ -954,8 +952,8 @@ ### Should all state of my app be stored in `mobx-state-tree`? | ||
- like Redux, and unlike MobX, MST prescribes a very specific state architecture. | ||
- Like Redux, and unlike MobX, MST prescribes a very specific state architecture. | ||
- mobx-state-tree allows direct modification of any value in the tree; it is not necessary to construct a new tree in your actions. | ||
- mobx-state-tree allows for fine-grained and efficient observation of any point in the state tree. | ||
- mobx-state-tree generates JSON patches for any modification that is made. | ||
- mobx-state-tree provides utilties to turn any MST tree into a valid Redux store. | ||
- having multiple MSTs in a single application is perfectly fine. | ||
- mobx-state-tree provides utilities to turn any MST tree into a valid Redux store. | ||
- Having multiple MSTs in a single application is perfectly fine. | ||
@@ -962,0 +960,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
455429
8024
959