Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mobx-state-tree

Package Overview
Dependencies
Maintainers
2
Versions
129
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mobx-state-tree - npm Package Compare versions

Comparing version 1.3.1 to 1.4.0

dist/types/utility-types/custom.d.ts

8

dist/core/action.d.ts

@@ -13,3 +13,7 @@ import { IStateTreeNode, IDisposer } from "../internal";

};
export declare type IMiddlewareHandler = (actionCall: IMiddlewareEvent, next: (actionCall: IMiddlewareEvent) => any) => any;
export declare type IMiddleware = {
handler: IMiddlewareHandler;
includeHooks: boolean;
};
export declare type IMiddlewareHandler = (actionCall: IMiddlewareEvent, next: (actionCall: IMiddlewareEvent, callback?: (value: any) => any) => void, abort: (value: any) => void) => any;
export declare function getNextActionId(): number;

@@ -30,3 +34,3 @@ export declare function runWithActionContext(context: IMiddlewareEvent, fn: Function): any;

*/
export declare function addMiddleware(target: IStateTreeNode, middleware: IMiddlewareHandler): IDisposer;
export declare function addMiddleware(target: IStateTreeNode, handler: IMiddlewareHandler, includeHooks?: boolean): IDisposer;
export declare function decorate<T extends Function>(middleware: IMiddlewareHandler, fn: T): T;

@@ -135,3 +135,3 @@ import { IObservableArray, ObservableMap } from "mobx";

export declare function getSnapshot<S>(target: IObservableArray<S>): S[];
export declare function getSnapshot<S>(target: ISnapshottable<S>): S;
export declare function getSnapshot<S = any>(target: ISnapshottable<S>): S;
/**

@@ -196,4 +196,12 @@ * Given a model instance, returns `true` if the object has a parent, that is, is part of another object, map or array

/**
* Returns the identifier of the target node.
*
* @export
* @param {IStateTreeNode} target
* @returns {(string | null)}
*/
export declare function getIdentifier(target: IStateTreeNode): string | null;
/**
*
*
* @export

@@ -287,2 +295,19 @@ * @param {Object} target

export declare function walk(target: IStateTreeNode, processor: (item: IStateTreeNode) => void): void;
export interface IModelReflectionData {
name: string;
properties: {
[K: string]: IType<any, any>;
};
actions: string[];
views: string[];
volatile: string[];
}
/**
* Returns a reflection of the node
*
* @export
* @param {IStateTreeNode} target
* @returns {IModelReflectionData}
*/
export declare function getMembers(target: IStateTreeNode): IModelReflectionData;
import { IStateTreeNode, IJsonPatch, IDisposer, ISnapshottable, IType } from "../internal";

@@ -27,2 +27,10 @@ import { IType, ObjectNode } from "../../internal";

};
export interface IMembers {
properties: {
[name: string]: IType<any, any>;
};
actions: Object;
views: Object;
volatile: Object;
}
/**

@@ -29,0 +37,0 @@ * Returns true if the given value is a node in a state tree.

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

import { INode, IJsonPatch, IReversibleJsonPatch, IType, IDisposer, IMiddlewareHandler, NodeLifeCycle, IdentifierCache } from "../../internal";
import { INode, IJsonPatch, IReversibleJsonPatch, IType, IDisposer, IMiddleware, IMiddlewareHandler, NodeLifeCycle, IdentifierCache } from "../../internal";
export declare class ObjectNode implements INode {

@@ -15,3 +15,3 @@ nodeId: number;

state: NodeLifeCycle;
middlewares: IMiddlewareHandler[];
middlewares: IMiddleware[];
private snapshotSubscribers;

@@ -54,4 +54,5 @@ private patchSubscribers;

addDisposer(disposer: () => void): void;
addMiddleWare(handler: IMiddlewareHandler): IDisposer;
removeMiddleware(handler: IMiddlewareHandler): void;
addMiddleWare(handler: IMiddlewareHandler, includeHooks?: boolean): () => void;
applyPatchLocally(subpath: string, patch: IJsonPatch): void;
}

@@ -49,3 +49,5 @@ import { IContext, IValidationResult, INode, IStateTreeNode, IJsonPatch, ObjectNode } from "../../internal";

export interface IComplexType<S, T> extends IType<S, T & IStateTreeNode> {
create(snapshot?: S, environment?: any): T & ISnapshottable<S>;
create(snapshot?: S, environment?: any): T & {
toJSON?(): S;
} & ISnapshottable<S>;
}

@@ -52,0 +54,0 @@ export declare abstract class ComplexType<S, T> implements IType<S, T> {

@@ -1,5 +0,1 @@

/**
* All imports / exports should be proxied through this file.
* Why? It gives us full control over the module load order, preventing circular dependency isses
*/
export * from "./core/mst-operations";

@@ -34,1 +30,2 @@ export * from "./core/node/scalar-node";

export * from "./types/utility-types/identifier";
export * from "./types/utility-types/custom";

