mobx-state-tree
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -1,2 +0,2 @@ | ||
export declare type IMiddlewareEventType = "action" | "process_spawn" | "process_resume" | "process_resume_error" | "process_return" | "process_throw"; | ||
export declare type IMiddlewareEventType = "action" | "flow_spawn" | "flow_resume" | "flow_resume_error" | "flow_return" | "flow_throw"; | ||
export declare type IMiddlewareEvent = { | ||
@@ -3,0 +3,0 @@ type: IMiddlewareEventType; |
@@ -103,13 +103,14 @@ /** | ||
* const Todo = types.model({ | ||
* done: false, | ||
* done: false | ||
* }).actions(self => ({ | ||
* toggle() { | ||
* this.done = !this.done | ||
* self.done = !self.done | ||
* } | ||
* }) | ||
* })) | ||
* | ||
* const todo = new Todo() | ||
* todo.done = true // OK | ||
* protect(todo) | ||
* todo.done = false // throws! | ||
* const todo = Todo.create() | ||
* todo.done = true // throws! | ||
* todo.toggle() // OK | ||
* unprotect(todo) | ||
* todo.done = false // OK | ||
*/ | ||
@@ -252,6 +253,6 @@ export declare function unprotect(target: IStateTreeNode): void; | ||
* title: types.string | ||
* }, { | ||
* }).actions(self => ({ | ||
* afterCreate() { | ||
* const autoSaveDisposer = reaction( | ||
* () => getSnapshot(this), | ||
* () => getSnapshot(self), | ||
* snapshot => sendSnapshotToServerSomehow(snapshot) | ||
@@ -261,5 +262,5 @@ * ) | ||
* // instance is destroyed | ||
* addDisposer(this, autoSaveDisposer) | ||
* addDisposer(self, autoSaveDisposer) | ||
* } | ||
* }) | ||
* })) | ||
* | ||
@@ -266,0 +267,0 @@ * @export |
@@ -7,2 +7,3 @@ import "./core/node"; | ||
export { decorate, addMiddleware, IMiddlewareEvent, IMiddlewareHandler, IMiddlewareEventType } from "./core/action"; | ||
export { flow } from "./core/flow"; | ||
export { process } from "./core/process"; | ||
@@ -9,0 +10,0 @@ export { isStateTreeNode, IStateTreeNode } from "./core/node"; |
@@ -52,2 +52,24 @@ import { IStateTreeNode } from "../core/node"; | ||
* | ||
* @example | ||
* const Todo = types.model({ | ||
* task: types.string | ||
* }) | ||
* | ||
* const TodoStore = types.model({ | ||
* todos: types.array(Todo) | ||
* }).actions(self => ({ | ||
* add(todo) { | ||
* self.todos.push(todo); | ||
* } | ||
* })) | ||
* | ||
* const s = TodoStore.create({ todos: [] }) | ||
* | ||
* let disposer = onAction(s, (call) => { | ||
* console.log(call); | ||
* }) | ||
* | ||
* s.add({ task: "Grab a coffee" }) | ||
* // Logs: { name: "add", path: "", args: [{ task: "Grab a coffee" }] } | ||
* | ||
* @export | ||
@@ -54,0 +76,0 @@ * @param {IStateTreeNode} target |
@@ -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}jt(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]:_t}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){var n=t.indexOf(e);-1!==n&&t.splice(n,1)}function g(t,e){return t.push(e),function(){m(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){return"oldValue"in t||i("Patches without `oldValue` field cannot be inversed"),[V(t),S(t)]}function V(t){switch(t.op){case"add":return{op:"add",path:t.path,value:t.value};case"remove":return{op:"remove",path:t.path};case"replace":return{op:"replace",path:t.path,value:t.value}}}function S(t){switch(t.op){case"add":return{op:"remove",path:t.path};case"remove":return{op:"add",path:t.path,value:t.oldValue};case"replace":return{op:"replace",path:t.path,value:t.oldValue}}}function A(t){return t.replace(/~/g,"~1").replace(/\//g,"~0")}function j(t){return t.replace(/~0/g,"/").replace(/~1/g,"~")}function _(t){return 0===t.length?"":"/"+t.map(A).join("/")}function T(t){var e=t.split("/").map(j);return""===e[0]?e.slice(1):e}function C(t){return"object"==typeof t&&t&&!0===t.isType}function x(t){return C(t)&&(t.flags&(At.String|At.Number|At.Boolean|At.Date))>0}function O(t){return(t.flags&At.Reference)>0}function N(t){return B(t).type}function I(t,e){return B(t).onPatch(e)}function D(t,e){B(t).applyPatches(u(e))}function R(t,e){return B(t).applySnapshot(e)}function z(t){return B(t).root.storedValue}function E(t,e){var n=B(t).resolve(e,!1);if(void 0!==n)return n?n.value:void 0}function k(t,e){var n=B(t);n.getChildren().forEach(function(t){W(t.storedValue)&&k(t.storedValue,e)}),e(n.storedValue)}function F(){return Ct++}function M(t,e){var n=B(t.context),r=n._isRunningAction,i=xt;n.assertAlive(),n._isRunningAction=!0,xt=t;try{return J(n,t,e)}finally{xt=i,n._isRunningAction=r}}function $(){return xt||i("Not running an action!")}function L(t,n,r){var i=e.action(n,r);return i.$mst_middleware=r.$mst_middleware,function(){var e=F();return M({type:"action",name:n,id:e,args:w(arguments),context:t,tree:z(t),rootId:xt?xt.rootId:e,parentId:xt?xt.id:0},i)}}function U(t,e){return B(t).addMiddleWare(e)}function H(t,e,n){for(var r=n.$mst_middleware||[],i=t;i;)r=r.concat(i.middlewares),i=i.parent;return r}function J(t,e,n){function r(t){var o=i.shift();return o?o(t,r):n.apply(null,e.args)}var i=H(t,e,n);return i.length?r(e):n.apply(null,e.args)}function W(t){return!(!t||!t.$treenode)}function B(t){return W(t)?t.$treenode:i("Value "+t+" is no MST Node")}function Y(t){return t&&"object"==typeof t&&!(t instanceof Date)&&!W(t)&&!Object.isFrozen(t)}function q(){return B(this).snapshot}function G(t,e,n,r,s,u,p){if(void 0===u&&(u=o),void 0===p&&(p=a),W(s)){var c=B(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 It(t,e,n,r,s,u,p)}function Z(t){try{return JSON.stringify(t)}catch(t){return"<Unserializable: "+t+">"}}function K(t){return"function"==typeof t?"<function"+(t.name?" "+t.name:"")+">":W(t)?"<"+t+">":"`"+Z(t)+"`"}function Q(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=W(e)?"value of type "+B(e).type.name+":":f(e)?"value":"snapshot",a=n&&W(e)&&n.is(B(e).snapshot);return""+i+o+" "+K(e)+" is not assignable "+(n?"to type: `"+n.name+"`":"")+(t.message?" ("+t.message+")":"")+(n?x(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 X(t,e,n){return t.concat([{path:e,type:n}])}function tt(){return _t}function et(t,e,n){return[{context:t,value:e,message:n}]}function nt(t){return t.reduce(function(t,e){return t.concat(e)},[])}function rt(t,e){}function it(t,e){var n=t.validate(e,[{path:"",type:t}]);n.length>0&&i("Error while converting "+K(e)+" to `"+t.name+"`:\n"+n.map(Q).join("\n"))}function ot(){return B(this)+"("+this.size+" items)"}function at(t){t||i("Map.put cannot be used to set empty values");var e;if(W(t))e=B(t);else{if(!l(t))return i("Map.put can only be used to store complex values");e=B(B(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 st(){return B(this)+"("+this.length+" items)"}function ut(t,e,n,r,o){for(var a,s,u=!1,p=void 0,c=0;a=n[c],(s=r[c])instanceof It&&(s=s.storedValue),u=c<=r.length-1,a||u;c++)if(u)if(a)if(ct(a,s))n[c]=pt(e,t,""+o[c],s,a);else{p=void 0;for(var l=c;l<n.length;l++)if(ct(n[l],s)){p=n.splice(l,1)[0];break}n.splice(c,0,pt(e,t,""+o[c],s,p))}else W(s)&&B(s).parent===t&&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+"/"+o[c]+"', but it lives already at '"+B(s).path+"'"),n.splice(c,0,pt(e,t,""+o[c],s));else a.die(),n.splice(c,1),c--;return n}function pt(t,e,n,r,i){if(rt(t,r),W(r)){var o=B(r);if(o.assertAlive(),null!==o.parent&&o.parent===e)return o.setParent(e,n),i&&i!==o&&i.die(),o}if(i){var a=t.reconcile(i,r);return a.setParent(e,n),a}return t.instantiate(e,n,e._environment,r)}function ct(t,e){return W(e)?B(e)===t:!(!l(e)||t.snapshot!==e)||!(null===t.identifier||!t.identifierAttribute||!c(e)||e[t.identifierAttribute]!==t.identifier)}function lt(t){switch(typeof t){case"string":return Ft;case"number":return Mt;case"boolean":return $t;case"object":if(t instanceof Date)return Ht}return i("Cannot determine primtive type from value "+t)}function ft(t,e){return new Wt(t,e)}function ht(){return B(this).toString()}function dt(t){return Object.keys(t).reduce(function(t,e){if(e in Bt)return i("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))return Object.assign({},t,(o={},o[e]=ft(lt(r),r),o));if(C(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 yt(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var r=C(t)?null:t,i=C(t)?e.concat(t):e,o="("+i.map(function(t){return t.name}).join(" | ")+")";return new Kt(o,i,r)}function vt(t){return new Qt(t)}function bt(t,e){var n=function(){function r(e,r,i){e.$mst_middleware=n.$mst_middleware,M({name:t,type:r,id:o,args:[i],tree:a.tree,context:a.context,parentId:a.id,rootId:a.rootId},e)}var o=F(),a=$(),s=arguments;return new Promise(function(u,p){function c(t){var e;try{r(function(t){e=h.next(t)},"process_resume",t)}catch(t){return void setImmediate(function(){r(function(e){p(t)},"process_throw",t)})}f(e)}function l(t){var e;try{r(function(t){e=h.throw(t)},"process_resume_error",t)}catch(t){return void setImmediate(function(){r(function(e){p(t)},"process_throw",t)})}f(e)}function f(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(c,l);setImmediate(function(){r(function(t){u(t)},"process_return",t.value)})}var h,d=function(){h=e.apply(null,arguments),c(void 0)};d.$mst_middleware=n.$mst_middleware,M({name:t,type:"process_spawn",id:o,args:w(s),tree:a.tree,context:a.context,parentId:a.id,rootId:a.rootId},d)})};return n}function mt(t,e,n,r){if(r instanceof Date)return{$MST_DATE:r.getTime()};if(f(r))return r;if(W(r))return wt("[MSTNode: "+N(r).name+"]");if("function"==typeof r)return wt("[function]");if("object"==typeof r&&!c(r)&&!s(r))return wt("[object "+(r&&r.constructor&&r.constructor.name||"Complex Object")+"]");try{return JSON.stringify(r),r}catch(t){return wt(""+t)}}function gt(t,e){return e&&"object"==typeof e&&"$MST_DATE"in e?new Date(e.$MST_DATE):e}function wt(t){return{$MST_UNSERIALIZABLE:!0,type:t}}function Pt(t,n){e.runInAction(function(){u(n).forEach(function(e){return Vt(t,e)})})}function Vt(t,e){var n=E(t,e.path||"");if(!n)return i("Invalid action path: "+(e.path||""));var r=B(n);return"@APPLY_PATCHES"===e.name?D.call(null,n,e.args[0]):"@APPLY_SNAPSHOT"===e.name?R.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 gt(r,t)}):[]))}function St(t,e,n){function r(n){if("action"===n.type&&n.id===n.rootId){var r=B(n.context);e({name:n.name,path:B(t).getRelativePathTo(r),args:n.args.map(function(t,e){return mt(r,n.name,e,t)})})}}return void 0===n&&(n=!1),U(t,n?function(t,e){var n=e(t);return r(t),n}:function(t,e){return r(t),e(t)})}var At,jt=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])},_t=Object.freeze([]),Tt=Object.freeze({});!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 Ct=1,xt=null,Ot=function(){function t(){this.cache=e.observable.map()}return t.prototype.addNodeToCache=function(t){if(t.identifierAttribute){var n=t.identifier;this.cache.has(n)||this.cache.set(n,e.observable.shallowArray());var r=this.cache.get(n);-1!==r.indexOf(t)&&i("Already registered"),r.push(t)}return this},t.prototype.mergeCache=function(t){var e=this;t.identifierCache.cache.values().forEach(function(t){return t.forEach(function(t){e.addNodeToCache(t)})})},t.prototype.notifyDied=function(t){if(t.identifierAttribute){var e=this.cache.get(t.identifier);e&&e.remove(t)}},t.prototype.splitCache=function(e){var n=new t,r=e.path;return this.cache.values().forEach(function(t){for(var e=t.length-1;e>=0;e--)0===t[e].path.indexOf(r)&&(n.addNodeToCache(t[e]),t.splice(e,1))}),n},t.prototype.resolve=function(t,e){var n=this.cache.get(e);if(!n)return null;var r=n.filter(function(e){return t.isAssignableFrom(e.type)});switch(r.length){case 0:return null;case 1:return r[0];default:return i("Cannot resolve a reference to type '"+t.name+"' with id: '"+e+"' unambigously, there are multiple candidates: "+r.map(function(t){return t.path}).join(", "))}},t}(),Nt=1,It=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=++Nt,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=Y(this.storedValue);this.applyPatches=L(this.storedValue,"@APPLY_PATCHES",function(t){t.forEach(function(t){var e=T(t.path);c.resolvePath(e.slice(0,-1)).applyPatchLocally(e[e.length-1],t)})}).bind(this.storedValue),this.applySnapshot=L(this.storedValue,"@APPLY_SNAPSHOT",function(t){if(t!==c.snapshot)return c.type.applySnapshot(c,t)}).bind(this.storedValue),n||(this.identifierCache=new Ot),l&&v(this.storedValue,"$treenode",this);var f=!0;try{l&&v(this.storedValue,"toJSON",q),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"),f=!1}finally{f&&(this._isAlive=!1)}var h=e.reaction(function(){return c.snapshot},function(t){c.emitSnapshot(t)});h.onError(function(t){throw t}),this.addDisposer(h)}return Object.defineProperty(t.prototype,"identifier",{get:function(){return this.identifierAttribute?this.storedValue[this.identifierAttribute]:null},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"path",{get:function(){return this.parent?this.parent.path+"/"+A(this.subpath):""},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isRoot",{get:function(){return null===this.parent},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"parent",{get:function(){return this._parent},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"root",{get:function(){for(var t,e=this;t=e.parent;)e=t;return e},enumerable:!0,configurable:!0}),t.prototype.getRelativePathTo=function(t){this.root!==t.root&&i("Cannot calculate relative path: objects '"+this+"' and '"+t+"' are not part of the same object tree");for(var e=T(this.path),n=T(t.path),r=0;r<e.length&&e[r]===n[r];r++);return e.slice(r).map(function(t){return".."}).join("/")+_(n.slice(r))},t.prototype.resolve=function(t,e){return void 0===e&&(e=!0),this.resolvePath(T(t),e)},t.prototype.resolvePath=function(t,e){void 0===e&&(e=!0);for(var n=this,r=0;r<t.length;r++){if(""===t[r])n=n.root;else if(".."===t[r])n=n.parent;else{if("."===t[r]||""===t[r])continue;if(n){n=n.getChildNode(t[r]);continue}}if(!n)return e?i("Could not resolve '"+t[r]+"' in '"+_(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||W(this.storedValue)&&(k(this.storedValue,function(t){return B(t).aboutToDie()}),k(this.storedValue,function(t){return B(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 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){return g(this.patchSubscribers,t)},t.prototype.emitPatch=function(t,e){if(this.patchSubscribers.length){var n=P(p({},t,{path:e.path.substr(this.path.length)+"/"+t.path})),r=n[0],i=n[1];this.patchSubscribers.forEach(function(t){return t(r,i)})}this.parent&&this.parent.emitPatch(t,e)},t.prototype.setParent=function(t,e){void 0===e&&(e=null),this.parent===t&&this.subpath===e||(t&&(this._parent&&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.root!==this||i("A state tree is not allowed to contain itself. Cannot assign "+this+" to path '"+t.path+"/"+e+"'"),!this._parent&&this._environment&&this._environment!==t._environment&&i("A state tree cannot be made part of another state tree as long as their environments are different.")),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}(),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()),rt(this,t),this.instantiate(null,"",e,t).value},t.prototype.isAssignableFrom=function(t){return t===this},t.prototype.validate=function(t,e){return W(t)?N(t)===this||this.isAssignableFrom(N(t))?tt():et(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(W(e)&&B(e)===t)return t;if(t.type===this&&l(e)&&!W(e)&&(!t.identifierAttribute||t.identifier===e[t.identifierAttribute]))return t.applySnapshot(e),t;var n=t.parent,r=t.subpath;if(t.die(),W(e)&&this.isAssignableFrom(N(e))){var i=B(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}(),Rt=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 _t},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),zt=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",at),v(t,"toString",ot),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 G(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=B(t.object);switch(e.assertWritable(),t.type){case"update":var n=t.newValue;if(n===t.object.get(t.name))return null;rt(this.subType,n),t.newValue=this.subType.reconcile(e.getChildNode(t.name),t.newValue),this.verifyIdentifier(t.name,t.newValue);break;case"add":rt(this.subType,t.newValue),t.newValue=this.subType.instantiate(e,t.name,void 0,t.newValue),this.verifyIdentifier(t.name,t.newValue)}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=B(t.object);switch(t.type){case"update":return void e.emitPatch({op:"replace",path:A(t.name),value:t.newValue.snapshot,oldValue:t.oldValue?t.oldValue.snapshot:void 0},e);case"add":return void e.emitPatch({op:"add",path:A(t.name),value:t.newValue.snapshot,oldValue:void 0},e);case"delete":var n=t.oldValue.snapshot;return t.oldValue.die(),void e.emitPatch({op:"remove",path:A(t.name),oldValue:n},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){rt(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)?nt(Object.keys(t).map(function(r){return n.subType.validate(t[r],X(e,r,n.subType))})):et(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),Et=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",st),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 G(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=B(t.object);e.assertWritable();var n=e.getChildren();switch(t.type){case"update":if(t.newValue===t.object[t.index])return null;t.newValue=ut(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=ut(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=B(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){rt(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)?nt(t.map(function(t,r){return n.subType.validate(t,X(e,""+r,n.subType))})):et(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),kt=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 G(this,t,e,n,r,this.initializer)},e.prototype.isValidSnapshot=function(t,e){return f(t)&&this.checker(t)?tt():et(e,t,"Value is not a "+("Date"===this.name?"Date or a unix milliseconds timestamp":this.name))},e}(Rt),Ft=new kt("string",At.String,function(t){return"string"==typeof t}),Mt=new kt("number",At.Number,function(t){return"number"==typeof t}),$t=new kt("boolean",At.Boolean,function(t){return"boolean"==typeof t}),Lt=new kt("null",At.Null,function(t){return null===t}),Ut=new kt("undefined",At.Undefined,function(t){return void 0===t}),Ht=new kt("Date",At.Date,function(t){return"number"==typeof t||t instanceof Date},function(t){return t instanceof Date?t:new Date(t)});Ht.getSnapshot=function(t){return t.storedValue.getTime()};var Jt=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&&W(t.storedValue)?(t.identifierAttribute&&i("Cannot define property '"+e+"' as object identifier, property '"+t.identifierAttribute+"' is already defined as identifier property"),t.identifierAttribute=e,G(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):et(e,t,"Value is not a valid identifier, which is a string or a number")},e}(Rt),Wt=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=W(i)?B(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&&rt(this,t),t},e.prototype.isValidSnapshot=function(t,e){return void 0===t?tt():this.type.validate(t,e)},e.prototype.isAssignableFrom=function(t){return this.type.isAssignableFrom(t)},e}(Rt),Bt={afterCreate:"afterCreate",afterAttach:"afterAttach",postProcessSnapshot:"postProcessSnapshot",beforeDetach:"beforeDetach",beforeDestroy:"beforeDestroy"},Yt={name:"AnonymousModel",properties:{},initializers:_t},qt=function(t){function o(n){var r=t.call(this,n.name||Yt.name)||this;r.flags=At.Object,r.createNewInstance=function(){var t=e.observable.shallowObject(Tt);return v(t,"toString",ht),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=B(t.object);e.emitPatch({op:"replace",path:A(t.name),value:t.newValue.snapshot,oldValue:t.oldValue?t.oldValue.snapshot:void 0},e)};var o=n.name||Yt.name;return/^\w[\w\d_]*$/.test(o)||i("Typename should be a valid identifier: "+o),Object.assign(r,Yt,n),r.properties=dt(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){if("preProcessSnapshot"===t)return i("Cannot define action 'preProcessSnapshot', it should be defined using 'type.preProcessSnapshot(fn)' instead");var r=n[t],o=e[t];if(t in Bt&&o){var a=r;r=t===Bt.postProcessSnapshot?function(t){return a(o(t))}:function(){o.apply(null,arguments),a.apply(null,arguments)}}v(e,t,L(e,t,r))}),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){var e=this.preProcessor;return e?this.extend({preProcessor:function(n){return e(t(n))}}):this.extend({preProcessor:t})},o.prototype.instantiate=function(t,e,n,r){return G(this,t,e,n,this.applySnapshotPreProcessor(r),this.createNewInstance,this.finalizeNewInstance)},o.prototype.willChange=function(t){var e=B(t.object),n=this.properties[t.name];return e.assertWritable(),rt(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);rt(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)?nt(this.propertiesNames.map(function(t){return n.properties[t].validate(r[t],X(e,t,n.properties[t]))})):et(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}(Dt),Gt=function(){return function(t,e){if(this.mode=t,this.value=e,"object"===t){if(!W(e))return i("Can only store references to tree nodes, got: '"+e+"'");if(!B(e).identifierAttribute)return i("Can only store references with a defined identifier attribute.")}}}(),Zt=function(t){function e(e){var n=t.call(this,"reference("+e.name+")")||this;return n.targetType=e,n.flags=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 B(e.value).identifier}},e.prototype.instantiate=function(t,e,n,r){var i=W(r);return G(this,t,e,n,new Gt(i?"object":"identifier",r))},e.prototype.reconcile=function(t,e){var n=W(e)?"object":"identifier";if(O(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?tt():et(e,t,"Value is not a valid identifier, which is a string or a number")},e}(Rt),Kt=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?et(e,t,"Multiple types are applicable for the union (hint: provide a dispatch function)"):0===r.length?et(e,t,"No type is applicable for the union").concat(nt(n)):tt()},e}(Rt),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 G(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?tt():et(e,t,"Value is not a literal "+JSON.stringify(this.value))},e}(Rt),Xt=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 G(this,t,e,n,d(r))},e.prototype.isValidSnapshot=function(t,e){return y(t)?tt():et(e,t,"Value is not serializable and cannot be frozen")},e}(Rt)),te=ft(Lt,null),ee=function(t){function e(e,n,r,i){var o=t.call(this,e)||this;return o.type=n,o.predicate=r,o.message=i,o}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=W(t)?B(t).snapshot:t;return this.predicate(r)?tt():et(e,t,this.message(t))},e}(Rt),ne=function(t){function e(e,n){var r=t.call(this,e)||this;return r._subType=null,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}(Rt),re={enumeration:function(t,e){var n="string"==typeof t?e:t,r=yt.apply(void 0,n.map(function(t){return vt(""+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 qt({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 new Zt(t)},union:yt,optional:ft,literal:vt,maybe:function(t){return yt(te,t)},refinement:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n="string"==typeof t[0]?t.shift():C(t[0])?t[0].name:null,r=t[0],i=t[1],o=t[2]?t[2]:function(t){return"Value does not respect the refinement predicate"};return new ee(n,r,i,o)},string:Ft,boolean:$t,number:Mt,Date:Ht,map:function(t){return new zt("map<string, "+t.name+">",t)},array:function(t){return new Et(t.name+"[]",t)},frozen:Xt,identifier:function(t){return void 0===t&&(t=Ft),new Jt(t)},late:function(t,e){var n="string"==typeof t?t:"late("+t.toString()+")";return new ne(n,"string"==typeof t?e:t)},undefined:Ut,null:Lt};t.types=re,t.typecheck=it,t.escapeJsonPath=A,t.unescapeJsonPath=j,t.decorate=function(t,e){return e.$mst_middleware?e.$mst_middleware.push(t):e.$mst_middleware=[t],e},t.addMiddleware=U,t.process=function(t){return bt(t.name,t)},t.isStateTreeNode=W,t.applyAction=Pt,t.onAction=St,t.recordActions=function(t){var e={actions:[],stop:function(){return n()},replay:function(t){Pt(t,e.actions)}},n=St(t,e.actions.push.bind(e.actions));return e},t.createActionTrackingMiddleware=function(t){var e=new Map;return function(n,r){switch(n.type){case"action":if(t.filter&&!0!==t.filter(n))return r(n);var i=t.onStart(n);t.onResume(n,i),e.set(n.id,{call:n,context:i,async:!1});try{var o=r(n);return t.onSuspend(n,i),!1===e.get(n.id).async&&t.onSuccess(n,i,o),o}catch(e){throw t.onFail(n,i,e),e}case"process_spawn":return(a=e.get(n.rootId)).async=!0,r(n);case"process_resume":case"process_resume_error":a=e.get(n.rootId),t.onResume(n,a.context);try{return r(n)}finally{t.onSuspend(n,a.context)}case"process_throw":return a=e.get(n.rootId),e.delete(n.id),t.onFail(n,a.context,n.args[0]),r(n);case"process_return":var a=e.get(n.rootId);return e.delete(n.id),t.onSuccess(n,a.context,n.args[0]),r(n)}}},t.getType=N,t.getChildType=function(t,e){return B(t).getChildType(e)},t.onPatch=I,t.onSnapshot=function(t,e){return B(t).onSnapshot(e)},t.applyPatch=D,t.recordPatches=function(t){function e(){n||(n=I(t,function(t,e){r.rawPatches.push([t,e])}))}var n=null,r={rawPatches:[],get patches(){return this.rawPatches.map(function(t){return t[0]})},get inversePatches(){return this.rawPatches.map(function(t){return t[0],t[1]})},stop:function(){n&&n(),n=null},resume:e,replay:function(e){D(e||t,r.patches)},undo:function(e){D(e||t,r.inversePatches.slice().reverse())}};return e(),r},t.protect=function(t){var e=B(t);e.isRoot||i("`protect` can only be invoked on root nodes"),e.isProtectionEnabled=!0},t.unprotect=function(t){var e=B(t);e.isRoot||i("`unprotect` can only be invoked on root nodes"),e.isProtectionEnabled=!1},t.isProtected=function(t){return B(t).isProtected},t.applySnapshot=R,t.getSnapshot=function(t){return B(t).snapshot},t.hasParent=function(t,e){void 0===e&&(e=1);for(var n=B(t).parent;n;){if(0==--e)return!0;n=n.parent}return!1},t.getParent=function(t,e){void 0===e&&(e=1);for(var n=e,r=B(t).parent;r;){if(0==--n)return r.storedValue;r=r.parent}return i("Failed to find the parent of "+B(t)+" at depth "+e)},t.getRoot=z,t.getPath=function(t){return B(t).path},t.getPathParts=function(t){return T(B(t).path)},t.isRoot=function(t){return B(t).isRoot},t.resolvePath=function(t,e){var n=B(t).resolve(e);return n?n.value:void 0},t.resolveIdentifier=function(t,e,n){var r=B(e).root.identifierCache.resolve(t,""+n);return r?r.value:void 0},t.tryResolve=E,t.getRelativePath=function(t,e){return B(t).getRelativePathTo(B(e))},t.clone=function(t,e){void 0===e&&(e=!0);var n=B(t);return n.type.create(n.snapshot,!0===e?n.root._environment:!1===e?void 0:e)},t.detach=function(t){return B(t).detach(),t},t.destroy=function(t){var e=B(t);e.isRoot?e.die():e.parent.removeChild(e.subpath)},t.isAlive=function(t){return B(t).isAlive},t.addDisposer=function(t,e){B(t).addDisposer(e)},t.getEnv=function(t){var e=B(t).root._environment;return e||Tt},t.walk=k,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("mobx")):"function"==typeof define&&define.amd?define(["exports","mobx"],e):e(t.mobxStateTree=t.mobxStateTree||{},t.mobx)}(this,function(t,e){"use strict";function n(t,e){function n(){this.constructor=t}St(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}function r(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols)for(var i=0,r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&(n[r[i]]=t[r[i]]);return n}function i(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 o(t){throw void 0===t&&(t="Illegal state"),new Error("[mobx-state-tree] "+t)}function a(t){return t}function s(){}function u(t){return!(!Array.isArray(t)&&!e.isObservableArray(t))}function p(t){return t?u(t)?t:[t]:jt}function c(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];for(var r=0;r<e.length;r++){var i=e[r];for(var o in i)t[o]=i[o]}return t}function l(t){if(null===t||"object"!=typeof t)return!1;var e=Object.getPrototypeOf(t);return e===Object.prototype||null===e}function f(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 d(t){return"function"!=typeof t}function y(t,e,n){Object.defineProperty(t,e,{enumerable:!1,writable:!1,configurable:!0,value:n})}function v(t,e,n){Object.defineProperty(t,e,{enumerable:!0,writable:!1,configurable:!0,value:n})}function b(t,e){var n=t.indexOf(e);-1!==n&&t.splice(n,1)}function m(t,e){return t.push(e),function(){b(t,e)}}function g(t){for(var e=new Array(t.length),n=0;n<t.length;n++)e[n]=t[n];return e}function w(t){return"oldValue"in t||o("Patches without `oldValue` field cannot be inversed"),[P(t),V(t)]}function P(t){switch(t.op){case"add":return{op:"add",path:t.path,value:t.value};case"remove":return{op:"remove",path:t.path};case"replace":return{op:"replace",path:t.path,value:t.value}}}function V(t){switch(t.op){case"add":return{op:"remove",path:t.path};case"remove":return{op:"add",path:t.path,value:t.oldValue};case"replace":return{op:"replace",path:t.path,value:t.oldValue}}}function A(t){return t.replace(/~/g,"~1").replace(/\//g,"~0")}function S(t){return t.replace(/~0/g,"/").replace(/~1/g,"~")}function j(t){return 0===t.length?"":"/"+t.map(A).join("/")}function T(t){var e=t.split("/").map(S);return""===e[0]?e.slice(1):e}function _(t){return"object"==typeof t&&t&&!0===t.isType}function C(t){return _(t)&&(t.flags&(Ct.String|Ct.Number|Ct.Boolean|Ct.Date))>0}function O(t){return(t.flags&Ct.Reference)>0}function x(t){return W(t).type}function N(t,e){return W(t).onPatch(e)}function I(t,e){W(t).applyPatches(p(e))}function D(t,e){return W(t).applySnapshot(e)}function E(t){return W(t).root.storedValue}function R(t,e){var n=W(t).resolve(e,!1);if(void 0!==n)return n?n.value:void 0}function z(t,e){var n=W(t);n.getChildren().forEach(function(t){J(t.storedValue)&&z(t.storedValue,e)}),e(n.storedValue)}function k(){return Ot++}function F(t,e){var n=W(t.context),r=n._isRunningAction,i=xt;n.assertAlive(),n._isRunningAction=!0,xt=t;try{return H(n,t,e)}finally{xt=i,n._isRunningAction=r}}function M(){return xt||o("Not running an action!")}function $(t,n,r){var i=e.action(n,r);return i.$mst_middleware=r.$mst_middleware,function(){var e=k();return F({type:"action",name:n,id:e,args:g(arguments),context:t,tree:E(t),rootId:xt?xt.rootId:e,parentId:xt?xt.id:0},i)}}function L(t,e){return W(t).addMiddleWare(e)}function U(t,e,n){for(var r=n.$mst_middleware||[],i=t;i;)r=r.concat(i.middlewares),i=i.parent;return r}function H(t,e,n){function r(t){var o=i.shift();return o?o(t,r):n.apply(null,e.args)}var i=U(t,e,n);return i.length?r(e):n.apply(null,e.args)}function J(t){return!(!t||!t.$treenode)}function W(t){return J(t)?t.$treenode:o("Value "+t+" is no MST Node")}function B(t){return t&&"object"==typeof t&&!(t instanceof Date)&&!J(t)&&!Object.isFrozen(t)}function Y(){return W(this).snapshot}function q(t,e,n,r,i,u,p){if(void 0===u&&(u=a),void 0===p&&(p=s),J(i)){var c=W(i);return c.isRoot||o("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,i,u,p)}function G(t){try{return JSON.stringify(t)}catch(t){return"<Unserializable: "+t+">"}}function Z(t){return"function"==typeof t?"<function"+(t.name?" "+t.name:"")+">":J(t)?"<"+t+">":"`"+G(t)+"`"}function K(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=J(e)?"value of type "+W(e).type.name+":":h(e)?"value":"snapshot",a=n&&J(e)&&n.is(W(e).snapshot);return""+i+o+" "+Z(e)+" is not assignable "+(n?"to type: `"+n.name+"`":"")+(t.message?" ("+t.message+")":"")+(n?C(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 Q(t,e,n){return t.concat([{path:e,type:n}])}function X(){return jt}function tt(t,e,n){return[{context:t,value:e,message:n}]}function et(t){return t.reduce(function(t,e){return t.concat(e)},[])}function nt(t,e){}function rt(t,e){var n=t.validate(e,[{path:"",type:t}]);n.length>0&&o("Error while converting "+Z(e)+" to `"+t.name+"`:\n"+n.map(K).join("\n"))}function it(){return W(this)+"("+this.size+" items)"}function ot(t){t||o("Map.put cannot be used to set empty values");var e;if(J(t))e=W(t);else{if(!f(t))return o("Map.put can only be used to store complex values");e=W(W(this).type.subType.create(t))}return e.identifierAttribute||o("Map.put can only be used to store complex values that have an identifier type attribute"),this.set(e.identifier,e.value),this}function at(){return W(this)+"("+this.length+" items)"}function st(t,e,n,r,i){for(var a,s,u=!1,p=void 0,c=0;u=c<=r.length-1,a=n[c],(s=u?r[c]:void 0)instanceof Dt&&(s=s.storedValue),a||u;c++)if(u)if(a)if(pt(a,s))n[c]=ut(e,t,""+i[c],s,a);else{p=void 0;for(var l=c;l<n.length;l++)if(pt(n[l],s)){p=n.splice(l,1)[0];break}n.splice(c,0,ut(e,t,""+i[c],s,p))}else J(s)&&W(s).parent===t&&o("Cannot add an object to a state tree if it is already part of the same or another state tree. Tried to assign an object to '"+t.path+"/"+i[c]+"', but it lives already at '"+W(s).path+"'"),n.splice(c,0,ut(e,t,""+i[c],s));else a.die(),n.splice(c,1),c--;return n}function ut(t,e,n,r,i){if(nt(t,r),J(r)){var o=W(r);if(o.assertAlive(),null!==o.parent&&o.parent===e)return o.setParent(e,n),i&&i!==o&&i.die(),o}if(i){var a=t.reconcile(i,r);return a.setParent(e,n),a}return t.instantiate(e,n,e._environment,r)}function pt(t,e){return J(e)?W(e)===t:!(!f(e)||t.snapshot!==e)||!(null===t.identifier||!t.identifierAttribute||!l(e)||e[t.identifierAttribute]!==t.identifier)}function ct(t){switch(typeof t){case"string":return Mt;case"number":return $t;case"boolean":return Lt;case"object":if(t instanceof Date)return Jt}return o("Cannot determine primitive type from value "+t)}function lt(t,e){return new Bt(t,e)}function ft(){return W(this).toString()}function ht(t){return Object.keys(t).reduce(function(t,e){if(e in Yt)return o("Hook '"+e+"' was defined as property. Hooks should be defined as part of the actions");var n=Object.getOwnPropertyDescriptor(t,e);"get"in n&&o("Getters are not supported as properties. Please use views instead");var r=n.value;if(null===r)o("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,(i={},i[e]=lt(ct(r),r),i));if(_(r))return t;o("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 i},t)}function dt(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var r=_(t)?null:t,i=_(t)?e.concat(t):e,o="("+i.map(function(t){return t.name}).join(" | ")+")";return new Qt(o,i,r)}function yt(t){return new Xt(t)}function vt(t){return bt(t.name,t)}function bt(t,e){var n=function(){function r(e,r,o){e.$mst_middleware=n.$mst_middleware,F({name:t,type:r,id:i,args:[o],tree:a.tree,context:a.context,parentId:a.id,rootId:a.rootId},e)}var i=k(),a=M(),s=arguments;return new Promise(function(u,p){function c(t){var e;try{r(function(t){e=h.next(t)},"flow_resume",t)}catch(t){return void setImmediate(function(){r(function(e){p(t)},"flow_throw",t)})}f(e)}function l(t){var e;try{r(function(t){e=h.throw(t)},"flow_resume_error",t)}catch(t){return void setImmediate(function(){r(function(e){p(t)},"flow_throw",t)})}f(e)}function f(t){if(!t.done)return t.value&&"function"==typeof t.value.then||o("Only promises can be yielded to `async`, got: "+t),t.value.then(c,l);setImmediate(function(){r(function(t){u(t)},"flow_return",t.value)})}var h,d=function(){h=e.apply(null,arguments),c(void 0)};d.$mst_middleware=n.$mst_middleware,F({name:t,type:"flow_spawn",id:i,args:g(s),tree:a.tree,context:a.context,parentId:a.id,rootId:a.rootId},d)})};return n}function mt(t,e,n,r){if(r instanceof Date)return{$MST_DATE:r.getTime()};if(h(r))return r;if(J(r))return wt("[MSTNode: "+x(r).name+"]");if("function"==typeof r)return wt("[function]");if("object"==typeof r&&!l(r)&&!u(r))return wt("[object "+(r&&r.constructor&&r.constructor.name||"Complex Object")+"]");try{return JSON.stringify(r),r}catch(t){return wt(""+t)}}function gt(t,e){return e&&"object"==typeof e&&"$MST_DATE"in e?new Date(e.$MST_DATE):e}function wt(t){return{$MST_UNSERIALIZABLE:!0,type:t}}function Pt(t,n){e.runInAction(function(){p(n).forEach(function(e){return Vt(t,e)})})}function Vt(t,e){var n=R(t,e.path||"");if(!n)return o("Invalid action path: "+(e.path||""));var r=W(n);return"@APPLY_PATCHES"===e.name?I.call(null,n,e.args[0]):"@APPLY_SNAPSHOT"===e.name?D.call(null,n,e.args[0]):("function"!=typeof n[e.name]&&o("Action '"+e.name+"' does not exist in '"+r.path+"'"),n[e.name].apply(n,e.args?e.args.map(function(t){return gt(r,t)}):[]))}function At(t,e,n){function r(n){if("action"===n.type&&n.id===n.rootId){var r=W(n.context);e({name:n.name,path:W(t).getRelativePathTo(r),args:n.args.map(function(t,e){return mt(r,n.name,e,t)})})}}return void 0===n&&(n=!1),L(t,n?function(t,e){var n=e(t);return r(t),n}:function(t,e){return r(t),e(t)})}var 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])},jt=Object.freeze([]),Tt=Object.freeze({}),_t=function(){};(_t=function(t,e){}).ids={};var Ct;!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"}(Ct||(Ct={}));var Ot=1,xt=null,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)&&o("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 o("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,o,u,p){void 0===u&&(u=a),void 0===p&&(p=s);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(o);var l=B(this.storedValue);this.applyPatches=$(this.storedValue,"@APPLY_PATCHES",function(t){t.forEach(function(t){var e=T(t.path);c.resolvePath(e.slice(0,-1)).applyPatchLocally(e[e.length-1],t)})}).bind(this.storedValue),this.applySnapshot=$(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&&y(this.storedValue,"$treenode",this);var f=!0;try{l&&y(this.storedValue,"toJSON",Y),this._isRunningAction=!0,p(this,o),this._isRunningAction=!1,n?n.root.identifierCache.addNodeToCache(this):this.identifierCache.addNodeToCache(this),this.fireHook("afterCreate"),n&&this.fireHook("afterAttach"),f=!1}finally{f&&(this._isAlive=!1)}var h=e.reaction(function(){return c.snapshot},function(t){c.emitSnapshot(t)});h.onError(function(t){throw t}),this.addDisposer(h)}return Object.defineProperty(t.prototype,"identifier",{get:function(){return this.identifierAttribute?this.storedValue[this.identifierAttribute]:null},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"path",{get:function(){return this.parent?this.parent.path+"/"+A(this.subpath):""},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isRoot",{get:function(){return null===this.parent},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"parent",{get:function(){return this._parent},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"root",{get:function(){for(var t,e=this;t=e.parent;)e=t;return e},enumerable:!0,configurable:!0}),t.prototype.getRelativePathTo=function(t){this.root!==t.root&&o("Cannot calculate relative path: objects '"+this+"' and '"+t+"' are not part of the same object tree");for(var e=T(this.path),n=T(t.path),r=0;r<e.length&&e[r]===n[r];r++);return e.slice(r).map(function(t){return".."}).join("/")+j(n.slice(r))},t.prototype.resolve=function(t,e){return void 0===e&&(e=!0),this.resolvePath(T(t),e)},t.prototype.resolvePath=function(t,e){void 0===e&&(e=!0);for(var n=this,r=0;r<t.length;r++){if(""===t[r])n=n.root;else if(".."===t[r])n=n.parent;else{if("."===t[r]||""===t[r])continue;if(n){n=n.getChildNode(t[r]);continue}}if(!n)return e?o("Could not resolve '"+t[r]+"' in '"+j(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||J(this.storedValue)&&(z(this.storedValue,function(t){return W(t).aboutToDie()}),z(this.storedValue,function(t){return W(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;v(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(){o("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||o(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 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){return m(this.patchSubscribers,t)},t.prototype.emitPatch=function(t,e){if(this.patchSubscribers.length){var n=w(c({},t,{path:e.path.substr(this.path.length)+"/"+t.path})),r=n[0],i=n[1];this.patchSubscribers.forEach(function(t){return t(r,i)})}this.parent&&this.parent.emitPatch(t,e)},t.prototype.setParent=function(t,e){void 0===e&&(e=null),this.parent===t&&this.subpath===e||(t&&(this._parent&&t!==this._parent&&o("A node cannot exists twice in the state tree. Failed to add "+this+" to path '"+t.path+"/"+e+"'."),this._parent||t.root!==this||o("A state tree is not allowed to contain itself. Cannot assign "+this+" to path '"+t.path+"/"+e+"'"),!this._parent&&this.root._environment&&this.root._environment!==t.root._environment&&o("A state tree cannot be made part of another state tree as long as their environments are different.")),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&&o("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||o("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]")},i([e.observable],t.prototype,"_parent",void 0),i([e.observable],t.prototype,"subpath",void 0),i([e.computed],t.prototype,"path",null),i([e.computed],t.prototype,"value",null),i([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()),nt(this,t),this.instantiate(null,"",e,t).value},t.prototype.isAssignableFrom=function(t){return t===this},t.prototype.validate=function(t,e){return J(t)?x(t)===this||this.isAssignableFrom(x(t))?X():tt(e,t):this.isValidSnapshot(t,e)},t.prototype.is=function(t){return 0===this.validate(t,[{path:"",type:this}]).length},t.prototype.reconcile=function(t,e){if(t.snapshot===e)return t;if(J(e)&&W(e)===t)return t;if(t.type===this&&f(e)&&!J(e)&&(!t.identifierAttribute||t.identifier===e[t.identifierAttribute]))return t.applySnapshot(e),t;var n=t.parent,r=t.subpath;if(t.die(),J(e)&&this.isAssignableFrom(x(e))){var i=W(e);return i.setParent(n,r),i}return this.instantiate(n,r,t._environment,e)},Object.defineProperty(t.prototype,"Type",{get:function(){return o("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 o("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}),i([e.action],t.prototype,"create",null),t}(),Rt=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){o("Immutable types do not support applying snapshots")},e.prototype.applyPatchLocally=function(t,e,n){o("Immutable types do not support applying patches")},e.prototype.getChildren=function(t){return jt},e.prototype.getChildNode=function(t,e){return o("No child '"+e+"' available in type: "+this.name)},e.prototype.getChildType=function(t){return o("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 o("No child '"+e+"' available in type: "+this.name)},e}(Et),zt=function(t){function r(n,r){var i=t.call(this,n)||this;return i.shouldAttachNode=!0,i.flags=Ct.Map,i.createNewInstance=function(){var t=e.observable.shallowMap();return y(t,"put",ot),y(t,"toString",it),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(r,t),r.prototype.instantiate=function(t,e,n,r){return q(this,t,e,n,r,this.createNewInstance,this.finalizeNewInstance)},r.prototype.describe=function(){return"Map<string, "+this.subType.describe()+">"},r.prototype.getChildren=function(t){return t.storedValue.values()},r.prototype.getChildNode=function(t,e){var n=t.storedValue.get(e);return n||o("Not a child "+e),n},r.prototype.willChange=function(t){var e=W(t.object);switch(e.assertWritable(),t.type){case"update":var n=t.newValue;if(n===t.object.get(t.name))return null;nt(this.subType,n),t.newValue=this.subType.reconcile(e.getChildNode(t.name),t.newValue),this.verifyIdentifier(t.name,t.newValue);break;case"add":nt(this.subType,t.newValue),t.newValue=this.subType.instantiate(e,t.name,void 0,t.newValue),this.verifyIdentifier(t.name,t.newValue)}return t},r.prototype.verifyIdentifier=function(t,e){var n=e.identifier;null!==n&&""+n!=""+t&&o("A map of objects containing an identifier should always store the object under their own identifier. Trying to store key '"+n+"', but expected: '"+t+"'")},r.prototype.getValue=function(t){return t.storedValue},r.prototype.getSnapshot=function(t){var e={};return t.getChildren().forEach(function(t){e[t.subpath]=t.snapshot}),e},r.prototype.didChange=function(t){var e=W(t.object);switch(t.type){case"update":return void e.emitPatch({op:"replace",path:A(t.name),value:t.newValue.snapshot,oldValue:t.oldValue?t.oldValue.snapshot:void 0},e);case"add":return void e.emitPatch({op:"add",path:A(t.name),value:t.newValue.snapshot,oldValue:void 0},e);case"delete":var n=t.oldValue.snapshot;return t.oldValue.die(),void e.emitPatch({op:"remove",path:A(t.name),oldValue:n},e)}},r.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)}},r.prototype.applySnapshot=function(t,e){nt(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)})},r.prototype.getChildType=function(t){return this.subType},r.prototype.isValidSnapshot=function(t,e){var n=this;return l(t)?et(Object.keys(t).map(function(r){return n.subType.validate(t[r],Q(e,r,n.subType))})):tt(e,t,"Value is not a plain object")},r.prototype.getDefaultSnapshot=function(){return{}},r.prototype.removeChild=function(t,e){t.storedValue.delete(e)},i([e.action],r.prototype,"applySnapshot",null),r}(Et),kt=function(t){function r(n,r){var i=t.call(this,n)||this;return i.shouldAttachNode=!0,i.flags=Ct.Array,i.createNewInstance=function(){var t=e.observable.shallowArray();return y(t,"toString",at),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(r,t),r.prototype.describe=function(){return this.subType.describe()+"[]"},r.prototype.instantiate=function(t,e,n,r){return q(this,t,e,n,r,this.createNewInstance,this.finalizeNewInstance)},r.prototype.getChildren=function(t){return t.storedValue.peek()},r.prototype.getChildNode=function(t,e){var n=parseInt(e,10);return n<t.storedValue.length?t.storedValue[n]:o("Not a child: "+e)},r.prototype.willChange=function(t){var e=W(t.object);e.assertWritable();var n=e.getChildren();switch(t.type){case"update":if(t.newValue===t.object[t.index])return null;t.newValue=st(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=st(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},r.prototype.getValue=function(t){return t.storedValue},r.prototype.getSnapshot=function(t){return t.getChildren().map(function(t){return t.snapshot})},r.prototype.didChange=function(t){var e=W(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}},r.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)}},r.prototype.applySnapshot=function(t,e){nt(this,e),t.storedValue.replace(e)},r.prototype.getChildType=function(t){return this.subType},r.prototype.isValidSnapshot=function(t,e){var n=this;return u(t)?et(t.map(function(t,r){return n.subType.validate(t,Q(e,""+r,n.subType))})):tt(e,t,"Value is not an array")},r.prototype.getDefaultSnapshot=function(){return[]},r.prototype.removeChild=function(t,e){t.storedValue.splice(parseInt(e,10),1)},i([e.action],r.prototype,"applySnapshot",null),r}(Et),Ft=function(t){function e(e,n,r,i){void 0===i&&(i=a);var o=t.call(this,e)||this;return o.flags=n,o.checker=r,o.initializer=i,o}return n(e,t),e.prototype.describe=function(){return this.name},e.prototype.instantiate=function(t,e,n,r){return q(this,t,e,n,r,this.initializer)},e.prototype.isValidSnapshot=function(t,e){return h(t)&&this.checker(t)?X():tt(e,t,"Value is not a "+("Date"===this.name?"Date or a unix milliseconds timestamp":this.name))},e}(Rt),Mt=new Ft("string",Ct.String,function(t){return"string"==typeof t}),$t=new Ft("number",Ct.Number,function(t){return"number"==typeof t}),Lt=new Ft("boolean",Ct.Boolean,function(t){return"boolean"==typeof t}),Ut=new Ft("null",Ct.Null,function(t){return null===t}),Ht=new Ft("undefined",Ct.Undefined,function(t){return void 0===t}),Jt=new Ft("Date",Ct.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=Ct.Identifier,n}return n(e,t),e.prototype.instantiate=function(t,e,n,r){return t&&J(t.storedValue)?(t.identifierAttribute&&o("Cannot define property '"+e+"' as object identifier, property '"+t.identifierAttribute+"' is already defined as identifier property"),t.identifierAttribute=e,q(this,t,e,n,r)):o("Identifier types can only be instantiated as direct child of a model type")},e.prototype.reconcile=function(t,e){return t.storedValue!==e?o("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):tt(e,t,"Value is not a valid identifier, which is a string or a number")},e}(Rt),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|Ct.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=J(i)?W(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&&nt(this,t),t},e.prototype.isValidSnapshot=function(t,e){return void 0===t?X():this.type.validate(t,e)},e.prototype.isAssignableFrom=function(t){return this.type.isAssignableFrom(t)},e}(Rt),Yt={afterCreate:"afterCreate",afterAttach:"afterAttach",postProcessSnapshot:"postProcessSnapshot",beforeDetach:"beforeDetach",beforeDestroy:"beforeDestroy"},qt={name:"AnonymousModel",properties:{},initializers:jt},Gt=function(t){function a(n){var r=t.call(this,n.name||qt.name)||this;r.flags=Ct.Object,r.createNewInstance=function(){var t=e.observable.shallowObject(Tt);return y(t,"toString",ft),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=W(t.object);e.emitPatch({op:"replace",path:A(t.name),value:t.newValue.snapshot,oldValue:t.oldValue?t.oldValue.snapshot:void 0},e)};var i=n.name||qt.name;return/^\w[\w\d_]*$/.test(i)||o("Typename should be a valid identifier: "+i),Object.assign(r,qt,n),r.properties=ht(r.properties),r.propertiesNames=Object.keys(r.properties),Object.freeze(r.properties),r}return n(a,t),a.prototype.cloneAndEnhance=function(t){return new a({name:t.name||this.name,properties:Object.assign({},this.properties,t.properties),initializers:this.initializers.concat(t.initializers||[]),preProcessor:t.preProcessor||this.preProcessor})},a.prototype.actions=function(t){var e=this;return this.cloneAndEnhance({initializers:[function(n){return e.instantiateActions(n,t(n)),n}]})},a.prototype.instantiateActions=function(t,e){l(e)||o("actions initializer should return a plain object containing actions"),Object.keys(e).forEach(function(n){if("preProcessSnapshot"===n)return o("Cannot define action 'preProcessSnapshot', it should be defined using 'type.preProcessSnapshot(fn)' instead");var r=e[n],i=t[n];if(n in Yt&&i){var a=r;r=n===Yt.postProcessSnapshot?function(t){return a(i(t))}:function(){i.apply(null,arguments),a.apply(null,arguments)}}y(t,n,$(t,n,r))})},a.prototype.named=function(t){return this.cloneAndEnhance({name:t})},a.prototype.props=function(t){return this.cloneAndEnhance({properties:t})},a.prototype.extend=function(t){var e=this;return this.cloneAndEnhance({initializers:[function(n){var i=t(n),a=i.actions,s=i.views,u=r(i,["actions","views"]);for(var p in u)o("The `extend` function should return an object with fields 'actions' and / or 'views'. Found invalid key '"+p+"'");return s&&e.instantiateViews(n,s),a&&e.instantiateActions(n,a),n}]})},a.prototype.views=function(t){var e=this;return this.cloneAndEnhance({initializers:[function(n){return e.instantiateViews(n,t(n)),n}]})},a.prototype.instantiateViews=function(t,n){l(n)||o("views initializer should return a plain object containing views"),Object.keys(n).forEach(function(r){var i=Object.getOwnPropertyDescriptor(n,r),a=i.value;if("get"in i)if(e.isComputed(t.$mobx.values[r]))t.$mobx.values[r]=e.computed(i.get,{name:r,setter:i.set,context:t});else{var s={};Object.defineProperty(s,r,{get:i.get,set:i.set,enumerable:!0}),e.extendShallowObservable(t,s)}else"function"==typeof a?y(t,r,a):o("A view member should either be a function or getter based property")})},a.prototype.preProcessSnapshot=function(t){var e=this.preProcessor;return e?this.cloneAndEnhance({preProcessor:function(n){return e(t(n))}}):this.cloneAndEnhance({preProcessor:t})},a.prototype.instantiate=function(t,e,n,r){return q(this,t,e,n,this.applySnapshotPreProcessor(r),this.createNewInstance,this.finalizeNewInstance)},a.prototype.willChange=function(t){var e=W(t.object),n=this.properties[t.name];return e.assertWritable(),nt(n,t.newValue),t.newValue=n.reconcile(e.getChildNode(t.name),t.newValue),t},a.prototype.getChildren=function(t){var e=this,n=[];return this.forAllProps(function(r,i){n.push(e.getChildNode(t,r))}),n},a.prototype.getChildNode=function(t,e){if(!(e in this.properties))return o("Not a value property: "+e);var n=t.storedValue.$mobx.values[e].value;return n||o("Node not available for property "+e)},a.prototype.getValue=function(t){return t.storedValue},a.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},a.prototype.applyPatchLocally=function(t,e,n){"replace"!==n.op&&"add"!==n.op&&o("object does not support operation "+n.op),t.storedValue[e]=n.value},a.prototype.applySnapshot=function(t,e){var n=this.applySnapshotPreProcessor(e);nt(this,n),this.forAllProps(function(e,r){t.storedValue[e]=n[e]})},a.prototype.applySnapshotPreProcessor=function(t){return this.preProcessor?this.preProcessor.call(null,t):t},a.prototype.getChildType=function(t){return this.properties[t]},a.prototype.isValidSnapshot=function(t,e){var n=this,r=this.applySnapshotPreProcessor(t);return l(r)?et(this.propertiesNames.map(function(t){return n.properties[t].validate(r[t],Q(e,t,n.properties[t]))})):tt(e,r,"Value is not a plain object")},a.prototype.forAllProps=function(t){var e=this;this.propertiesNames.forEach(function(n){return t(n,e.properties[n])})},a.prototype.describe=function(){var t=this;return"{ "+this.propertiesNames.map(function(e){return e+": "+t.properties[e].describe()}).join("; ")+" }"},a.prototype.getDefaultSnapshot=function(){return{}},a.prototype.removeChild=function(t,e){t.storedValue[e]=null},i([e.action],a.prototype,"applySnapshot",null),a}(Et),Zt=function(){return function(t,e){if(this.mode=t,this.value=e,"object"===t){if(!J(e))return o("Can only store references to tree nodes, got: '"+e+"'");if(!W(e).identifierAttribute)return o("Can only store references with a defined identifier attribute.")}}}(),Kt=function(t){function e(e){var n=t.call(this,"reference("+e.name+")")||this;return n.targetType=e,n.flags=Ct.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:o("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 W(e.value).identifier}},e.prototype.instantiate=function(t,e,n,r){var i=J(r);return q(this,t,e,n,new Zt(i?"object":"identifier",r))},e.prototype.reconcile=function(t,e){var n=J(e)?"object":"identifier";if(O(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?X():tt(e,t,"Value is not a valid identifier, which is a string or a number")},e}(Rt),Qt=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=Ct.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?o("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?tt(e,t,"Multiple types are applicable for the union (hint: provide a dispatch function)"):0===r.length?tt(e,t,"No type is applicable for the union").concat(et(n)):X()},e}(Rt),Xt=function(t){function e(e){var n=t.call(this,JSON.stringify(e))||this;return n.flags=Ct.Literal,n.value=e,n}return n(e,t),e.prototype.instantiate=function(t,e,n,r){return q(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?X():tt(e,t,"Value is not a literal "+JSON.stringify(this.value))},e}(Rt),te=new(function(t){function e(){var e=t.call(this,"frozen")||this;return e.flags=Ct.Frozen,e}return n(e,t),e.prototype.describe=function(){return"<any immutable value>"},e.prototype.instantiate=function(t,e,n,r){return q(this,t,e,n,r)},e.prototype.isValidSnapshot=function(t,e){return d(t)?X():tt(e,t,"Value is not serializable and cannot be frozen")},e}(Rt)),ee=lt(Ut,null),ne=function(t){function e(e,n,r,i){var o=t.call(this,e)||this;return o.type=n,o.predicate=r,o.message=i,o}return n(e,t),Object.defineProperty(e.prototype,"flags",{get:function(){return this.type.flags|Ct.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=J(t)?W(t).snapshot:t;return this.predicate(r)?X():tt(e,t,this.message(t))},e}(Rt),re=function(t){function e(e,n){var r=t.call(this,e)||this;return r._subType=null,r.definition=n,r}return n(e,t),Object.defineProperty(e.prototype,"flags",{get:function(){return this.subType.flags|Ct.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}(Rt),ie={enumeration:function(t,e){var n="string"==typeof t?e:t,r=dt.apply(void 0,n.map(function(t){return yt(""+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.cloneAndEnhance({name:t.name+"_"+e.name,properties:e.properties,initializers:e.initializers})}).named(n)},reference:function(t){return new Kt(t)},union:dt,optional:lt,literal:yt,maybe:function(t){return dt(ee,t)},refinement:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n="string"==typeof t[0]?t.shift():_(t[0])?t[0].name:null,r=t[0],i=t[1],o=t[2]?t[2]:function(t){return"Value does not respect the refinement predicate"};return new ne(n,r,i,o)},string:Mt,boolean:Lt,number:$t,Date:Jt,map:function(t){return new zt("map<string, "+t.name+">",t)},array:function(t){return new kt(t.name+"[]",t)},frozen:te,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 re(n,"string"==typeof t?e:t)},undefined:Ht,null:Ut},oe="See https://github.com/mobxjs/mobx-state-tree/issues/399 for more information. Note that the middleware event types starting with `process` now start with `flow`.";t.types=ie,t.typecheck=rt,t.escapeJsonPath=A,t.unescapeJsonPath=S,t.decorate=function(t,e){return e.$mst_middleware?e.$mst_middleware.push(t):e.$mst_middleware=[t],e},t.addMiddleware=L,t.flow=vt,t.process=function(t){return _t("process","`process()` has been renamed to `flow()`. "+oe),vt(t)},t.isStateTreeNode=J,t.applyAction=Pt,t.onAction=At,t.recordActions=function(t){var e={actions:[],stop:function(){return n()},replay:function(t){Pt(t,e.actions)}},n=At(t,e.actions.push.bind(e.actions));return e},t.createActionTrackingMiddleware=function(t){var e=new Map;return function(n,r){switch(n.type){case"action":if(t.filter&&!0!==t.filter(n))return r(n);var i=t.onStart(n);t.onResume(n,i),e.set(n.id,{call:n,context:i,async:!1});try{var o=r(n);return t.onSuspend(n,i),!1===e.get(n.id).async&&t.onSuccess(n,i,o),o}catch(e){throw t.onFail(n,i,e),e}case"flow_spawn":return(a=e.get(n.rootId)).async=!0,r(n);case"flow_resume":case"flow_resume_error":a=e.get(n.rootId),t.onResume(n,a.context);try{return r(n)}finally{t.onSuspend(n,a.context)}case"flow_throw":return a=e.get(n.rootId),e.delete(n.id),t.onFail(n,a.context,n.args[0]),r(n);case"flow_return":var a=e.get(n.rootId);return e.delete(n.id),t.onSuccess(n,a.context,n.args[0]),r(n)}}},t.getType=x,t.getChildType=function(t,e){return W(t).getChildType(e)},t.onPatch=N,t.onSnapshot=function(t,e){return W(t).onSnapshot(e)},t.applyPatch=I,t.recordPatches=function(t){function e(){n||(n=N(t,function(t,e){r.rawPatches.push([t,e])}))}var n=null,r={rawPatches:[],get patches(){return this.rawPatches.map(function(t){return t[0]})},get inversePatches(){return this.rawPatches.map(function(t){return t[0],t[1]})},stop:function(){n&&n(),n=null},resume:e,replay:function(e){I(e||t,r.patches)},undo:function(e){I(e||t,r.inversePatches.slice().reverse())}};return e(),r},t.protect=function(t){var e=W(t);e.isRoot||o("`protect` can only be invoked on root nodes"),e.isProtectionEnabled=!0},t.unprotect=function(t){var e=W(t);e.isRoot||o("`unprotect` can only be invoked on root nodes"),e.isProtectionEnabled=!1},t.isProtected=function(t){return W(t).isProtected},t.applySnapshot=D,t.getSnapshot=function(t){return W(t).snapshot},t.hasParent=function(t,e){void 0===e&&(e=1);for(var n=W(t).parent;n;){if(0==--e)return!0;n=n.parent}return!1},t.getParent=function(t,e){void 0===e&&(e=1);for(var n=e,r=W(t).parent;r;){if(0==--n)return r.storedValue;r=r.parent}return o("Failed to find the parent of "+W(t)+" at depth "+e)},t.getRoot=E,t.getPath=function(t){return W(t).path},t.getPathParts=function(t){return T(W(t).path)},t.isRoot=function(t){return W(t).isRoot},t.resolvePath=function(t,e){var n=W(t).resolve(e);return n?n.value:void 0},t.resolveIdentifier=function(t,e,n){var r=W(e).root.identifierCache.resolve(t,""+n);return r?r.value:void 0},t.tryResolve=R,t.getRelativePath=function(t,e){return W(t).getRelativePathTo(W(e))},t.clone=function(t,e){void 0===e&&(e=!0);var n=W(t);return n.type.create(n.snapshot,!0===e?n.root._environment:!1===e?void 0:e)},t.detach=function(t){return W(t).detach(),t},t.destroy=function(t){var e=W(t);e.isRoot?e.die():e.parent.removeChild(e.subpath)},t.isAlive=function(t){return W(t).isAlive},t.addDisposer=function(t,e){W(t).addDisposer(e)},t.getEnv=function(t){var e=W(t).root._environment;return e||Tt},t.walk=z,Object.defineProperty(t,"__esModule",{value:!0})}); |
@@ -44,2 +44,3 @@ import { IObservableArray, IArrayWillChange, IArrayWillSplice, IArrayChange, IArraySplice } from "mobx"; | ||
* const s = TodoStore.create({ todos: [] }) | ||
* unprotect(s) // needed to allow modifying outside of an action | ||
* s.todos.push({ task: "Grab coffee" }) | ||
@@ -46,0 +47,0 @@ * console.log(s.todos[0]) // prints: "Grab coffee" |
import { IType, IComplexType } from "./type"; | ||
import { CoreType } from "./primitives"; | ||
import { IExtendedObservableMap } from "./complex-types/map"; | ||
import { ObjectType } from "./complex-types/object"; | ||
import { ModelType } from "./complex-types/model"; | ||
import { IdentifierType } from "./utility-types/identifier"; | ||
@@ -39,3 +39,3 @@ import { ReferenceType } from "./utility-types/reference"; | ||
}, IExtendedObservableMap<T>>; | ||
export declare function isObjectType(type: any): type is ObjectType<any, any>; | ||
export declare function isObjectType(type: any): type is ModelType<any, any>; | ||
export declare function isFrozenType(type: any): type is Frozen<any>; | ||
@@ -42,0 +42,0 @@ export declare function isIdentifierType(type: any): type is IdentifierType<any>; |
@@ -25,3 +25,3 @@ import { ISimpleType, Type } from "../type"; | ||
* | ||
* const hero = new GameCharacter({ | ||
* const hero = GameCharacter.create({ | ||
* name: "Mario", | ||
@@ -28,0 +28,0 @@ * location: { x: 7, y: 4 } |
@@ -31,1 +31,8 @@ export declare const EMPTY_ARRAY: ReadonlyArray<any>; | ||
export declare function argsToArray(args: IArguments): any[]; | ||
export declare type DeprecatedFunction = Function & { | ||
ids?: { | ||
[id: string]: true; | ||
}; | ||
}; | ||
declare let deprecated: DeprecatedFunction; | ||
export { deprecated }; |
{ | ||
"name": "mobx-state-tree", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Opinionated, transactional, MobX powered state container", | ||
@@ -21,8 +21,5 @@ "main": "dist/mobx-state-tree.js", | ||
"coverage": "npm run build-tests && nyc ava && nyc report -r html && nyc report -r lcov", | ||
"build-docs": "npm run quick-build && documentation build lib/index.js --sort-order alpha -f md -o API.md.tmp && concat -o API.md docs/API_header.md API.md.tmp && rm API.md.tmp", | ||
"build-docs": "npm run quick-build && documentation build lib/index.js --sort-order alpha -f md -o ../../API.md.tmp && concat -o ../../API.md ../../docs/API_header.md ../../API.md.tmp && rm ../../API.md.tmp", | ||
"lint": "tslint -c tslint.json 'src/**/*.ts'", | ||
"clean": "rm -rf lib test-lib .nyc_output coverage", | ||
"precommit": "lint-staged", | ||
"example-tests": "yarn run build && cd examples/boxes && yarn install && npm install ../../ && CI=true yarn jest && cd ../bookshop && yarn install && npm install ../../ && CI=true yarn test && cd ../redux-todomvc && yarn install && npm install ../../ && CI=true yarn test", | ||
"middleware-tests": "cd middleware && yarn test" | ||
"clean": "rm -rf lib test-lib .nyc_output coverage" | ||
}, | ||
@@ -39,4 +36,3 @@ "repository": { | ||
"files": [ | ||
"dist/", | ||
"middleware/" | ||
"dist/" | ||
], | ||
@@ -51,7 +47,4 @@ "devDependencies": { | ||
"documentation": "^5.2.2", | ||
"husky": "^0.13.4", | ||
"lint-staged": "^3.6.1", | ||
"mobx": "^3.2.2", | ||
"nyc": "^10.0.0", | ||
"prettier": "^1.4.4", | ||
"rollup": "^0.43.0", | ||
@@ -88,9 +81,3 @@ "rollup-plugin-commonjs": "^8.0.2", | ||
] | ||
}, | ||
"lint-staged": { | ||
"*.{ts,tsx,js,jsx}": [ | ||
"prettier --write --print-width 100 --tab-width 4 --no-semi", | ||
"git add" | ||
] | ||
} | ||
} | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
20
9447
572197
34
1
0
88