@@ -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){return F(t).type}function r(t,e){return F(t).onPatch(e)}function i(t,e){F(t).applyPatches(W(e))}function o(t,e){return F(t).applySnapshot(e)}function a(t){return F(t).root.storedValue}function s(t,e){var n=$(F(t),e,!1);if(void 0!==n)return n?n.value:void 0}function u(t,e){var n=F(t);n.getChildren().forEach(function(t){k(t.storedValue)&&u(t.storedValue,e)}),e(n.storedValue)}function p(t,e){function n(){this.constructor=t}Ct(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}function c(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 l(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 h(t){return"object"==typeof t&&t&&!0===t.isType}function f(t,e,r,i){if(i instanceof Date)return{$MST_DATE:i.getTime()};if(K(i))return i;if(k(i))return y("[MSTNode: "+n(i).name+"]");if("function"==typeof i)return y("[function]");if("object"==typeof i&&!Y(i)&&!G(i))return y("[object "+(i&&i.constructor&&i.constructor.name||"Complex Object")+"]");try{return JSON.stringify(i),i}catch(t){return y(""+t)}}function d(t,e){return e&&"object"==typeof e&&"$MST_DATE"in e?new Date(e.$MST_DATE):e}function y(t){return{$MST_UNSERIALIZABLE:!0,type:t}}function b(t,n){e.runInAction(function(){W(n).forEach(function(e){return v(t,e)})})}function v(t,e){var n=s(t,e.path||"");if(!n)return H("Invalid action path: "+(e.path||""));var r=F(n);return"@APPLY_PATCHES"===e.name?i.call(null,n,e.args[0]):"@APPLY_SNAPSHOT"===e.name?o.call(null,n,e.args[0]):("function"!=typeof n[e.name]&&H("Action '"+e.name+"' does not exist in '"+r.path+"'"),n[e.name].apply(n,e.args?e.args.map(function(t){return d(r,t)}):[]))}function m(t,e,n){function r(n){if("action"===n.type&&n.id===n.rootId){var r=F(n.context);e({name:n.name,path:M(F(t),r),args:n.args.map(function(t,e){return f(r,n.name,e,t)})})}}return void 0===n&&(n=!1),P(t,n?function(t,e){var n=e(t);return r(t),n}:function(t,e){return r(t),e(t)})}function g(){return Et++}function w(t,e){var n=F(t.context),r=n._isRunningAction,i=Rt;n.assertAlive(),n._isRunningAction=!0,Rt=t;try{return j(n,t,e)}finally{Rt=i,n._isRunningAction=r}}function A(){return Rt||H("Not running an action!")}function V(t,e,n){return function(){var r=g();return w({type:"action",name:e,id:r,args:rt(arguments),context:t,tree:a(t),rootId:Rt?Rt.rootId:r,parentId:Rt?Rt.id:0},n)}}function P(t,e){return F(t).addMiddleWare(e)}function S(t,e,n){for(var r=n.$mst_middleware||Lt,i=t;i;)i.middlewares&&(r=r.concat(i.middlewares)),i=i.parent;return r}function j(t,n,r){function i(t){var s=o[a++];return s?s(t,i):e.action(r).apply(null,n.args)}var o=S(t,n,r);if(!o.length)return e.action(r).apply(null,n.args);var a=0;return i(n)}function T(t){try{return JSON.stringify(t)}catch(t){return"<Unserializable: "+t+">"}}function C(t){return"function"==typeof t?"<function"+(t.name?" "+t.name:"")+">":k(t)?"<"+t+">":"`"+T(t)+"`"}function N(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=k(e)?"value of type "+F(e).type.name+":":K(e)?"value":"snapshot",a=n&&k(e)&&n.is(F(e).snapshot);return""+i+o+" "+C(e)+" is not assignable "+(n?"to type: `"+n.name+"`":"")+(t.message?" ("+t.message+")":"")+(n?Vt(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 O(t,e,n){return t.concat([{path:e,type:n}])}function _(){return Lt}function I(t,e,n){return[{context:t,value:e,message:n}]}function x(t){return t.reduce(function(t,e){return t.concat(e)},[])}function D(t,e){}function E(t,e){var n=t.validate(e,[{path:"",type:t}]);n.length>0&&H("Error while converting "+C(e)+" to `"+t.name+"`:\n"+n.map(N).join("\n"))}function R(t,e,n,r,i,o,a){if(void 0===o&&(o=J),void 0===a&&(a=Z),k(i)){var s=i.$treenode;return s.isRoot||H("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 '"+s.path+"'"),s.setParent(e,n),s}var u=o(i);if(t.shouldAttachNode){var p=new _t(t,e,n,r,i,u,t.shouldAttachNode,a);return p.finalizeCreation(),p}return new Nt(t,e,n,r,i,u,t.shouldAttachNode,a)}function z(t){return t instanceof Nt||t instanceof _t}function k(t){return!(!t||!t.$treenode)}function F(t){return k(t)?t.$treenode:H("Value "+t+" is no MST Node")}function L(){return F(this).snapshot}function M(t,e){t.root!==e.root&&H("Cannot calculate relative path: objects '"+t+"' and '"+e+"' are not part of the same object tree");for(var n=ht(t.path),r=ht(e.path),i=0;i<n.length&&n[i]===r[i];i++);return n.slice(i).map(kt).join("/")+lt(r.slice(i))}function $(t,e,n){return void 0===n&&(n=!0),U(t,ht(e),n)}function U(t,e,n){void 0===n&&(n=!0);for(var r=t,i=0;i<e.length;i++){if(""===e[i])r=r.root;else if(".."===e[i])r=r.parent;else{if("."===e[i]||""===e[i])continue;if(r){if(!(r instanceof _t))return H("Illegal state");r=r.getChildNode(e[i]);continue}}if(!r)return n?H("Could not resolve '"+e[i]+"' in '"+lt(e.slice(0,i-1))+"', path of the patch does not resolve"):void 0}return r}function H(t){throw void 0===t&&(t="Illegal state"),new Error("[mobx-state-tree] "+t)}function J(t){return t}function Z(){}function G(t){return!(!Array.isArray(t)&&!e.isObservableArray(t))}function W(t){return t?G(t)?t:[t]:Lt}function B(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 Y(t){if(null===t||"object"!=typeof t)return!1;var e=Object.getPrototypeOf(t);return e===Object.prototype||null===e}function q(t){return!(null===t||"object"!=typeof t||t instanceof Date||t instanceof RegExp)}function K(t){return null===t||void 0===t||("string"==typeof t||"number"==typeof t||"boolean"==typeof t||t instanceof Date)}function Q(t){return"function"!=typeof t}function X(t,e,n){Object.defineProperty(t,e,{enumerable:!1,writable:!1,configurable:!0,value:n})}function tt(t,e,n){Object.defineProperty(t,e,{enumerable:!0,writable:!1,configurable:!0,value:n})}function et(t,e){var n=t.indexOf(e);-1!==n&&t.splice(n,1)}function nt(t,e){return t.push(e),function(){et(t,e)}}function rt(t){for(var e=new Array(t.length),n=0;n<t.length;n++)e[n]=t[n];return e}function it(t){return ot(t.name,t)}function ot(t,e){var n=function(){function r(e,r,a){e.$mst_middleware=n.$mst_middleware,w({name:t,type:r,id:i,args:[a],tree:o.tree,context:o.context,parentId:o.id,rootId:o.rootId},e)}var i=g(),o=A(),a=arguments;return new Promise(function(s,u){function p(t){var e;try{r(function(t){e=h.next(t)},"flow_resume",t)}catch(t){return void setImmediate(function(){r(function(e){u(t)},"flow_throw",t)})}l(e)}function c(t){var e;try{r(function(t){e=h.throw(t)},"flow_resume_error",t)}catch(t){return void setImmediate(function(){r(function(e){u(t)},"flow_throw",t)})}l(e)}function l(t){if(!t.done)return t.value&&"function"==typeof t.value.then||H("Only promises can be yielded to `async`, got: "+t),t.value.then(p,c);setImmediate(function(){r(function(t){s(t)},"flow_return",t.value)})}var h,f=function(){h=e.apply(null,arguments),p(void 0)};f.$mst_middleware=n.$mst_middleware,w({name:t,type:"flow_spawn",id:i,args:rt(a),tree:o.tree,context:o.context,parentId:o.id,rootId:o.rootId},f)})};return n}function at(t){return"oldValue"in t||H("Patches without `oldValue` field cannot be inversed"),[st(t),ut(t)]}function st(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 ut(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 pt(t){return t.replace(/~/g,"~1").replace(/\//g,"~0")}function ct(t){return t.replace(/~0/g,"/").replace(/~1/g,"~")}function lt(t){return 0===t.length?"":"/"+t.map(pt).join("/")}function ht(t){var e=t.split("/").map(ct);return""===e[0]?e.slice(1):e}function ft(){return F(this)+"("+this.size+" items)"}function dt(t){t||H("Map.put cannot be used to set empty values");var e;if(k(t))e=F(t);else{if(!q(t))return H("Map.put can only be used to store complex values");e=F(F(this).type.subType.create(t))}return e.identifierAttribute||H("Map.put can only be used to store complex values that have an identifier type attribute"),this.set(e.identifier,e.value),this}function yt(){return F(this)+"("+this.length+" items)"}function bt(t,e,n,r,i){for(var o,a,s=!1,u=void 0,p=0;s=p<=r.length-1,o=n[p],a=s?r[p]:void 0,z(a)&&(a=a.storedValue),o||s;p++)if(s)if(o)if(mt(o,a))n[p]=vt(e,t,""+i[p],a,o);else{u=void 0;for(var c=p;c<n.length;c++)if(mt(n[c],a)){u=n.splice(c,1)[0];break}n.splice(p,0,vt(e,t,""+i[p],a,u))}else k(a)&&F(a).parent===t&&H("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[p]+"', but it lives already at '"+F(a).path+"'"),n.splice(p,0,vt(e,t,""+i[p],a));else o.die(),n.splice(p,1),p--;return n}function vt(t,e,n,r,i){if(D(t,r),k(r)){var o=F(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 mt(t,e){return k(e)?F(e)===t:!(!q(e)||t.snapshot!==e)||!!(t instanceof _t&&null!==t.identifier&&t.identifierAttribute&&Y(e)&&e[t.identifierAttribute]===t.identifier)}function gt(){return F(this).toString()}function wt(t){return Object.keys(t).reduce(function(t,e){if(e in Jt)return H("Hook '"+e+"' was defined as property. Hooks should be defined as part of the actions");var n=Object.getOwnPropertyDescriptor(t,e);"get"in n&&H("Getters are not supported as properties. Please use views instead");var r=n.value;if(null===r)H("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(K(r))return Object.assign({},t,(i={},i[e]=jt(At(r),r),i));if(h(r))return t;H("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 At(t){switch(typeof t){case"string":return Bt;case"number":return Yt;case"boolean":return qt;case"object":if(t instanceof Date)return Xt}return H("Cannot determine primitive type from value "+t)}function Vt(t){return h(t)&&(t.flags&(Tt.String|Tt.Number|Tt.Boolean|Tt.Date))>0}function Pt(t){return new te(t)}function St(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var r=h(t)?null:t,i=h(t)?e.concat(t):e,o="("+i.map(function(t){return t.name}).join(" | ")+")";return new ne(o,i,r)}function jt(t,e){return new re(t,e)}var Tt,Ct=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])},Nt=function(){function t(t,e,n,r,i,o,a,s){void 0===s&&(s=Z),this.subpath="",this._environment=void 0,this._autoUnbox=!0,this.state=It.INITIALIZING,this.type=t,this.storedValue=o,this._parent=e,this.subpath=n,this.storedValue=o,this._environment=r,this.unbox=this.unbox.bind(this),a&&X(this.storedValue,"$treenode",this);var u=!0;try{a&&X(this.storedValue,"toJSON",L),s(this,i),this.state=It.CREATED,u=!1}finally{u&&(this.state=It.DEAD)}}return Object.defineProperty(t.prototype,"path",{get:function(){return this.parent?this.parent.path+"/"+pt(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(){return this._parent?this._parent.root:H("This scalar node is not part of a tree")},enumerable:!0,configurable:!0}),t.prototype.setParent=function(t,e){void 0===e&&(e=null),this.parent!==t&&H("Cannot change parent of immutable node"),this.subpath!==e&&(this.subpath=e||"")},Object.defineProperty(t.prototype,"value",{get:function(){return this.type.getValue(this)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"snapshot",{get:function(){return this.type.getSnapshot(this)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isAlive",{get:function(){return this.state!==It.DEAD},enumerable:!0,configurable:!0}),t.prototype.unbox=function(t){return t&&!0===this._autoUnbox?t.value:t},t.prototype.toString=function(){return this.type.name+"@"+(this.path||"<root>")+(this.isAlive?"":"[dead]")},t.prototype.die=function(){this.state=It.DEAD},l([e.observable],t.prototype,"subpath",void 0),t}(),Ot=1,_t=function(){function t(t,n,r,i,o,a,s,u){void 0===u&&(u=Z);var p=this;this.nodeId=++Ot,this.subpath="",this._parent=null,this._isRunningAction=!1,this.isProtectionEnabled=!0,this.identifierAttribute=void 0,this._environment=void 0,this._autoUnbox=!0,this.state=It.INITIALIZING,this.middlewares=Lt,this.type=t,this.storedValue=a,this._parent=n,this.subpath=r,this._environment=i,this.unbox=this.unbox.bind(this),this.preboot(),n||(this.identifierCache=new zt),s&&X(this.storedValue,"$treenode",this);var c=!0;try{s&&X(this.storedValue,"toJSON",L),this._isRunningAction=!0,u(this,o),this._isRunningAction=!1,n?n.root.identifierCache.addNodeToCache(this):this.identifierCache.addNodeToCache(this),this.fireHook("afterCreate"),this.state=It.CREATED,c=!1}finally{c&&(this.state=It.DEAD)}var l=e.reaction(function(){return p.snapshot},function(t){p.emitSnapshot(t)});l.onError(function(t){throw t}),this.addDisposer(l)}return Object.defineProperty(t.prototype,"path",{get:function(){return this.parent?this.parent.path+"/"+pt(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.setParent=function(t,e){void 0===e&&(e=null),this.parent===t&&this.subpath===e||(t&&(this._parent&&t!==this._parent&&H("A node cannot exists twice in the state tree. Failed to add "+this+" to path '"+t.path+"/"+e+"'."),this._parent||t.root!==this||H("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&&H("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.fireHook=function(t){var e=this.storedValue&&"object"==typeof this.storedValue&&this.storedValue[t];"function"==typeof e&&e.apply(this.storedValue)},Object.defineProperty(t.prototype,"value",{get:function(){if(this.isAlive)return this.type.getValue(this)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"snapshot",{get:function(){if(this.isAlive)return this.type.getSnapshot(this)},enumerable:!0,configurable:!0}),t.prototype.isRunningAction=function(){return!!this._isRunningAction||!this.isRoot&&this.parent.isRunningAction()},Object.defineProperty(t.prototype,"identifier",{get:function(){return this.identifierAttribute?this.storedValue[this.identifierAttribute]:null},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isAlive",{get:function(){return this.state!==It.DEAD},enumerable:!0,configurable:!0}),t.prototype.assertAlive=function(){this.isAlive||H(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")},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&&H("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.unbox=function(t){return t&&!0===this._autoUnbox?t.value:t},t.prototype.toString=function(){var t=this.identifier?"(id: "+this.identifier+")":"";return this.type.name+"@"+(this.path||"<root>")+t+(this.isAlive?"":"[dead]")},t.prototype.finalizeCreation=function(){if(this.state===It.CREATED){if(this.parent){if(this.parent.state!==It.FINALIZED)return;this.fireHook("afterAttach")}this.state=It.FINALIZED;for(var e=0,n=this.getChildren();e<n.length;e++){var r=n[e];r instanceof t&&r.finalizeCreation()}}},t.prototype.detach=function(){this.isAlive||H("Error while detaching, node is not alive."),this.isRoot||(this.fireHook("beforeDetach"),this._environment=this.root._environment,this.state=It.DETACHING,this.identifierCache=this.root.identifierCache.splitCache(this),this.parent.removeChild(this.subpath),this._parent=null,this.subpath="",this.state=It.FINALIZED)},t.prototype.preboot=function(){var t=this;this.disposers=[],this.middlewares=[],this.snapshotSubscribers=[],this.patchSubscribers=[],this.applyPatches=V(this.storedValue,"@APPLY_PATCHES",function(e){e.forEach(function(e){var n=ht(e.path);U(t,n.slice(0,-1)).applyPatchLocally(n[n.length-1],e)})}).bind(this.storedValue),this.applySnapshot=V(this.storedValue,"@APPLY_SNAPSHOT",function(e){if(e!==t.snapshot)return t.type.applySnapshot(t,e)}).bind(this.storedValue)},t.prototype.die=function(){this.state!==It.DETACHING&&k(this.storedValue)&&(u(this.storedValue,function(e){var n=F(e);n instanceof t&&n.aboutToDie()}),u(this.storedValue,function(e){var n=F(e);n instanceof t&&n.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;tt(this,"snapshot",this.snapshot),this.patchSubscribers.splice(0),this.snapshotSubscribers.splice(0),this.patchSubscribers.splice(0),this.state=It.DEAD,this._parent=null,this.subpath="",Object.defineProperty(this.storedValue,"$mobx",{get:function(){H("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.onSnapshot=function(t){return nt(this.snapshotSubscribers,t)},t.prototype.emitSnapshot=function(t){this.snapshotSubscribers.forEach(function(e){return e(t)})},t.prototype.onPatch=function(t){return nt(this.patchSubscribers,t)},t.prototype.emitPatch=function(t,e){if(this.patchSubscribers.length){var n=at(B({},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.addDisposer=function(t){this.disposers.unshift(t)},t.prototype.addMiddleWare=function(t){return nt(this.middlewares,t)},t.prototype.applyPatchLocally=function(t,e){this.assertWritable(),this.type.applyPatchLocally(this,t,e)},l([e.observable],t.prototype,"subpath",void 0),l([e.observable],t.prototype,"_parent",void 0),l([e.computed],t.prototype,"path",null),l([e.computed],t.prototype,"value",null),l([e.computed],t.prototype,"snapshot",null),t}();!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"}(Tt||(Tt={}));var It,xt=function(){function t(t){this.isType=!0,this.name=t}return t.prototype.create=function(t,e){return void 0===t&&(t=this.getDefaultSnapshot()),D(this,t),this.instantiate(null,"",e,t).value},t.prototype.isAssignableFrom=function(t){return t===this},t.prototype.validate=function(t,e){return k(t)?n(t)===this||this.isAssignableFrom(n(t))?_():I(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(k(e)&&F(e)===t)return t;if(t.type===this&&q(e)&&!k(e)&&(!t.identifierAttribute||t.identifier===e[t.identifierAttribute]))return t.applySnapshot(e),t;var r=t.parent,i=t.subpath;if(t.die(),k(e)&&this.isAssignableFrom(n(e))){var o=F(e);return o.setParent(r,i),o}return this.instantiate(r,i,t._environment,e)},Object.defineProperty(t.prototype,"Type",{get:function(){return H("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 H("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}),l([e.action],t.prototype,"create",null),t}(),Dt=function(t){function e(e){return t.call(this,e)||this}return p(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){H("Immutable types do not support applying snapshots")},e.prototype.applyPatchLocally=function(t,e,n){H("Immutable types do not support applying patches")},e.prototype.getChildren=function(t){return Lt},e.prototype.getChildNode=function(t,e){return H("No child '"+e+"' available in type: "+this.name)},e.prototype.getChildType=function(t){return H("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 H("No child '"+e+"' available in type: "+this.name)},e}(xt),Et=1,Rt=null,zt=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)&&H("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 H("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}();!function(t){t[t.INITIALIZING=0]="INITIALIZING",t[t.CREATED=1]="CREATED",t[t.FINALIZED=2]="FINALIZED",t[t.DETACHING=3]="DETACHING",t[t.DEAD=4]="DEAD"}(It||(It={}));var kt=function(t){return".."},Ft="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`.",Lt=Object.freeze([]),Mt=Object.freeze({}),$t=function(){};($t=function(t,e){}).ids={};var Ut=function(t){function n(n,r){var i=t.call(this,n)||this;return i.shouldAttachNode=!0,i.flags=Tt.Map,i.createNewInstance=function(){var t=e.observable.shallowMap();return X(t,"put",dt),X(t,"toString",ft),t},i.finalizeNewInstance=function(t,n){var r=t.storedValue;e.extras.interceptReads(r,t.unbox),e.intercept(r,function(t){return i.willChange(t)}),t.applySnapshot(n),e.observe(r,i.didChange)},i.subType=r,i}return p(n,t),n.prototype.instantiate=function(t,e,n,r){return R(this,t,e,n,r,this.createNewInstance,this.finalizeNewInstance)},n.prototype.describe=function(){return"Map<string, "+this.subType.describe()+">"},n.prototype.getChildren=function(t){return t.storedValue.values()},n.prototype.getChildNode=function(t,e){var n=t.storedValue.get(e);return n||H("Not a child "+e),n},n.prototype.willChange=function(t){var e=F(t.object);switch(e.assertWritable(),t.type){case"update":var n=t.newValue;if(n===t.object.get(t.name))return null;D(this.subType,n),t.newValue=this.subType.reconcile(e.getChildNode(t.name),t.newValue),this.verifyIdentifier(t.name,t.newValue);break;case"add":D(this.subType,t.newValue),t.newValue=this.subType.instantiate(e,t.name,void 0,t.newValue),this.verifyIdentifier(t.name,t.newValue)}return t},n.prototype.verifyIdentifier=function(t,e){if(e instanceof _t){var n=e.identifier;null!==n&&""+n!=""+t&&H("A map of objects containing an identifier should always store the object under their own identifier. Trying to store key '"+n+"', but expected: '"+t+"'")}},n.prototype.getValue=function(t){return t.storedValue},n.prototype.getSnapshot=function(t){var e={};return t.getChildren().forEach(function(t){e[t.subpath]=t.snapshot}),e},n.prototype.didChange=function(t){var e=F(t.object);switch(t.type){case"update":return void e.emitPatch({op:"replace",path:pt(t.name),value:t.newValue.snapshot,oldValue:t.oldValue?t.oldValue.snapshot:void 0},e);case"add":return void e.emitPatch({op:"add",path:pt(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:pt(t.name),oldValue:n},e)}},n.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)}},n.prototype.applySnapshot=function(t,e){D(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)})},n.prototype.getChildType=function(t){return this.subType},n.prototype.isValidSnapshot=function(t,e){var n=this;return Y(t)?x(Object.keys(t).map(function(r){return n.subType.validate(t[r],O(e,r,n.subType))})):I(e,t,"Value is not a plain object")},n.prototype.getDefaultSnapshot=function(){return{}},n.prototype.removeChild=function(t,e){t.storedValue.delete(e)},l([e.action],n.prototype,"applySnapshot",null),n}(xt),Ht=function(t){function n(n,r){var i=t.call(this,n)||this;return i.shouldAttachNode=!0,i.flags=Tt.Array,i.createNewInstance=function(){var t=e.observable.shallowArray();return X(t,"toString",yt),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 p(n,t),n.prototype.describe=function(){return this.subType.describe()+"[]"},n.prototype.instantiate=function(t,e,n,r){return R(this,t,e,n,r,this.createNewInstance,this.finalizeNewInstance)},n.prototype.getChildren=function(t){return t.storedValue.peek()},n.prototype.getChildNode=function(t,e){var n=parseInt(e,10);return n<t.storedValue.length?t.storedValue[n]:H("Not a child: "+e)},n.prototype.willChange=function(t){var e=F(t.object);e.assertWritable();var n=e.getChildren();switch(t.type){case"update":if(t.newValue===t.object[t.index])return null;t.newValue=bt(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=bt(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},n.prototype.getValue=function(t){return t.storedValue},n.prototype.getSnapshot=function(t){return t.getChildren().map(function(t){return t.snapshot})},n.prototype.didChange=function(t){var e=F(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}},n.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)}},n.prototype.applySnapshot=function(t,e){D(this,e),t.storedValue.replace(e)},n.prototype.getChildType=function(t){return this.subType},n.prototype.isValidSnapshot=function(t,e){var n=this;return G(t)?x(t.map(function(t,r){return n.subType.validate(t,O(e,""+r,n.subType))})):I(e,t,"Value is not an array")},n.prototype.getDefaultSnapshot=function(){return[]},n.prototype.removeChild=function(t,e){t.storedValue.splice(parseInt(e,10),1)},l([e.action],n.prototype,"applySnapshot",null),n}(xt),Jt={afterCreate:"afterCreate",afterAttach:"afterAttach",postProcessSnapshot:"postProcessSnapshot",beforeDetach:"beforeDetach",beforeDestroy:"beforeDestroy"},Zt={name:"AnonymousModel",properties:{},initializers:Lt},Gt=function(t){function n(n){var r=t.call(this,n.name||Zt.name)||this;r.flags=Tt.Object,r.shouldAttachNode=!0,r.createNewInstance=function(){var t=e.observable.shallowObject(Mt);return X(t,"toString",gt),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(i,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){if(r.properties[t.name]){var e=F(t.object),n=t.oldValue?t.oldValue.snapshot:void 0;e.emitPatch({op:"replace",path:pt(t.name),value:t.newValue.snapshot,oldValue:n},e)}};var i=n.name||Zt.name;return/^\w[\w\d_]*$/.test(i)||H("Typename should be a valid identifier: "+i),Object.assign(r,Zt,n),r.properties=wt(r.properties),r.propertiesNames=Object.keys(r.properties),Object.freeze(r.properties),r}return p(n,t),n.prototype.cloneAndEnhance=function(t){return new n({name:t.name||this.name,properties:Object.assign({},this.properties,t.properties),initializers:this.initializers.concat(t.initializers||[]),preProcessor:t.preProcessor||this.preProcessor})},n.prototype.actions=function(t){var e=this;return this.cloneAndEnhance({initializers:[function(n){return e.instantiateActions(n,t(n)),n}]})},n.prototype.instantiateActions=function(t,e){Y(e)||H("actions initializer should return a plain object containing actions"),Object.keys(e).forEach(function(n){if("preProcessSnapshot"===n)return H("Cannot define action 'preProcessSnapshot', it should be defined using 'type.preProcessSnapshot(fn)' instead");var r=e[n],i=t[n];if(n in Jt&&i){var o=r;r=n===Jt.postProcessSnapshot?function(t){return o(i(t))}:function(){i.apply(null,arguments),o.apply(null,arguments)}}X(t,n,V(t,n,r))})},n.prototype.named=function(t){return this.cloneAndEnhance({name:t})},n.prototype.props=function(t){return this.cloneAndEnhance({properties:t})},n.prototype.volatile=function(t){var e=this;return this.cloneAndEnhance({initializers:[function(n){return e.instantiateVolatileState(n,t(n)),n}]})},n.prototype.instantiateVolatileState=function(t,n){Y(n)||H("state initializer should return a plain object containing views"),e.extendShallowObservable(t,n)},n.prototype.extend=function(t){var e=this;return this.cloneAndEnhance({initializers:[function(n){var r=t(n),i=r.actions,o=r.views,a=r.state,s=c(r,["actions","views","state"]);for(var u in s)H("The `extend` function should return an object with a subset of the fields 'actions', 'views' and 'state'. Found invalid key '"+u+"'");return a&&e.instantiateVolatileState(n,a),o&&e.instantiateViews(n,o),i&&e.instantiateActions(n,i),n}]})},n.prototype.views=function(t){var e=this;return this.cloneAndEnhance({initializers:[function(n){return e.instantiateViews(n,t(n)),n}]})},n.prototype.instantiateViews=function(t,n){Y(n)||H("views initializer should return a plain object containing views"),Object.keys(n).forEach(function(r){var i=Object.getOwnPropertyDescriptor(n,r),o=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 a={};Object.defineProperty(a,r,{get:i.get,set:i.set,enumerable:!0}),e.extendShallowObservable(t,a)}else"function"==typeof o?X(t,r,o):H("A view member should either be a function or getter based property")})},n.prototype.preProcessSnapshot=function(t){var e=this.preProcessor;return e?this.cloneAndEnhance({preProcessor:function(n){return e(t(n))}}):this.cloneAndEnhance({preProcessor:t})},n.prototype.instantiate=function(t,e,n,r){return R(this,t,e,n,this.applySnapshotPreProcessor(r),this.createNewInstance,this.finalizeNewInstance)},n.prototype.willChange=function(t){var e=F(t.object);e.assertWritable();var n=this.properties[t.name];return n&&(D(n,t.newValue),t.newValue=n.reconcile(e.getChildNode(t.name),t.newValue)),t},n.prototype.getChildren=function(t){var e=this,n=[];return this.forAllProps(function(r,i){n.push(e.getChildNode(t,r))}),n},n.prototype.getChildNode=function(t,e){if(!(e in this.properties))return H("Not a value property: "+e);var n=t.storedValue.$mobx.values[e].value;return n||H("Node not available for property "+e)},n.prototype.getValue=function(t){return t.storedValue},n.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},n.prototype.applyPatchLocally=function(t,e,n){"replace"!==n.op&&"add"!==n.op&&H("object does not support operation "+n.op),t.storedValue[e]=n.value},n.prototype.applySnapshot=function(t,e){var n=this.applySnapshotPreProcessor(e);D(this,n),this.forAllProps(function(e,r){t.storedValue[e]=n[e]})},n.prototype.applySnapshotPreProcessor=function(t){return this.preProcessor?this.preProcessor.call(null,t):t},n.prototype.getChildType=function(t){return this.properties[t]},n.prototype.isValidSnapshot=function(t,e){var n=this,r=this.applySnapshotPreProcessor(t);return Y(r)?x(this.propertiesNames.map(function(t){return n.properties[t].validate(r[t],O(e,t,n.properties[t]))})):I(e,r,"Value is not a plain object")},n.prototype.forAllProps=function(t){var e=this;this.propertiesNames.forEach(function(n){return t(n,e.properties[n])})},n.prototype.describe=function(){var t=this;return"{ "+this.propertiesNames.map(function(e){return e+": "+t.properties[e].describe()}).join("; ")+" }"},n.prototype.getDefaultSnapshot=function(){return{}},n.prototype.removeChild=function(t,e){t.storedValue[e]=null},l([e.action],n.prototype,"applySnapshot",null),n}(xt),Wt=function(t){function e(e,n,r,i){void 0===i&&(i=J);var o=t.call(this,e)||this;return o.shouldAttachNode=!1,o.flags=n,o.checker=r,o.initializer=i,o}return p(e,t),e.prototype.describe=function(){return this.name},e.prototype.instantiate=function(t,e,n,r){return R(this,t,e,n,r,this.initializer)},e.prototype.isValidSnapshot=function(t,e){return K(t)&&this.checker(t)?_():I(e,t,"Value is not a "+("Date"===this.name?"Date or a unix milliseconds timestamp":this.name))},e}(Dt),Bt=new Wt("string",Tt.String,function(t){return"string"==typeof t}),Yt=new Wt("number",Tt.Number,function(t){return"number"==typeof t}),qt=new Wt("boolean",Tt.Boolean,function(t){return"boolean"==typeof t}),Kt=new Wt("null",Tt.Null,function(t){return null===t}),Qt=new Wt("undefined",Tt.Undefined,function(t){return void 0===t}),Xt=new Wt("Date",Tt.Date,function(t){return"number"==typeof t||t instanceof Date},function(t){return t instanceof Date?t:new Date(t)});Xt.getSnapshot=function(t){return t.storedValue.getTime()};var te=function(t){function e(e){var n=t.call(this,JSON.stringify(e))||this;return n.shouldAttachNode=!1,n.flags=Tt.Literal,n.value=e,n}return p(e,t),e.prototype.instantiate=function(t,e,n,r){return R(this,t,e,n,r)},e.prototype.describe=function(){return JSON.stringify(this.value)},e.prototype.isValidSnapshot=function(t,e){return K(t)&&t===this.value?_():I(e,t,"Value is not a literal "+JSON.stringify(this.value))},e}(Dt),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 p(e,t),Object.defineProperty(e.prototype,"flags",{get:function(){return this.type.flags|Tt.Refinement},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"shouldAttachNode",{get:function(){return this.type.shouldAttachNode},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=k(t)?F(t).snapshot:t;return this.predicate(r)?_():I(e,t,this.message(t))},e}(Dt),ne=function(t){function e(e,n,r){var i=t.call(this,e)||this;return i.dispatcher=null,i.dispatcher=r,i.types=n,i}return p(e,t),Object.defineProperty(e.prototype,"flags",{get:function(){var t=Tt.Union;return this.types.forEach(function(e){t|=e.flags}),t},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"shouldAttachNode",{get:function(){return this.types.some(function(t){return t.shouldAttachNode})},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?H("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?I(e,t,"Multiple types are applicable for the union (hint: provide a dispatch function)"):0===r.length?I(e,t,"No type is applicable for the union").concat(x(n)):_()},e}(Dt),re=function(t){function e(e,n){var r=t.call(this,e.name)||this;return r.type=e,r.defaultValue=n,r}return p(e,t),Object.defineProperty(e.prototype,"flags",{get:function(){return this.type.flags|Tt.Optional},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"shouldAttachNode",{get:function(){return this.type.shouldAttachNode},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=k(i)?F(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&&D(this,t),t},e.prototype.isValidSnapshot=function(t,e){return void 0===t?_():this.type.validate(t,e)},e.prototype.isAssignableFrom=function(t){return this.type.isAssignableFrom(t)},e}(Dt),ie=jt(Kt,null),oe=function(t){function e(e,n){var r=t.call(this,e)||this;return r._subType=null,r.definition=n,r}return p(e,t),Object.defineProperty(e.prototype,"flags",{get:function(){return this.subType.flags|Tt.Late},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"shouldAttachNode",{get:function(){return this.subType.shouldAttachNode},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}(Dt),ae=new(function(t){function e(){var e=t.call(this,"frozen")||this;return e.shouldAttachNode=!1,e.flags=Tt.Frozen,e}return p(e,t),e.prototype.describe=function(){return"<any immutable value>"},e.prototype.instantiate=function(t,e,n,r){return R(this,t,e,n,r)},e.prototype.isValidSnapshot=function(t,e){return Q(t)?_():I(e,t,"Value is not serializable and cannot be frozen")},e}(Dt)),se=function(){return function(t,e){if(this.mode=t,this.value=e,"object"===t){if(!k(e))return H("Can only store references to tree nodes, got: '"+e+"'");if(!F(e).identifierAttribute)return H("Can only store references with a defined identifier attribute.")}}}(),ue=function(t){function e(e){var n=t.call(this,"reference("+e.name+")")||this;return n.targetType=e,n.flags=Tt.Reference,n}return p(e,t),e.prototype.describe=function(){return this.name},e.prototype.isAssignableFrom=function(t){return this.targetType.isAssignableFrom(t)},e.prototype.isValidSnapshot=function(t,e){return"string"==typeof t||"number"==typeof t?_():I(e,t,"Value is not a valid identifier, which is a string or a number")},e}(Dt),pe=function(t){function e(e){var n=t.call(this,e)||this;return n.shouldAttachNode=!0,n}return p(e,t),e.prototype.getValue=function(t){if(t.isAlive){var e=t.storedValue;if("object"===e.mode)return e.value;var n=t.root.identifierCache.resolve(this.targetType,e.value);return n?n.value:H("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 F(e.value).identifier}},e.prototype.instantiate=function(t,e,n,r){return R(this,t,e,n,new se(k(r)?"object":"identifier",r))},e.prototype.reconcile=function(t,e){if(t.type===this){var n=k(e)?"object":"identifier",r=t.storedValue;if(n===r.mode&&r.value===e)return t}var i=this.instantiate(t.parent,t.subpath,t._environment,e);return t.die(),i},e}(ue),ce=function(t){function e(e,n){var r=t.call(this,e)||this;return r.options=n,r.shouldAttachNode=!1,r}return p(e,t),e.prototype.getValue=function(t){if(t.isAlive)return this.options.get(t.storedValue,t.parent?t.parent.storedValue:null)},e.prototype.getSnapshot=function(t){return t.storedValue},e.prototype.instantiate=function(t,e,n,r){return R(this,t,e,n,k(r)?this.options.set(r,t?t.storedValue:null):r)},e.prototype.reconcile=function(t,e){var n=k(e)?this.options.set(e,t?t.storedValue:null):e;if(t.type===this&&t.storedValue===n)return t;var r=this.instantiate(t.parent,t.subpath,t._environment,n);return t.die(),r},e}(ue),le=function(t){function e(e){var n=t.call(this,"identifier("+e.name+")")||this;return n.identifierType=e,n.shouldAttachNode=!1,n.flags=Tt.Identifier,n}return p(e,t),e.prototype.instantiate=function(t,e,n,r){return t&&k(t.storedValue)?(t.identifierAttribute&&H("Cannot define property '"+e+"' as object identifier, property '"+t.identifierAttribute+"' is already defined as identifier property"),t.identifierAttribute=e,R(this,t,e,n,r)):H("Identifier types can only be instantiated as direct child of a model type")},e.prototype.reconcile=function(t,e){return t.storedValue!==e?H("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):I(e,t,"Value is not a valid identifier, which is a string or a number")},e}(Dt),he={enumeration:function(t,e){var n="string"==typeof t?e:t,r=St.apply(void 0,n.map(function(t){return Pt(""+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,e){return e?new ce(t,e):new pe(t)},union:St,optional:jt,literal:Pt,maybe:function(t){return St(ie,t)},refinement:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n="string"==typeof t[0]?t.shift():h(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:Bt,boolean:qt,number:Yt,Date:Xt,map:function(t){return new Ut("map<string, "+t.name+">",t)},array:function(t){return new Ht(t.name+"[]",t)},frozen:ae,identifier:function(t){return void 0===t&&(t=Bt),new le(t)},late:function(t,e){var n="string"==typeof t?t:"late("+t.toString()+")";return new oe(n,"string"==typeof t?e:t)},undefined:Qt,null:Kt};t.types=he,t.typecheck=E,t.escapeJsonPath=pt,t.unescapeJsonPath=ct,t.decorate=function(t,e){return e.$mst_middleware?e.$mst_middleware.push(t):e.$mst_middleware=[t],e},t.addMiddleware=P,t.process=function(t){return $t("process","`process()` has been renamed to `flow()`. "+Ft),it(t)},t.isStateTreeNode=k,t.flow=it,t.applyAction=b,t.onAction=m,t.recordActions=function(t){var e={actions:[],stop:function(){return n()},replay:function(t){b(t,e.actions)}},n=m(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=n,t.getChildType=function(t,e){return F(t).getChildType(e)},t.onPatch=r,t.onSnapshot=function(t,e){return F(t).onSnapshot(e)},t.applyPatch=i,t.recordPatches=function(t){function e(){n||(n=r(t,function(t,e){o.rawPatches.push([t,e])}))}var n=null,o={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,o.patches)},undo:function(e){i(e||t,o.inversePatches.slice().reverse())}};return e(),o},t.protect=function(t){var e=F(t);e.isRoot||H("`protect` can only be invoked on root nodes"),e.isProtectionEnabled=!0},t.unprotect=function(t){var e=F(t);e.isRoot||H("`unprotect` can only be invoked on root nodes"),e.isProtectionEnabled=!1},t.isProtected=function(t){return F(t).isProtected},t.applySnapshot=o,t.getSnapshot=function(t){return F(t).snapshot},t.hasParent=function(t,e){void 0===e&&(e=1);for(var n=F(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=F(t).parent;r;){if(0==--n)return r.storedValue;r=r.parent}return H("Failed to find the parent of "+F(t)+" at depth "+e)},t.getRoot=a,t.getPath=function(t){return F(t).path},t.getPathParts=function(t){return ht(F(t).path)},t.isRoot=function(t){return F(t).isRoot},t.resolvePath=function(t,e){var n=$(F(t),e);return n?n.value:void 0},t.resolveIdentifier=function(t,e,n){var r=F(e).root.identifierCache.resolve(t,""+n);return r?r.value:void 0},t.tryResolve=s,t.getRelativePath=function(t,e){return M(F(t),F(e))},t.clone=function(t,e){void 0===e&&(e=!0);var n=F(t);return n.type.create(n.snapshot,!0===e?n.root._environment:!1===e?void 0:e)},t.detach=function(t){return F(t).detach(),t},t.destroy=function(t){var e=F(t);e.isRoot?e.die():e.parent.removeChild(e.subpath)},t.isAlive=function(t){return F(t).isAlive},t.addDisposer=function(t,e){F(t).addDisposer(e)},t.getEnv=function(t){var e=F(t).root._environment;return e||Mt},t.walk=u,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}_t(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){return F(t).type}function a(t,e){return F(t).onPatch(e)}function s(t,e){F(t).applyPatches(Y(e))}function u(t,e){return F(t).applySnapshot(e)}function p(t){return F(t).root.storedValue}function c(t,e){var n=U(F(t),e,!1);if(void 0!==n)try{return n.value}catch(t){return}}function l(t,e){var n=F(t);n.getChildren().forEach(function(t){M(t.storedValue)&&l(t.storedValue,e)}),e(n.storedValue)}function h(t){return"object"==typeof t&&t&&!0===t.isType}function f(t,e,n,r){if(r instanceof Date)return{$MST_DATE:r.getTime()};if(Q(r))return r;if(M(r))return y("[MSTNode: "+o(r).name+"]");if("function"==typeof r)return y("[function]");if("object"==typeof r&&!K(r)&&!G(r))return y("[object "+(r&&r.constructor&&r.constructor.name||"Complex Object")+"]");try{return JSON.stringify(r),r}catch(t){return y(""+t)}}function d(t,e){return e&&"object"==typeof e&&"$MST_DATE"in e?new Date(e.$MST_DATE):e}function y(t){return{$MST_UNSERIALIZABLE:!0,type:t}}function b(t,n){e.runInAction(function(){Y(n).forEach(function(e){return v(t,e)})})}function v(t,e){var n=c(t,e.path||"");if(!n)return W("Invalid action path: "+(e.path||""));var r=F(n);return"@APPLY_PATCHES"===e.name?s.call(null,n,e.args[0]):"@APPLY_SNAPSHOT"===e.name?u.call(null,n,e.args[0]):("function"!=typeof n[e.name]&&W("Action '"+e.name+"' does not exist in '"+r.path+"'"),n[e.name].apply(n,e.args?e.args.map(function(t){return d(r,t)}):[]))}function m(t,e,n){function r(n){if("action"===n.type&&n.id===n.rootId){var r=F(n.context);e({name:n.name,path:$(F(t),r),args:n.args.map(function(t,e){return f(r,n.name,e,t)})})}}return void 0===n&&(n=!1),P(t,n?function(t,e){var n=e(t);return r(t),n}:function(t,e){return r(t),e(t)})}function g(){return Ft++}function w(t,e){var n=F(t.context),r=n._isRunningAction,i=Lt;n.assertAlive(),n._isRunningAction=!0,Lt=t;try{return j(n,t,e)}finally{Lt=i,n._isRunningAction=r}}function A(){return Lt||W("Not running an action!")}function V(t,e,n){var r=function(){var r=g();return w({type:"action",name:e,id:r,args:at(arguments),context:t,tree:p(t),rootId:Lt?Lt.rootId:r,parentId:Lt?Lt.id:0},n)};return r._isMSTAction=!0,r}function P(t,e,n){return void 0===n&&(n=!0),F(t).addMiddleWare(e,n)}function S(t,e,n){for(var r=n.$mst_middleware||Wt,i=t;i;)i.middlewares&&(r=r.concat(i.middlewares)),i=i.parent;return r}function j(t,n,r){function i(t){function u(t,e){h=!0,s=e?e(i(t)||s):i(t)}function p(t){f=!0,s=t}var c=o[a++],l=c&&c.handler,h=!1,f=!1,d=function(){return l(t,u,p),s};return l&&c.includeHooks?d():l&&!c.includeHooks?Bt[t.name]?i(t):d():e.action(r).apply(null,n.args)}var o=S(t,n,r);if(!o.length)return e.action(r).apply(null,n.args);var a=0,s=null;return i(n)}function T(t){try{return JSON.stringify(t)}catch(t){return"<Unserializable: "+t+">"}}function N(t){return"function"==typeof t?"<function"+(t.name?" "+t.name:"")+">":M(t)?"<"+t+">":"`"+T(t)+"`"}function O(t){return t.length<280?t:t.substring(0,272)+"......"+t.substring(t.length-8)}function C(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=M(e)?"value of type "+F(e).type.name+":":Q(e)?"value":"snapshot",a=n&&M(e)&&n.is(F(e).snapshot);return""+i+o+" "+N(e)+" is not assignable "+(n?"to type: `"+n.name+"`":"")+(t.message?" ("+t.message+")":"")+(n?jt(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 _(t,e,n){return t.concat([{path:e,type:n}])}function I(){return Wt}function x(t,e,n){return[{context:t,value:e,message:n}]}function D(t){return t.reduce(function(t,e){return t.concat(e)},[])}function E(t,e){}function R(t,e){var n=t.validate(e,[{path:"",type:t}]);n.length>0&&(console.error('Failed to create "'+t.name+'" from:',e),W("Error while converting "+O(N(e))+" to `"+t.name+"`:\n\n "+n.map(C).join("\n ")))}function k(t,e,n,r,i,o,a){if(void 0===o&&(o=J),void 0===a&&(a=Z),M(i)){var s=i.$treenode;return s.isRoot||W("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 '"+s.path+"'"),s.setParent(e,n),s}var u=o(i);if(t.shouldAttachNode){var p=new Et(t,e,n,r,i,u,t.shouldAttachNode,a);return p.finalizeCreation(),p}return new xt(t,e,n,r,i,u,t.shouldAttachNode,a)}function z(t){return t instanceof xt||t instanceof Et}function M(t){return!(!t||!t.$treenode)}function F(t){return M(t)?t.$treenode:W("Value "+t+" is no MST Node")}function L(){return F(this).snapshot}function $(t,e){t.root!==e.root&&W("Cannot calculate relative path: objects '"+t+"' and '"+e+"' are not part of the same object tree");for(var n=yt(t.path),r=yt(e.path),i=0;i<n.length&&n[i]===r[i];i++);return n.slice(i).map(Ut).join("/")+dt(r.slice(i))}function U(t,e,n){return void 0===n&&(n=!0),H(t,yt(e),n)}function H(t,e,n){void 0===n&&(n=!0);for(var r=t,i=0;i<e.length;i++){var o=e[i];{if(""!==o){if(".."===o){if(r=r.parent)continue}else{if("."===o||""===o)continue;if(r){if(r instanceof xt)try{var a=r.value;M(a)&&(r=F(a))}catch(t){if(!n)return;throw t}if(r instanceof Et&&r.getChildType(o)&&(r=r.getChildNode(o)))continue}}return n?W("Could not resolve '"+o+"' in path '"+(dt(e.slice(0,i))||"/")+"' while resolving '"+dt(e)+"'"):void 0}r=r.root}}return r}function W(t){throw void 0===t&&(t="Illegal state"),new Error("[mobx-state-tree] "+t)}function J(t){return t}function Z(){}function G(t){return!(!Array.isArray(t)&&!e.isObservableArray(t))}function Y(t){return t?G(t)?t:[t]:Wt}function B(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 K(t){if(null===t||"object"!=typeof t)return!1;var e=Object.getPrototypeOf(t);return e===Object.prototype||null===e}function q(t){return!(null===t||"object"!=typeof t||t instanceof Date||t instanceof RegExp)}function Q(t){return null===t||void 0===t||("string"==typeof t||"number"==typeof t||"boolean"==typeof t||t instanceof Date)}function X(t){return t}function tt(t){return t}function et(t){return"function"!=typeof t}function nt(t,e,n){Object.defineProperty(t,e,{enumerable:!1,writable:!1,configurable:!0,value:n})}function rt(t,e,n){Object.defineProperty(t,e,{enumerable:!0,writable:!1,configurable:!0,value:n})}function it(t,e){var n=t.indexOf(e);-1!==n&&t.splice(n,1)}function ot(t,e){return t.push(e),function(){it(t,e)}}function at(t){for(var e=new Array(t.length),n=0;n<t.length;n++)e[n]=t[n];return e}function st(t){return ut(t.name,t)}function ut(t,e){var n=function(){function r(e,r,a){e.$mst_middleware=n.$mst_middleware,w({name:t,type:r,id:i,args:[a],tree:o.tree,context:o.context,parentId:o.id,rootId:o.rootId},e)}var i=g(),o=A(),a=arguments;return new Promise(function(s,u){function p(t){var e;try{r(function(t){e=h.next(t)},"flow_resume",t)}catch(t){return void setImmediate(function(){r(function(e){u(t)},"flow_throw",t)})}l(e)}function c(t){var e;try{r(function(t){e=h.throw(t)},"flow_resume_error",t)}catch(t){return void setImmediate(function(){r(function(e){u(t)},"flow_throw",t)})}l(e)}function l(t){if(!t.done)return t.value&&"function"==typeof t.value.then||W("Only promises can be yielded to `async`, got: "+t),t.value.then(p,c);setImmediate(function(){r(function(t){s(t)},"flow_return",t.value)})}var h,f=function(){h=e.apply(null,arguments),p(void 0)};f.$mst_middleware=n.$mst_middleware,w({name:t,type:"flow_spawn",id:i,args:at(a),tree:o.tree,context:o.context,parentId:o.id,rootId:o.rootId},f)})};return n}function pt(t){return"oldValue"in t||W("Patches without `oldValue` field cannot be inversed"),[ct(t),lt(t)]}function ct(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 lt(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 ht(t){return t.replace(/~/g,"~1").replace(/\//g,"~0")}function ft(t){return t.replace(/~0/g,"/").replace(/~1/g,"~")}function dt(t){return 0===t.length?"":"/"+t.map(ht).join("/")}function yt(t){var e=t.split("/").map(ft);return""===e[0]?e.slice(1):e}function bt(){return F(this)+"("+this.size+" items)"}function vt(t){if(t||W("Map.put cannot be used to set empty values"),M(t)){var e=F(t);return this.set(""+e.identifier,e.value),this}if(q(t)){var n=F(this).type;return n.identifierMode===Gt.NO?W(Yt):n.identifierMode===Gt.YES?(this.set(""+t[n.identifierAttribute],t),this):(e=F(n.subType.create(t))).identifierAttribute?(this.set(""+e.value[e.identifierAttribute],e.value),this):W(Yt)}return W("Map.put can only be used to store complex values")}function mt(){return F(this)+"("+this.length+" items)"}function gt(t,e,n,r,i){for(var o,a,s=!1,u=void 0,p=0;s=p<=r.length-1,o=n[p],a=s?r[p]:void 0,z(a)&&(a=a.storedValue),o||s;p++)if(s)if(o)if(At(o,a))n[p]=wt(e,t,""+i[p],a,o);else{u=void 0;for(var c=p;c<n.length;c++)if(At(n[c],a)){u=n.splice(c,1)[0];break}n.splice(p,0,wt(e,t,""+i[p],a,u))}else M(a)&&F(a).parent===t&&W("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[p]+"', but it lives already at '"+F(a).path+"'"),n.splice(p,0,wt(e,t,""+i[p],a));else o.die(),n.splice(p,1),p--;return n}function wt(t,e,n,r,i){if(E(t,r),M(r)){var o=F(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 At(t,e){return M(e)?F(e)===t:!(!q(e)||t.snapshot!==e)||!!(t instanceof Et&&null!==t.identifier&&t.identifierAttribute&&K(e)&&e[t.identifierAttribute]===t.identifier)}function Vt(){return F(this).toString()}function Pt(t){return Object.keys(t).reduce(function(t,e){if(e in Bt)return W("Hook '"+e+"' was defined as property. Hooks should be defined as part of the actions");var n=Object.getOwnPropertyDescriptor(t,e);"get"in n&&W("Getters are not supported as properties. Please use views instead");var r=n.value;if(null===r||void 0===r)W("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(Q(r))return Object.assign({},t,(i={},i[e]=Ot(St(r),r),i));if(h(r))return t;W("function"==typeof r?"Functions are not supported as properties, use views instead":"object"==typeof r?"In property '"+e+"': base models should not contain complex values: '"+r+"'":"Unexpected value for property '"+e+"'")}var i},t)}function St(t){switch(typeof t){case"string":return ee;case"number":return ne;case"boolean":return re;case"object":if(t instanceof Date)return ae}return W("Cannot determine primitive type from value "+t)}function jt(t){return h(t)&&(t.flags&(Ct.String|Ct.Number|Ct.Boolean|Ct.Date))>0}function Tt(t){return new se(t)}function Nt(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var r=h(t)?null:t,i=h(t)?e.concat(t):e,o="("+i.map(function(t){return t.name}).join(" | ")+")";return new pe(o,i,r)}function Ot(t,e){return new ce(t,e)}var Ct,_t=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])},It=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++){e=arguments[n];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])}return t},xt=function(){function t(t,e,n,r,i,o,a,s){void 0===s&&(s=Z),this.subpath="",this._environment=void 0,this._autoUnbox=!0,this.state=Rt.INITIALIZING,this.type=t,this.storedValue=o,this._parent=e,this.subpath=n,this.storedValue=o,this._environment=r,this.unbox=this.unbox.bind(this),a&&nt(this.storedValue,"$treenode",this);var u=!0;try{a&&nt(this.storedValue,"toJSON",L),s(this,i),this.state=Rt.CREATED,u=!1}finally{u&&(this.state=Rt.DEAD)}}return Object.defineProperty(t.prototype,"path",{get:function(){return this.parent?this.parent.path+"/"+ht(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(){return this._parent?this._parent.root:W("This scalar node is not part of a tree")},enumerable:!0,configurable:!0}),t.prototype.setParent=function(t,e){void 0===e&&(e=null),this.parent!==t&&W("Cannot change parent of immutable node"),this.subpath!==e&&(this.subpath=e||"")},Object.defineProperty(t.prototype,"value",{get:function(){return this.type.getValue(this)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"snapshot",{get:function(){return X(this.type.getSnapshot(this))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isAlive",{get:function(){return this.state!==Rt.DEAD},enumerable:!0,configurable:!0}),t.prototype.unbox=function(t){return t&&!0===this._autoUnbox?t.value:t},t.prototype.toString=function(){return this.type.name+"@"+(this.path||"<root>")+(this.isAlive?"":"[dead]")},t.prototype.die=function(){this.state=Rt.DEAD},i([e.observable],t.prototype,"subpath",void 0),t}(),Dt=1,Et=function(){function t(t,n,r,i,o,a,s,u){void 0===u&&(u=Z);var p=this;this.nodeId=++Dt,this.subpath="",this._parent=null,this._isRunningAction=!1,this.isProtectionEnabled=!0,this.identifierAttribute=void 0,this._environment=void 0,this._autoUnbox=!0,this.state=Rt.INITIALIZING,this.middlewares=Wt,this.type=t,this.storedValue=a,this._parent=n,this.subpath=r,this._environment=i,this.unbox=this.unbox.bind(this),this.preboot(),n||(this.identifierCache=new $t),s&&nt(this.storedValue,"$treenode",this);var c=!0;try{s&&nt(this.storedValue,"toJSON",L),this._isRunningAction=!0,u(this,o),this._isRunningAction=!1,n?n.root.identifierCache.addNodeToCache(this):this.identifierCache.addNodeToCache(this),this.fireHook("afterCreate"),this.state=Rt.CREATED,c=!1}finally{c&&(this.state=Rt.DEAD)}var l=e.reaction(function(){return p.snapshot},function(t){p.emitSnapshot(t)});l.onError(function(t){throw t}),this.addDisposer(l)}return Object.defineProperty(t.prototype,"path",{get:function(){return this.parent?this.parent.path+"/"+ht(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.setParent=function(t,e){void 0===e&&(e=null),this.parent===t&&this.subpath===e||(t&&(this._parent&&t!==this._parent&&W("A node cannot exists twice in the state tree. Failed to add "+this+" to path '"+t.path+"/"+e+"'."),this._parent||t.root!==this||W("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&&W("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.fireHook=function(t){var e=this.storedValue&&"object"==typeof this.storedValue&&this.storedValue[t];"function"==typeof e&&e.apply(this.storedValue)},Object.defineProperty(t.prototype,"value",{get:function(){if(this.isAlive)return this.type.getValue(this)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"snapshot",{get:function(){if(this.isAlive)return X(this.type.getSnapshot(this))},enumerable:!0,configurable:!0}),t.prototype.isRunningAction=function(){return!!this._isRunningAction||!this.isRoot&&this.parent.isRunningAction()},Object.defineProperty(t.prototype,"identifier",{get:function(){return this.identifierAttribute?this.snapshot[this.identifierAttribute]:null},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isAlive",{get:function(){return this.state!==Rt.DEAD},enumerable:!0,configurable:!0}),t.prototype.assertAlive=function(){this.isAlive||W(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")},t.prototype.getChildNode=function(t){this.assertAlive(),this._autoUnbox=!1;try{return this.type.getChildNode(this,t)}finally{this._autoUnbox=!0}},t.prototype.getChildren=function(){this.assertAlive(),this._autoUnbox=!1;try{return this.type.getChildren(this)}finally{this._autoUnbox=!0}},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&&W("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.unbox=function(t){return t&&!0===this._autoUnbox?t.value:t},t.prototype.toString=function(){var t=this.identifier?"(id: "+this.identifier+")":"";return this.type.name+"@"+(this.path||"<root>")+t+(this.isAlive?"":"[dead]")},t.prototype.finalizeCreation=function(){if(this.state===Rt.CREATED){if(this.parent){if(this.parent.state!==Rt.FINALIZED)return;this.fireHook("afterAttach")}this.state=Rt.FINALIZED;for(var e=0,n=this.getChildren();e<n.length;e++){var r=n[e];r instanceof t&&r.finalizeCreation()}}},t.prototype.detach=function(){this.isAlive||W("Error while detaching, node is not alive."),this.isRoot||(this.fireHook("beforeDetach"),this._environment=this.root._environment,this.state=Rt.DETACHING,this.identifierCache=this.root.identifierCache.splitCache(this),this.parent.removeChild(this.subpath),this._parent=null,this.subpath="",this.state=Rt.FINALIZED)},t.prototype.preboot=function(){var t=this;this.disposers=[],this.middlewares=[],this.snapshotSubscribers=[],this.patchSubscribers=[],this.applyPatches=V(this.storedValue,"@APPLY_PATCHES",function(e){e.forEach(function(e){var n=yt(e.path);H(t,n.slice(0,-1)).applyPatchLocally(n[n.length-1],e)})}).bind(this.storedValue),this.applySnapshot=V(this.storedValue,"@APPLY_SNAPSHOT",function(e){if(e!==t.snapshot)return t.type.applySnapshot(t,e)}).bind(this.storedValue)},t.prototype.die=function(){this.state!==Rt.DETACHING&&M(this.storedValue)&&(l(this.storedValue,function(e){var n=F(e);n instanceof t&&n.aboutToDie()}),l(this.storedValue,function(e){var n=F(e);n instanceof t&&n.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;rt(this,"snapshot",this.snapshot),this.patchSubscribers.splice(0),this.snapshotSubscribers.splice(0),this.patchSubscribers.splice(0),this.state=Rt.DEAD,this._parent=null,this.subpath="",Object.defineProperty(this.storedValue,"$mobx",{get:function(){W("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.onSnapshot=function(t){return ot(this.snapshotSubscribers,t)},t.prototype.emitSnapshot=function(t){this.snapshotSubscribers.forEach(function(e){return e(t)})},t.prototype.onPatch=function(t){return ot(this.patchSubscribers,t)},t.prototype.emitPatch=function(t,e){if(this.patchSubscribers.length){var n=pt(B({},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.addDisposer=function(t){this.disposers.unshift(t)},t.prototype.removeMiddleware=function(t){this.middlewares=this.middlewares.filter(function(e){return e.handler!==t})},t.prototype.addMiddleWare=function(t,e){var n=this;return void 0===e&&(e=!0),this.middlewares.push({handler:t,includeHooks:e}),function(){n.removeMiddleware(t)}},t.prototype.applyPatchLocally=function(t,e){this.assertWritable(),this.type.applyPatchLocally(this,t,e)},i([e.observable],t.prototype,"subpath",void 0),i([e.observable],t.prototype,"_parent",void 0),i([e.computed],t.prototype,"path",null),i([e.computed],t.prototype,"value",null),i([e.computed],t.prototype,"snapshot",null),t}();!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 Rt,kt=function(){function t(t){this.isType=!0,this.name=t}return t.prototype.create=function(t,e){return void 0===t&&(t=this.getDefaultSnapshot()),E(this,t),this.instantiate(null,"",e,t).value},t.prototype.isAssignableFrom=function(t){return t===this},t.prototype.validate=function(t,e){return M(t)?o(t)===this||this.isAssignableFrom(o(t))?I():x(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(M(e)&&F(e)===t)return t;if(t.type===this&&q(e)&&!M(e)&&(!t.identifierAttribute||t.identifier===e[t.identifierAttribute]))return t.applySnapshot(e),t;var n=t.parent,r=t.subpath;if(t.die(),M(e)&&this.isAssignableFrom(o(e))){var i=F(e);return i.setParent(n,r),i}return this.instantiate(n,r,t._environment,e)},Object.defineProperty(t.prototype,"Type",{get:function(){return W("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 W("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}(),zt=function(t){function e(e){return t.call(this,e)||this}return n(e,t),e.prototype.getValue=function(t){return t.storedValue},e.prototype.getSnapshot=function(t){return t.storedValue},e.prototype.getDefaultSnapshot=function(){},e.prototype.applySnapshot=function(t,e){W("Immutable types do not support applying snapshots")},e.prototype.applyPatchLocally=function(t,e,n){W("Immutable types do not support applying patches")},e.prototype.getChildren=function(t){return Wt},e.prototype.getChildNode=function(t,e){return W("No child '"+e+"' available in type: "+this.name)},e.prototype.getChildType=function(t){return W("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 W("No child '"+e+"' available in type: "+this.name)},e}(kt),Mt=new Map,Ft=1,Lt=null,$t=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)&&W("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 W("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}();!function(t){t[t.INITIALIZING=0]="INITIALIZING",t[t.CREATED=1]="CREATED",t[t.FINALIZED=2]="FINALIZED",t[t.DETACHING=3]="DETACHING",t[t.DEAD=4]="DEAD"}(Rt||(Rt={}));var Ut=function(t){return".."},Ht="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`.",Wt=Object.freeze([]),Jt=Object.freeze({}),Zt=function(){};(Zt=function(t,e){}).ids={};var Gt,Yt="Map.put can only be used to store complex values that have an identifier type attribute";!function(t){t[t.UNKNOWN=0]="UNKNOWN",t[t.YES=1]="YES",t[t.NO=2]="NO"}(Gt||(Gt={}));var Bt,Kt=function(t){function r(n,r){var i=t.call(this,n)||this;return i.shouldAttachNode=!0,i.identifierMode=Gt.UNKNOWN,i.identifierAttribute=void 0,i.flags=Ct.Map,i.createNewInstance=function(){var t=e.observable.shallowMap();return nt(t,"put",vt),nt(t,"toString",bt),t},i.finalizeNewInstance=function(t,n){var r=t,o=r.storedValue;e.extras.interceptReads(o,r.unbox),e.intercept(o,function(t){return i.willChange(t)}),r.applySnapshot(n),e.observe(o,i.didChange)},i.subType=r,i}return n(r,t),r.prototype.instantiate=function(t,e,n,r){return k(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||W("Not a child "+e),n},r.prototype.willChange=function(t){var e=F(t.object);switch(e.assertWritable(),t.type){case"update":var n=t.newValue;if(n===t.object.get(t.name))return null;E(this.subType,n),t.newValue=this.subType.reconcile(e.getChildNode(t.name),t.newValue),this.processIdentifier(t.name,t.newValue);break;case"add":E(this.subType,t.newValue),t.newValue=this.subType.instantiate(e,t.name,void 0,t.newValue),this.processIdentifier(t.name,t.newValue)}return t},r.prototype.processIdentifier=function(t,e){if(e instanceof Et&&(this.identifierMode===Gt.UNKNOWN&&(this.identifierMode=void 0!==e.identifierAttribute?Gt.YES:Gt.NO,this.identifierAttribute=e.identifierAttribute),e.identifierAttribute!==this.identifierAttribute&&W("The objects in a map should all have the same identifier attribute, expected '"+this.identifierAttribute+"', but child of type '"+e.type.name+"' declared attribute '"+e.identifierAttribute+"' as identifier"),this.identifierMode===Gt.YES)){var n=""+e.identifier;n!==t&&W("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=F(t.object);switch(t.type){case"update":return void e.emitPatch({op:"replace",path:ht(t.name),value:t.newValue.snapshot,oldValue:t.oldValue?t.oldValue.snapshot:void 0},e);case"add":return void e.emitPatch({op:"add",path:ht(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:ht(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){E(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 K(t)?D(Object.keys(t).map(function(r){return n.subType.validate(t[r],_(e,r,n.subType))})):x(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}(kt),qt=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 nt(t,"toString",mt),t},i.finalizeNewInstance=function(t,n){var r=t,o=r.storedValue;e.extras.getAdministration(o).dehancer=r.unbox,e.intercept(o,function(t){return i.willChange(t)}),r.applySnapshot(n),e.observe(o,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 k(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]:W("Not a child: "+e)},r.prototype.willChange=function(t){var e=F(t.object);e.assertWritable();var n=e.getChildren();switch(t.type){case"update":if(t.newValue===t.object[t.index])return null;t.newValue=gt(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=gt(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=F(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){E(this,e),t.storedValue.replace(e)},r.prototype.getChildType=function(t){return this.subType},r.prototype.isValidSnapshot=function(t,e){var n=this;return G(t)?D(t.map(function(t,r){return n.subType.validate(t,_(e,""+r,n.subType))})):x(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}(kt);!function(t){t.afterCreate="afterCreate",t.afterAttach="afterAttach",t.postProcessSnapshot="postProcessSnapshot",t.beforeDetach="beforeDetach",t.beforeDestroy="beforeDestroy"}(Bt||(Bt={}));var Qt={name:"AnonymousModel",properties:{},initializers:Wt},Xt=function(t){function o(n){var r=t.call(this,n.name||Qt.name)||this;r.flags=Ct.Object,r.shouldAttachNode=!0,r.properties={},r.createNewInstance=function(){var t=e.observable.shallowObject(Jt);return nt(t,"toString",Vt),t},r.finalizeNewInstance=function(t,n){var i=t,o=i.storedValue;r.forAllProps(function(t,r){e.extendShallowObservable(o,(a={},a[t]=e.observable.ref(r.instantiate(i,t,i._environment,n[t])),a)),e.extras.interceptReads(o,t,i.unbox);var a}),r.initializers.reduce(function(t,e){return e(t)},o),e.intercept(o,function(t){return r.willChange(t)}),e.observe(o,r.didChange)},r.didChange=function(t){if(r.properties[t.name]){var e=F(t.object),n=t.oldValue?t.oldValue.snapshot:void 0;e.emitPatch({op:"replace",path:ht(t.name),value:t.newValue.snapshot,oldValue:n},e)}};var i=n.name||Qt.name;return/^\w[\w\d_]*$/.test(i)||W("Typename should be a valid identifier: "+i),Object.assign(r,Qt,n),r.properties=Pt(r.properties),X(r.properties),r}return n(o,t),Object.defineProperty(o.prototype,"propertyNames",{get:function(){return Object.keys(this.properties)},enumerable:!0,configurable:!0}),o.prototype.cloneAndEnhance=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){var e=this;return this.cloneAndEnhance({initializers:[function(n){return e.instantiateActions(n,t(n)),n}]})},o.prototype.instantiateActions=function(t,e){K(e)||W("actions initializer should return a plain object containing actions"),Object.keys(e).forEach(function(n){if("preProcessSnapshot"===n)return W("Cannot define action 'preProcessSnapshot', it should be defined using 'type.preProcessSnapshot(fn)' instead");var r=e[n],i=t[n];if(n in Bt&&i){var o=r;r=n===Bt.postProcessSnapshot?function(t){return o(i(t))}:function(){i.apply(null,arguments),o.apply(null,arguments)}}nt(t,n,V(t,n,r))})},o.prototype.named=function(t){return this.cloneAndEnhance({name:t})},o.prototype.props=function(t){return this.cloneAndEnhance({properties:t})},o.prototype.volatile=function(t){var e=this;return this.cloneAndEnhance({initializers:[function(n){return e.instantiateVolatileState(n,t(n)),n}]})},o.prototype.instantiateVolatileState=function(t,n){K(n)||W("volatile state initializer should return a plain object containing state"),e.extendShallowObservable(t,n)},o.prototype.extend=function(t){var e=this;return this.cloneAndEnhance({initializers:[function(n){var i=t(n),o=i.actions,a=i.views,s=i.state,u=r(i,["actions","views","state"]);for(var p in u)W("The `extend` function should return an object with a subset of the fields 'actions', 'views' and 'state'. Found invalid key '"+p+"'");return s&&e.instantiateVolatileState(n,s),a&&e.instantiateViews(n,a),o&&e.instantiateActions(n,o),n}]})},o.prototype.views=function(t){var e=this;return this.cloneAndEnhance({initializers:[function(n){return e.instantiateViews(n,t(n)),n}]})},o.prototype.instantiateViews=function(t,n){K(n)||W("views initializer should return a plain object containing views"),Object.keys(n).forEach(function(r){var i=Object.getOwnPropertyDescriptor(n,r),o=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 a={};Object.defineProperty(a,r,{get:i.get,set:i.set,enumerable:!0}),e.extendShallowObservable(t,a)}else"function"==typeof o?nt(t,r,o):W("A view member should either be a function or getter based property")})},o.prototype.preProcessSnapshot=function(t){var e=this.preProcessor;return e?this.cloneAndEnhance({preProcessor:function(n){return e(t(n))}}):this.cloneAndEnhance({preProcessor:t})},o.prototype.instantiate=function(t,e,n,r){return k(this,t,e,n,this.applySnapshotPreProcessor(r),this.createNewInstance,this.finalizeNewInstance)},o.prototype.willChange=function(t){var e=F(t.object);e.assertWritable();var n=this.properties[t.name];return n&&(E(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 W("Not a value property: "+e);var n=t.storedValue.$mobx.values[e].value;return n||W("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&&W("object does not support operation "+n.op),t.storedValue[e]=n.value},o.prototype.applySnapshot=function(t,e){var n=this.applySnapshotPreProcessor(e);E(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 K(r)?D(this.propertyNames.map(function(t){return n.properties[t].validate(r[t],_(e,t,n.properties[t]))})):x(e,r,"Value is not a plain object")},o.prototype.forAllProps=function(t){var e=this;this.propertyNames.forEach(function(n){return t(n,e.properties[n])})},o.prototype.describe=function(){var t=this;return"{ "+this.propertyNames.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},i([e.action],o.prototype,"applySnapshot",null),o}(kt),te=function(t){function e(e,n,r,i){void 0===i&&(i=J);var o=t.call(this,e)||this;return o.shouldAttachNode=!1,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 k(this,t,e,n,r,this.initializer)},e.prototype.isValidSnapshot=function(t,e){return Q(t)&&this.checker(t)?I():x(e,t,"Value is not a "+("Date"===this.name?"Date or a unix milliseconds timestamp":this.name))},e}(zt),ee=new te("string",Ct.String,function(t){return"string"==typeof t}),ne=new te("number",Ct.Number,function(t){return"number"==typeof t}),re=new te("boolean",Ct.Boolean,function(t){return"boolean"==typeof t}),ie=new te("null",Ct.Null,function(t){return null===t}),oe=new te("undefined",Ct.Undefined,function(t){return void 0===t}),ae=new te("Date",Ct.Date,function(t){return"number"==typeof t||t instanceof Date},function(t){return t instanceof Date?t:new Date(t)});ae.getSnapshot=function(t){return t.storedValue.getTime()};var se=function(t){function e(e){var n=t.call(this,JSON.stringify(e))||this;return n.shouldAttachNode=!1,n.flags=Ct.Literal,n.value=e,n}return n(e,t),e.prototype.instantiate=function(t,e,n,r){return k(this,t,e,n,r)},e.prototype.describe=function(){return JSON.stringify(this.value)},e.prototype.isValidSnapshot=function(t,e){return Q(t)&&t===this.value?I():x(e,t,"Value is not a literal "+JSON.stringify(this.value))},e}(zt),ue=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}),Object.defineProperty(e.prototype,"shouldAttachNode",{get:function(){return this.type.shouldAttachNode},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=M(t)?F(t).snapshot:t;return this.predicate(r)?I():x(e,t,this.message(t))},e}(zt),pe=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}),Object.defineProperty(e.prototype,"shouldAttachNode",{get:function(){return this.types.some(function(t){return t.shouldAttachNode})},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?W("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?x(e,t,"Multiple types are applicable for the union (hint: provide a dispatch function)"):0===r.length?x(e,t,"No type is applicable for the union").concat(D(n)):I()},e}(zt),ce=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}),Object.defineProperty(e.prototype,"shouldAttachNode",{get:function(){return this.type.shouldAttachNode},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=M(i)?F(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&&E(this,t),t},e.prototype.isValidSnapshot=function(t,e){return void 0===t?I():this.type.validate(t,e)},e.prototype.isAssignableFrom=function(t){return this.type.isAssignableFrom(t)},e}(zt),le=Ot(ie,null),he=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,"shouldAttachNode",{get:function(){return this.subType.shouldAttachNode},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"subType",{get:function(){return null===this._subType&&(this._subType=this.definition()),this._subType},enumerable:!0,configurable:!0}),e.prototype.instantiate=function(t,e,n,r){return this.subType.instantiate(t,e,n,r)},e.prototype.reconcile=function(t,e){return this.subType.reconcile(t,e)},e.prototype.describe=function(){return this.subType.name},e.prototype.isValidSnapshot=function(t,e){return this.subType.validate(t,e)},e.prototype.isAssignableFrom=function(t){return this.subType.isAssignableFrom(t)},e}(zt),fe=new(function(t){function e(){var e=t.call(this,"frozen")||this;return e.shouldAttachNode=!1,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 k(this,t,e,n,tt(r))},e.prototype.isValidSnapshot=function(t,e){return et(t)?I():x(e,t,"Value is not serializable and cannot be frozen")},e}(zt)),de=function(){return function(t,e){if(this.mode=t,this.value=e,"object"===t){if(!M(e))return W("Can only store references to tree nodes, got: '"+e+"'");if(!F(e).identifierAttribute)return W("Can only store references with a defined identifier attribute.")}}}(),ye=function(t){function e(e){var n=t.call(this,"reference("+e.name+")")||this;return n.targetType=e,n.shouldAttachNode=!1,n.flags=Ct.Reference,n}return n(e,t),e.prototype.describe=function(){return this.name},e.prototype.isAssignableFrom=function(t){return this.targetType.isAssignableFrom(t)},e.prototype.isValidSnapshot=function(t,e){return"string"==typeof t||"number"==typeof t?I():x(e,t,"Value is not a valid identifier, which is a string or a number")},e}(zt),be=function(t){function e(e){return t.call(this,e)||this}return n(e,t),e.prototype.getValue=function(t){if(t.isAlive){var e=t.storedValue;if("object"===e.mode)return e.value;var n=t.root.identifierCache.resolve(this.targetType,e.value);return n?n.value:W("Failed to resolve reference '"+e.value+"' to type '"+this.targetType.name+"' (from node: "+t.path+")")}},e.prototype.getSnapshot=function(t){var e=t.storedValue;switch(e.mode){case"identifier":return e.value;case"object":return F(e.value).identifier}},e.prototype.instantiate=function(t,e,n,r){return k(this,t,e,n,new de(M(r)?"object":"identifier",r))},e.prototype.reconcile=function(t,e){if(t.type===this){var n=M(e)?"object":"identifier",r=t.storedValue;if(n===r.mode&&r.value===e)return t}var i=this.instantiate(t.parent,t.subpath,t._environment,e);return t.die(),i},e}(ye),ve=function(t){function e(e,n){var r=t.call(this,e)||this;return r.options=n,r}return n(e,t),e.prototype.getValue=function(t){if(t.isAlive)return this.options.get(t.storedValue,t.parent?t.parent.storedValue:null)},e.prototype.getSnapshot=function(t){return t.storedValue},e.prototype.instantiate=function(t,e,n,r){return k(this,t,e,n,M(r)?this.options.set(r,t?t.storedValue:null):r)},e.prototype.reconcile=function(t,e){var n=M(e)?this.options.set(e,t?t.storedValue:null):e;if(t.type===this&&t.storedValue===n)return t;var r=this.instantiate(t.parent,t.subpath,t._environment,n);return t.die(),r},e}(ye),me=function(t){function e(e){var n=t.call(this,"identifier("+e.name+")")||this;return n.identifierType=e,n.shouldAttachNode=!1,n.flags=Ct.Identifier,n}return n(e,t),e.prototype.instantiate=function(t,e,n,r){return t&&M(t.storedValue)?(t.identifierAttribute&&W("Cannot define property '"+e+"' as object identifier, property '"+t.identifierAttribute+"' is already defined as identifier property"),t.identifierAttribute=e,k(this,t,e,n,r)):W("Identifier types can only be instantiated as direct child of a model type")},e.prototype.reconcile=function(t,e){return t.storedValue!==e?W("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):x(e,t,"Value is not a valid identifier, which is a string or a number")},e}(zt),ge=function(t){function e(e){var n=t.call(this,e.name)||this;return n.options=e,n.flags=Ct.Reference,n.shouldAttachNode=!1,n}return n(e,t),e.prototype.describe=function(){return this.name},e.prototype.isAssignableFrom=function(t){return t===this},e.prototype.isValidSnapshot=function(t,e){if(this.options.isTargetType(t))return I();var n=this.options.getValidationMessage(t);return n?x(e,t,"Invalid value for type '"+this.name+"': "+n):I()},e.prototype.getValue=function(t){if(t.isAlive)return t.storedValue},e.prototype.getSnapshot=function(t){return this.options.toSnapshot(t.storedValue)},e.prototype.instantiate=function(t,e,n,r){return k(this,t,e,n,this.options.isTargetType(r)?r:this.options.fromSnapshot(r))},e.prototype.reconcile=function(t,e){var n=!this.options.isTargetType(e),r=!0;if(t.type===this&&(r=n?e===t.snapshot:e===t.storedValue),r)return t;var i=n?this.options.fromSnapshot(e):e,o=this.instantiate(t.parent,t.subpath,t._environment,i);return t.die(),o},e}(zt),we={enumeration:function(t,e){var n="string"==typeof t?e:t,r=Nt.apply(void 0,n.map(function(t){return Tt(""+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 Xt({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)},custom:function(t){return new ge(t)},reference:function(t,e){return e?new ve(t,e):new be(t)},union:Nt,optional:Ot,literal:Tt,maybe:function(t){return Nt(le,t)},refinement:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n="string"==typeof t[0]?t.shift():h(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 ue(n,r,i,o)},string:ee,boolean:re,number:ne,Date:ae,map:function(t){return new Kt("map<string, "+t.name+">",t)},array:function(t){return new qt(t.name+"[]",t)},frozen:fe,identifier:function(t){return void 0===t&&(t=ee),new me(t)},late:function(t,e){var n="string"==typeof t?t:"late("+t.toString()+")";return new he(n,"string"==typeof t?e:t)},undefined:oe,null:ie};t.types=we,t.typecheck=R,t.escapeJsonPath=ht,t.unescapeJsonPath=ft,t.decorate=function(t,e){var n={handler:t,includeHooks:!0};return e.$mst_middleware?e.$mst_middleware.push(n):e.$mst_middleware=[n],e},t.addMiddleware=P,t.process=function(t){return Zt("process","`process()` has been renamed to `flow()`. "+Ht),st(t)},t.isStateTreeNode=M,t.flow=st,t.applyAction=b,t.onAction=m,t.recordActions=function(t){var e={actions:[],stop:function(){return n()},replay:function(t){b(t,e.actions)}},n=m(t,e.actions.push.bind(e.actions));return e},t.createActionTrackingMiddleware=function(t){return function(e,n,r){switch(e.type){case"action":if(t.filter&&!0!==t.filter(e))return n(e);var i=t.onStart(e);t.onResume(e,i),Mt.set(e.id,{call:e,context:i,async:!1});try{var o=n(e);return t.onSuspend(e,i),!1===Mt.get(e.id).async&&(Mt.delete(e.id),t.onSuccess(e,i,o)),o}catch(n){throw Mt.delete(e.id),t.onFail(e,i,n),n}case"flow_spawn":return(a=Mt.get(e.rootId)).async=!0,n(e);case"flow_resume":case"flow_resume_error":a=Mt.get(e.rootId),t.onResume(e,a.context);try{return n(e)}finally{t.onSuspend(e,a.context)}case"flow_throw":return a=Mt.get(e.rootId),Mt.delete(e.id),t.onFail(e,a.context,e.args[0]),n(e);case"flow_return":var a=Mt.get(e.rootId);return Mt.delete(e.id),t.onSuccess(e,a.context,e.args[0]),n(e)}}},t.getType=o,t.getChildType=function(t,e){return F(t).getChildType(e)},t.onPatch=a,t.onSnapshot=function(t,e){return F(t).onSnapshot(e)},t.applyPatch=s,t.recordPatches=function(t){function e(){n||(n=a(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){s(e||t,r.patches)},undo:function(e){s(e||t,r.inversePatches.slice().reverse())}};return e(),r},t.protect=function(t){var e=F(t);e.isRoot||W("`protect` can only be invoked on root nodes"),e.isProtectionEnabled=!0},t.unprotect=function(t){var e=F(t);e.isRoot||W("`unprotect` can only be invoked on root nodes"),e.isProtectionEnabled=!1},t.isProtected=function(t){return F(t).isProtected},t.applySnapshot=u,t.getSnapshot=function(t){return F(t).snapshot},t.hasParent=function(t,e){void 0===e&&(e=1);for(var n=F(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=F(t).parent;r;){if(0==--n)return r.storedValue;r=r.parent}return W("Failed to find the parent of "+F(t)+" at depth "+e)},t.getRoot=p,t.getPath=function(t){return F(t).path},t.getPathParts=function(t){return yt(F(t).path)},t.isRoot=function(t){return F(t).isRoot},t.resolvePath=function(t,e){var n=U(F(t),e);return n?n.value:void 0},t.resolveIdentifier=function(t,e,n){var r=F(e).root.identifierCache.resolve(t,""+n);return r?r.value:void 0},t.getIdentifier=function(t){return F(t).identifier},t.tryResolve=c,t.getRelativePath=function(t,e){return $(F(t),F(e))},t.clone=function(t,e){void 0===e&&(e=!0);var n=F(t);return n.type.create(n.snapshot,!0===e?n.root._environment:!1===e?void 0:e)},t.detach=function(t){return F(t).detach(),t},t.destroy=function(t){var e=F(t);e.isRoot?e.die():e.parent.removeChild(e.subpath)},t.isAlive=function(t){return F(t).isAlive},t.addDisposer=function(t,e){F(t).addDisposer(e)},t.getEnv=function(t){var e=F(t).root._environment;return e||Jt},t.walk=l,t.getMembers=function(t){var n=F(t).type,r=Object.getOwnPropertyNames(t),i={name:n.name,properties:It({},n.properties),actions:[],volatile:[],views:[]};return r.forEach(function(n){if(!(n in i.properties)){var r=Object.getOwnPropertyDescriptor(t,n);r.get?e.isComputed(t,n)?i.views.push(n):i.volatile.push(n):!0===r.value._isMSTAction?i.actions.push(n):e.isObservable(t,n)?i.volatile.push(n):i.views.push(n)}}),i},Object.defineProperty(t,"__esModule",{value:!0})});

@@ -11,3 +11,3 @@ import { IObservableArray, IArrayWillChange, IArrayWillSplice, IArrayChange, IArraySplice } from "mobx";

createNewInstance: () => IObservableArray<{}>;
finalizeNewInstance: (node: ObjectNode, snapshot: any) => void;
finalizeNewInstance: (node: INode, snapshot: any) => void;
instantiate(parent: ObjectNode | null, subpath: string, environment: any, snapshot: S): INode;

@@ -14,0 +14,0 @@ getChildren(node: ObjectNode): INode[];

@@ -7,2 +7,7 @@ import { ObservableMap, IMapChange, IMapWillChange } from "mobx";

export declare function mapToString(this: ObservableMap<any>): string;
export declare enum MapIdentifierMode {
UNKNOWN = 0,
YES = 1,
NO = 2,
}
export declare class MapType<S, T> extends ComplexType<{

@@ -13,2 +18,4 @@ [key: string]: S;

subType: IType<any, any>;
identifierMode: MapIdentifierMode;
identifierAttribute: string | undefined;
readonly flags: TypeFlags;

@@ -19,7 +26,7 @@ constructor(name: string, subType: IType<any, any>);

createNewInstance: () => ObservableMap<{}>;
finalizeNewInstance: (node: ObjectNode, snapshot: any) => void;
finalizeNewInstance: (node: INode, snapshot: any) => void;
getChildren(node: ObjectNode): INode[];
getChildNode(node: ObjectNode, key: string): INode;
willChange(change: IMapWillChange<any>): IMapWillChange<any> | null;
private verifyIdentifier(expected, node);
private processIdentifier(expected, node);
getValue(node: ObjectNode): any;

@@ -26,0 +33,0 @@ getSnapshot(node: ObjectNode): {

import { IObjectChange, IObjectWillChange } from "mobx";
import { IStateTreeNode, IJsonPatch, INode, ComplexType, IComplexType, IType, TypeFlags, IContext, IValidationResult, ObjectNode } from "../../internal";
export declare enum HookNames {
afterCreate = "afterCreate",
afterAttach = "afterAttach",
postProcessSnapshot = "postProcessSnapshot",
beforeDetach = "beforeDetach",
beforeDestroy = "beforeDestroy",
}
export declare type ModelTypeConfig = {

@@ -19,4 +26,4 @@ name?: string;

private preProcessor;
private readonly propertiesNames;
constructor(opts: ModelTypeConfig);
readonly propertyNames: string[];
cloneAndEnhance(opts: ModelTypeConfig): ModelType<any, any>;

@@ -31,5 +38,5 @@ actions<A extends {

props<SP, TP>(properties: {
[K in keyof TP]: IType<any, TP[K]>;
[K in keyof TP]: IType<any, TP[K]> | TP[K];
} & {
[K in keyof SP]: IType<SP[K], any>;
[K in keyof SP]: IType<SP[K], any> | SP[K];
}): IModelType<S & SP, T & TP>;

@@ -50,3 +57,3 @@ volatile<TP>(fn: (self: T) => TP): IModelType<S, T & TP>;

createNewInstance: () => Object;
finalizeNewInstance: (node: ObjectNode, snapshot: any) => void;
finalizeNewInstance: (node: INode, snapshot: any) => void;
willChange(change: IObjectWillChange): IObjectWillChange | null;

@@ -69,2 +76,5 @@ didChange: (change: IObjectChange) => void;

export interface IModelType<S, T> extends IComplexType<S, T & IStateTreeNode> {
readonly properties: {
readonly [K: string]: IType<any, any>;
};
named(newName: string): IModelType<S, T>;

@@ -71,0 +81,0 @@ props<SP, TP>(props: {

@@ -1,5 +0,5 @@

import { INode, Type, IType, TypeFlags, IContext, IValidationResult, ObjectNode } from "../../internal";
import { IStateTreeNode } from "../../index";
import { INode, Type, IType, TypeFlags, IContext, IValidationResult, ObjectNode, IStateTreeNode } from "../../internal";
export declare abstract class BaseReferenceType<T> extends Type<string | number, T> {
protected readonly targetType: IType<any, T>;
readonly shouldAttachNode: boolean;
readonly flags: TypeFlags;

@@ -12,3 +12,2 @@ constructor(targetType: IType<any, T>);

export declare class IdentifierReferenceType<T> extends BaseReferenceType<T> {
readonly shouldAttachNode: boolean;
constructor(targetType: IType<any, T>);

@@ -22,3 +21,2 @@ getValue(node: INode): any;

private readonly options;
readonly shouldAttachNode: boolean;
constructor(targetType: IType<any, T>, options: ReferenceOptions<T>);

@@ -25,0 +23,0 @@ getValue(node: INode): T | undefined;

{
"name": "mobx-state-tree",
"version": "1.3.1",
"version": "1.4.0",
"description": "Opinionated, transactional, MobX powered state container",

@@ -10,16 +10,12 @@ "main": "dist/mobx-state-tree.js",

"scripts": {
"build": "npm run quick-build && cpr lib dist --delete-first --filter=\\\\.js && rollup -c",
"quick-build": "tsc",
"build": "tsc && cpr lib dist --delete-first --filter=\\\\.js && yarn rollup",
"rollup": "rollup -c",
"build-tests": "tsc -p test/",
"test": "npm run build-tests && cross-env NODE_ENV=development ava && cross-env NODE_ENV=production ava && npm run test-cyclic",
"update-snapshots": "ava -u",
"speedtest": "npm run build-tests && node --expose-gc test-lib/test/perf/report.js",
"test": "cross-env NODE_ENV=development jest --ci && cross-env NODE_ENV=production jest --ci && npm run test-cyclic && npm run speedtest",
"speedtest": "node --expose-gc test/perf/report.js",
"test-cyclic": "npm run build && node -e \"require('.')\"",
"watch": "(tsc -p test --skipLibCheck || true) && concurrently --kill-others --names 'build-tests,test-runner' 'tsc --skipLibCheck --watch -p test' --raw 'ava --watch'",
"watch": "jest --watch",
"_prepublish": "npm run build && npm run build-docs",
"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",
"lint": "tslint -c tslint.json 'src/**/*.ts'",
"clean": "rm -rf lib test-lib .nyc_output coverage"
"coverage": "jest --coverage",
"build-docs": "tsc && 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'"
},

@@ -39,4 +35,4 @@ "repository": {

"devDependencies": {
"@types/jest": "^22.2.0",
"@types/node": "^8.0.19",
"ava": "^0.19.1",
"concat": "^1.0.3",

@@ -48,4 +44,4 @@ "concurrently": "^3.1.0",

"documentation": "^5.2.2",
"jest": "^22.4.2",
"mobx": "^3.2.2",
"nyc": "^10.0.0",
"rollup": "^0.43.0",

@@ -58,6 +54,6 @@ "rollup-plugin-commonjs": "^8.0.2",

"sinon": "^3.2.1",
"tape": "^4.6.0",
"ts-jest": "^22.4.1",
"tslib": "^1.7.1",
"tslint": "^3.15.1",
"typescript": "^2.4.2"
"typescript": "^2.7.0"
},

@@ -76,10 +72,27 @@ "peerDependencies": {

],
"ava": {
"files": [
"test-lib/test/*.js"
"jest": {
"transform": {
"^.+\\.tsx?$": "ts-jest",
"^.+\\.jsx?$": "babel-jest"
},
"testRegex": "test/.*\\.(t|j)sx?$",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx",
"json"
],
"source": [
"test-lib/src/**/*.js"
"testPathIgnorePatterns": [
"/node_modules/",
"/src/",
"/dist/",
"/test/fixtures",
"/test/perf",
"/\\./"
],
"watchPathIgnorePatterns": [
"<rootDir>/node_modules/"
]
}
}

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc