mobx-state-tree
Advanced tools
Comparing version 0.9.1 to 0.9.2
@@ -0,1 +1,9 @@ | ||
# 0.9.2 | ||
Introduced the concept of reverse patches, see [#231](https://github.com/mobxjs/mobx-state-tree/pull/231/) | ||
* Introduced the `revertPatch` operation, that takes a patch or list of patches, and reverse applies it to the target. | ||
* `onPatch` now takes a second argument, `includeOldValue`, defaulting to `false`, which, if set to true, includes in the patch any value that is being overwritten as result of the patch. Setting this option to true produces patches that can be used with `revertPatch` | ||
* `patchRecorder` now introduces additional fields / methods to be able to reverse apply changes: `patchRecorder.cleanPatches`, `patchRecorder.undo` | ||
# 0.9.1 | ||
@@ -2,0 +10,0 @@ |
@@ -6,2 +6,7 @@ export declare type IJsonPatch = { | ||
}; | ||
export declare type IReversibleJsonPatch = IJsonPatch & { | ||
oldValue?: any; | ||
}; | ||
export declare function invertPatch(patch: IReversibleJsonPatch): IReversibleJsonPatch; | ||
export declare function stripPatch(patch: IReversibleJsonPatch): IJsonPatch; | ||
/** | ||
@@ -8,0 +13,0 @@ * escape slashes and backslashes |
@@ -74,5 +74,7 @@ /** | ||
* @param {(patch: IJsonPatch) => void} callback the callback that is invoked for each patch | ||
* @param {includeOldValue} boolean if oldValue is included in the patches, they can be inverted. However patches will become much bigger and might not be suitable for efficient transport | ||
* @returns {IDisposer} function to remove the listener | ||
*/ | ||
export declare function onPatch(target: IStateTreeNode, callback: (patch: IJsonPatch) => void): IDisposer; | ||
export declare function onPatch(target: IStateTreeNode, callback: (patch: IReversibleJsonPatch) => void, includeOldValue: true): IDisposer; | ||
export declare function onSnapshot<S>(target: ObservableMap<S>, callback: (snapshot: { | ||
@@ -95,6 +97,20 @@ [key: string]: S; | ||
export declare function applyPatch(target: IStateTreeNode, patch: IJsonPatch | IJsonPatch[]): void; | ||
/** | ||
* The inverse function of apply patch. | ||
* Given a patch or set of patches, restores the target to the state before the patches where produced. | ||
* The inverse patch is computed, and all the patches are applied in reverse order, basically 'rewinding' the target, | ||
* so that conceptually the following holds for any set of patches: | ||
* | ||
* `getSnapshot(x) === getSnapshot(revertPatch(applyPatches(x, patches), patches))` | ||
* | ||
* Note: Reverting patches will generate a new set of patches as side effect of applying the patches. | ||
* Note: only patches that include `oldValue` information are suitable for reverting. Such patches can be generated by passing `true` as second argument when attaching an `onPatch` listener. | ||
*/ | ||
export declare function revertPatch(target: IStateTreeNode, patch: IReversibleJsonPatch | IReversibleJsonPatch[]): void; | ||
export interface IPatchRecorder { | ||
patches: IJsonPatch[]; | ||
patches: ReadonlyArray<IReversibleJsonPatch>; | ||
cleanPatches: ReadonlyArray<IJsonPatch>; | ||
stop(): any; | ||
replay(target: IStateTreeNode): any; | ||
replay(target?: IStateTreeNode): any; | ||
undo(target?: IStateTreeNode): void; | ||
} | ||
@@ -109,6 +125,11 @@ /** | ||
* patches: IJsonPatch[] | ||
* // the same set of recorded patches, but without undo information, making them smaller and compliant with json-patch spec | ||
* cleanPatches: IJSonPatch[] | ||
* // stop recording patches | ||
* stop(): any | ||
* // apply all the recorded patches on the given object | ||
* replay(target: IStateTreeNode): any | ||
* stop(target?: IStateTreeNode): any | ||
* // apply all the recorded patches on the given target (the original subject if omitted) | ||
* replay(target?: IStateTreeNode): any | ||
* // reverse apply the recorded patches on the given target (the original subject if omitted) | ||
* // stops the recorder if not already stopped | ||
* undo(): void | ||
* } | ||
@@ -134,3 +155,3 @@ * ``` | ||
export interface IActionRecorder { | ||
actions: ISerializedActionCall[]; | ||
actions: ReadonlyArray<ISerializedActionCall>; | ||
stop(): any; | ||
@@ -146,3 +167,3 @@ replay(target: IStateTreeNode): any; | ||
* // the recorded actions | ||
* actions: IJsonPatch[] | ||
* actions: ISerializedActionCall[] | ||
* // stop recording actions | ||
@@ -303,4 +324,4 @@ * stop(): any | ||
import { IStateTreeNode } from "./node"; | ||
import { IJsonPatch } from "./json-patch"; | ||
import { IJsonPatch, IReversibleJsonPatch } from "./json-patch"; | ||
import { IDisposer } from "../utils"; | ||
import { ISnapshottable, IType } from "../types/type"; |
@@ -19,3 +19,3 @@ export declare class Node { | ||
private readonly disposers; | ||
applyPatches: (patches: IJsonPatch[]) => void; | ||
applyPatches: (patches: IReversibleJsonPatch[]) => void; | ||
applySnapshot: (snapshot: any) => void; | ||
@@ -42,5 +42,5 @@ constructor(type: IType<any, any>, parent: Node | null, subpath: string, environment: any, storedValue: any); | ||
emitSnapshot(snapshot: any): void; | ||
applyPatchLocally(subpath: string, patch: IJsonPatch): void; | ||
onPatch(onPatch: (patches: IJsonPatch) => void): IDisposer; | ||
emitPatch(patch: IJsonPatch, source: Node): void; | ||
applyPatchLocally(subpath: string, patch: IReversibleJsonPatch): void; | ||
onPatch(onPatch: (patch: IReversibleJsonPatch) => void, includeOldValue: boolean): IDisposer; | ||
emitPatch(patch: IReversibleJsonPatch, source: Node): void; | ||
setParent(newParent: Node | null, subpath?: string | null): void; | ||
@@ -68,5 +68,5 @@ addDisposer(disposer: () => void): void; | ||
import { IType } from "../types/type"; | ||
import { IJsonPatch } from "./json-patch"; | ||
import { IReversibleJsonPatch } from "./json-patch"; | ||
import { IMiddleWareHandler } from "./action"; | ||
import { IDisposer } from "../utils"; | ||
import { IdentifierCache } from "./identifier-cache"; |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("mobx")):"function"==typeof define&&define.amd?define(["exports","mobx"],e):e(t.mobxStateTree=t.mobxStateTree||{},t.mobx)}(this,function(t,e){"use strict";function n(t,e){function n(){this.constructor=t}Pt(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}function r(t,e,n,r){var i,o=arguments.length,a=o<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,n,r);else for(var s=t.length-1;s>=0;s--)(i=t[s])&&(a=(o<3?i(a):o>3?i(e,n,a):i(e,n))||a);return o>3&&a&&Object.defineProperty(e,n,a),a}function i(t){return t.replace(/~/g,"~1").replace(/\//g,"~0")}function o(t){return t.replace(/~0/g,"\\").replace(/~1/g,"~")}function a(t){return 0===t.length?"":"/"+t.map(i).join("/")}function s(t){var e=t.split("/").map(o);return""===e[0]?e.slice(1):e}function u(t){throw void 0===t&&(t="Illegal state"),new Error("[mobx-state-tree] "+t)}function p(t){return t}function c(){}function l(t){return!(!Array.isArray(t)&&!e.isObservableArray(t))}function h(t){return t?l(t)?t:[t]:At}function f(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 d(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];for(var r=0;r<e.length;r++){var i=e[r];for(var o in i){var a=Object.getOwnPropertyDescriptor(i,o);"get"in a?Object.defineProperty(t,o,jt({},a,{configurable:!0})):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 v(t){return!(null===t||"object"!=typeof t||t instanceof Date||t instanceof RegExp)}function b(t){return null===t||void 0===t||("string"==typeof t||"number"==typeof t||"boolean"==typeof t||t instanceof Date)}function g(t){return b(t)?t:Object.freeze(t)}function m(t){return g(t),y(t)&&Object.keys(t).forEach(function(e){b(t[e])||Object.isFrozen(t[e])||m(t[e])}),t}function w(t){return"function"!=typeof t}function P(t,e,n){Object.defineProperty(t,e,{enumerable:!1,writable:!1,configurable:!0,value:n})}function j(t,e,n){Object.defineProperty(t,e,{enumerable:!0,writable:!1,configurable:!0,value:n})}function A(t,e){return t.push(e),function(){var n=t.indexOf(e);-1!==n&&t.splice(n,1)}}function V(t,e){return Vt.call(t,e)}function C(t){for(var e=new Array(t.length),n=0;n<t.length;n++)e[n]=t[n];return e}function S(t){for(var e=t.middlewares.slice(),n=t;n.parent;)n=n.parent,e=e.concat(n.middlewares);return e}function T(t,e,n){function r(t){var o=i.shift();return o?o(t,r):n.apply(e.object,e.args)}var i=S(t);return i.length?r(e):n.apply(e.object,e.args)}function O(t,n){var r=e.action(t,n);return function(){var e=G(this);if(e.assertAlive(),e.isRunningAction())return r.apply(this,arguments);var n={name:t,object:e.storedValue,args:C(arguments)},i=e.root;i._isRunningAction=!0;try{return T(e,n,r)}finally{i._isRunningAction=!1}}}function x(t,n,r,i){if(b(i))return i;if(q(i)){var o=G(i);if(t.root!==o.root)throw new Error("Argument "+r+" that was passed to action '"+n+"' is a model that is not part of the same state tree. Consider passing a snapshot or some representative ID instead");return{$ref:t.getRelativePathTo(G(i))}}if("function"==typeof i)throw new Error("Argument "+r+" that was passed to action '"+n+"' should be a primitive, model object or plain object, received a function");if("object"==typeof i&&!y(i)&&!l(i))throw new Error("Argument "+r+" that was passed to action '"+n+"' should be a primitive, model object or plain object, received a "+(i&&i.constructor?i.constructor.name:"Complex Object"));if(e.isObservable(i))throw new Error("Argument "+r+" that was passed to action '"+n+"' should be a primitive, model object or plain object, received an mobx observable.");try{return JSON.stringify(i),i}catch(t){throw new Error("Argument "+r+" that was passed to action '"+n+"' is not serializable.")}}function _(t,e){if("object"==typeof e){var n=Object.keys(e);if(1===n.length&&"$ref"===n[0])return W(t.storedValue,e.$ref)}return e}function N(t,e){var n=B(t,e.path||"");if(!n)return u("Invalid action path: "+(e.path||""));var r=G(n);return"@APPLY_PATCHES"===e.name?H.call(null,n,e.args[0]):"@APPLY_SNAPSHOT"===e.name?$.call(null,n,e.args[0]):("function"!=typeof n[e.name]&&u("Action '"+e.name+"' does not exist in '"+r.path+"'"),n[e.name].apply(n,e.args?e.args.map(function(t){return _(r,t)}):[]))}function z(t,e){return F(t,function(n,r){var i=G(n.object);return e({name:n.name,path:G(t).getRelativePathTo(i),args:n.args.map(function(t,e){return x(i,n.name,e,t)})}),r(n)})}function D(t){return"object"==typeof t&&t&&!0===t.isType}function I(t){return D(t)&&(t.flags&(wt.String|wt.Number|wt.Boolean|wt.Date))>0}function E(t){return D(t)&&(t.flags&wt.Object)>0}function R(t){return(t.flags&wt.Reference)>0}function k(t){return G(t).type}function F(t,e){var n=G(t);return n.isProtectionEnabled||console.warn("It is recommended to protect the state tree before attaching action middleware, as otherwise it cannot be guaranteed that all changes are passed through middleware. See `protect`"),n.addMiddleWare(e)}function L(t,e){return G(t).onPatch(e)}function M(t,e){return G(t).onSnapshot(e)}function H(t,e){G(t).applyPatches(h(e))}function U(t,n){e.runInAction(function(){h(n).forEach(function(e){return N(t,e)})})}function $(t,e){return G(t).applySnapshot(e)}function J(t){return G(t).snapshot}function W(t,e){var n=G(t).resolve(e);return n?n.value:void 0}function B(t,e){var n=G(t).resolve(e,!1);if(void 0!==n)return n?n.value:void 0}function Y(t,e){var n=G(t);n.getChildren().forEach(function(t){q(t.storedValue)&&Y(t.storedValue,e)}),e(n.storedValue)}function q(t){return!(!t||!t.$treenode)}function G(t){return q(t)?t.$treenode:u("Value "+t+" is no MST Node")}function K(t){return t&&"object"==typeof t&&!(t instanceof Date)&&!q(t)&&!Object.isFrozen(t)}function Q(){return G(this).snapshot}function X(t,e,n,r,i,o,a){if(void 0===o&&(o=p),void 0===a&&(a=c),q(i)){var s=G(i);return s.isRoot||u("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 l=o(i),h=K(l),f=new Tt(t,e,n,r,l);e||(f.identifierCache=new Ct),h&&P(l,"$treenode",f);var d=!0;try{return h&&j(l,"toJSON",Q),f._isRunningAction=!0,a(f,i),f._isRunningAction=!1,e?e.root.identifierCache.addNodeToCache(f):f.identifierCache.addNodeToCache(f),f.fireHook("afterCreate"),e&&f.fireHook("afterAttach"),d=!1,f}finally{d&&(f._isAlive=!1)}}function Z(t){return"function"==typeof t?"<function"+(t.name?" "+t.name:"")+">":q(t)?"<"+t+">":"`"+JSON.stringify(t)+"`"}function tt(t){var e=t.value,n=t.context[t.context.length-1].type,r=t.context.map(function(t){return t.path}).filter(function(t){return t.length>0}).join("/"),i=r.length>0?'at path "/'+r+'" ':"",o=q(e)?"value of type "+G(e).type.name+":":b(e)?"value":"snapshot",a=n&&q(e)&&n.is(G(e).snapshot);return""+i+o+" "+Z(e)+" is not assignable "+(n?"to type: `"+n.name+"`":"")+(t.message?" ("+t.message+")":"")+(n?I(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 et(t,e,n){return t.concat([{path:e,type:n}])}function nt(){return At}function rt(t,e,n){return[{context:t,value:e,message:n}]}function it(t){return t.reduce(function(t,e){return t.concat(e)},[])}function ot(t,e){var n=t.validate(e,[{path:"",type:t}]);n.length>0&&u("Error while converting "+Z(e)+" to `"+t.name+"`:\n"+n.map(tt).join("\n"))}function at(){return G(this)+"("+this.size+" items)"}function st(t){t||u("Map.put cannot be used to set empty values");var e;if(q(t))e=G(t);else{if(!v(t))return u("Map.put can only be used to store complex values");e=G(G(this).type.subType.create(t))}return e.identifierAttribute||u("Map.put can only be used to store complex values that have an identifier type attribute"),this.set(e.identifier,e.value),this}function ut(){return G(this)+"("+this.length+" items)"}function pt(t,e,n,r,i){function o(t){for(var e in p){var n=t[e];if(("string"==typeof n||"number"==typeof n)&&p[e][n])return p[e][n]}return null}var a=new Array(r.length),s={},p={};n.forEach(function(t){t.identifierAttribute&&((p[t.identifierAttribute]||(p[t.identifierAttribute]={}))[t.identifier]=t),s[t.nodeId]=t}),r.forEach(function(n,r){var p=""+i[r];if(q(n))(l=G(n)).assertAlive(),l.parent===t?(s[l.nodeId]||u("Cannot add an object to a state tree if it is already part of the same or another state tree. Tried to assign an object to '"+t.path+"/"+p+"', but it lives already at '"+l.path+"'"),s[l.nodeId]=void 0,l.setParent(t,p),a[r]=l):a[r]=e.instantiate(t,p,void 0,n);else if(v(n)){var c=o(n);if(c){var l=e.reconcile(c,n);s[c.nodeId]=void 0,l.setParent(t,p),a[r]=l}else a[r]=e.instantiate(t,p,void 0,n)}else a[r]=e.instantiate(t,p,void 0,n)});for(var c in s)void 0!==s[c]&&s[c].die();return a}function ct(t){switch(typeof t){case"string":return Dt;case"number":return It;case"boolean":return Et;case"object":if(t instanceof Date)return Rt}return u("Cannot determine primtive type from value "+t)}function lt(t,e){var n="function"==typeof e?e():e;return ot(t,q(n)?G(n).snapshot:n),new Ft(t,e)}function ht(t){return b(t)||u("Literal types can be built only on top of primitives"),new Ht(t)}function ft(t,n){return function(){var t=this,r=arguments;return G(this).assertAlive(),e.extras.allowStateChanges(!1,function(){return n.apply(t,r)})}}function dt(){return G(this).toString()}function yt(){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()||u("types.model must specify properties"),i=t.length>1&&t.shift()||{},o=t.shift()||{};return new qt(n,r,i,o)}function vt(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n="string"==typeof t[0]?t.shift():"AnonymousModel";if(t.every(function(t){return D(t)}))return t.reduce(function(t,e){return vt(n,t,e.properties,e.state,e.actions)});var r=t.shift(),i=t.shift()||u("types.compose must specify properties or `{}`"),o=t.length>1&&t.shift()||{},a=t.shift()||{};return E(r)?yt(n,d({},r.properties,i),d({},r.state,o),d({},r.actions,a)):u("Only model types can be composed")}function bt(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var r=D(t)?null:t,i=D(t)?e.concat(t):e,o=i.map(function(t){return t.name}).join(" | ");return new Qt(o,i,r)}function gt(t){var e=f({},t);return delete e.type,{name:t.type,args:[e]}}function mt(t,e,n){function r(t){var i=e.shift();i?i(r)(t):n(t)}r(t)}var wt,Pt=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])},jt=Object.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},At=Object.freeze([]),Vt=Object.prototype.hasOwnProperty;!function(t){t[t.String=1]="String",t[t.Number=2]="Number",t[t.Boolean=4]="Boolean",t[t.Date=8]="Date",t[t.Literal=16]="Literal",t[t.Array=32]="Array",t[t.Map=64]="Map",t[t.Object=128]="Object",t[t.Frozen=256]="Frozen",t[t.Optional=512]="Optional",t[t.Reference=1024]="Reference",t[t.Identifier=2048]="Identifier",t[t.Late=4096]="Late",t[t.Refinement=8192]="Refinement",t[t.Union=16384]="Union"}(wt||(wt={}));var Ct=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)&&u("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 u("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}(),St=1,Tt=function(){function t(t,n,r,i,o){var a=this;this.nodeId=++St,this._parent=null,this.subpath="",this.isProtectionEnabled=!0,this.identifierAttribute=void 0,this._environment=void 0,this._isRunningAction=!1,this._autoUnbox=!0,this._isAlive=!0,this._isDetaching=!1,this.middlewares=[],this.snapshotSubscribers=[],this.patchSubscribers=[],this.disposers=[],this.type=t,this._parent=n,this.subpath=r,this.storedValue=o,this._environment=i,this.unbox=this.unbox.bind(this),this.applyPatches=O("@APPLY_PATCHES",function(t){t.forEach(function(t){var e=s(t.path);a.resolvePath(e.slice(0,-1)).applyPatchLocally(e[e.length-1],t)})}).bind(this.storedValue),this.applySnapshot=O("@APPLY_SNAPSHOT",function(t){return a.type.applySnapshot(a,t)}).bind(this.storedValue);var u=e.reaction(function(){return a.snapshot},function(t){a.emitSnapshot(t)});u.onError(function(t){throw t}),this.addDisposer(u)}return Object.defineProperty(t.prototype,"identifier",{get:function(){return this.identifierAttribute?this.storedValue[this.identifierAttribute]:null},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"path",{get:function(){return this.parent?this.parent.path+"/"+i(this.subpath):""},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isRoot",{get:function(){return null===this.parent},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"parent",{get:function(){return this._parent},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"root",{get:function(){for(var t,e=this;t=e.parent;)e=t;return e},enumerable:!0,configurable:!0}),t.prototype.getRelativePathTo=function(t){this.root!==t.root&&u("Cannot calculate relative path: objects '"+this+"' and '"+t+"' are not part of the same object tree");for(var e=s(this.path),n=s(t.path),r=0;r<e.length&&e[r]===n[r];r++);return e.slice(r).map(function(t){return".."}).join("/")+a(n.slice(r))},t.prototype.resolve=function(t,e){return void 0===e&&(e=!0),this.resolvePath(s(t),e)},t.prototype.resolvePath=function(t,e){void 0===e&&(e=!0);for(var n=this,r=0;r<t.length;r++){if(""===t[r])n=n.root;else if(".."===t[r])n=n.parent;else{if("."===t[r]||""===t[r])continue;if(n){n=n.getChildNode(t[r]);continue}}if(!n)return e?u("Could not resolve '"+t[r]+"' in '"+a(t.slice(0,r-1))+"', path of the patch does not resolve"):void 0}return n},Object.defineProperty(t.prototype,"value",{get:function(){if(this._isAlive)return this.type.getValue(this)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isAlive",{get:function(){return this._isAlive},enumerable:!0,configurable:!0}),t.prototype.die=function(){this._isDetaching||q(this.storedValue)&&(Y(this.storedValue,function(t){return G(t).aboutToDie()}),Y(this.storedValue,function(t){return G(t).finalizeDeath()}))},t.prototype.aboutToDie=function(){this.disposers.splice(0).forEach(function(t){return t()}),this.fireHook("beforeDestroy")},t.prototype.finalizeDeath=function(){this.root.identifierCache.notifyDied(this);var t=this,e=this.path;j(this,"snapshot",this.snapshot),this.patchSubscribers.splice(0),this.snapshotSubscribers.splice(0),this.patchSubscribers.splice(0),this._isAlive=!1,this._parent=null,this.subpath="",Object.defineProperty(this.storedValue,"$mobx",{get:function(){u("This object has died and is no longer part of a state tree. It cannot be used anymore. The object (of type '"+t.type.name+"') used to live at '"+e+"'. It is possible to access the last snapshot of this object using 'getSnapshot', or to create a fresh copy using 'clone'. If you want to remove an object from the tree without killing it, use 'detach' instead.")}})},t.prototype.assertAlive=function(){this._isAlive||u(this+" cannot be used anymore as it has died; it has been removed from a state tree. If you want to remove an element from a tree and let it live on, use 'detach' or 'clone' the value")},Object.defineProperty(t.prototype,"snapshot",{get:function(){if(this._isAlive)return g(this.type.getSnapshot(this))},enumerable:!0,configurable:!0}),t.prototype.onSnapshot=function(t){return A(this.snapshotSubscribers,t)},t.prototype.emitSnapshot=function(t){this.snapshotSubscribers.forEach(function(e){return e(t)})},t.prototype.applyPatchLocally=function(t,e){this.assertWritable(),this.type.applyPatchLocally(this,t,e)},t.prototype.onPatch=function(t){return A(this.patchSubscribers,t)},t.prototype.emitPatch=function(t,e){if(this.patchSubscribers.length){var n=f({},t,{path:e.path.substr(this.path.length)+"/"+t.path});this.patchSubscribers.forEach(function(t){return t(n)})}this.parent&&this.parent.emitPatch(t,e)},t.prototype.setParent=function(t,e){void 0===e&&(e=null),this.parent===t&&this.subpath===e||(this._parent&&t&&t!==this._parent&&u("A node cannot exists twice in the state tree. Failed to add "+this+" to path '"+t.path+"/"+e+"'."),!this._parent&&t&&t.root===this&&u("A state tree is not allowed to contain itself. Cannot assign "+this+" to path '"+t.path+"/"+e+"'"),!this._parent&&this._environment&&u("A state tree that has been initialized with an environment cannot be made part of another state tree."),this.parent&&!t?this.die():(this.subpath=e||"",t&&t!==this._parent&&(t.root.identifierCache.mergeCache(this),this._parent=t,this.fireHook("afterAttach"))))},t.prototype.addDisposer=function(t){this.disposers.unshift(t)},t.prototype.isRunningAction=function(){return!!this._isRunningAction||!this.isRoot&&this.parent.isRunningAction()},t.prototype.addMiddleWare=function(t){return A(this.middlewares,t)},t.prototype.getChildNode=function(t){this.assertAlive(),this._autoUnbox=!1;var e=this.type.getChildNode(this,t);return this._autoUnbox=!0,e},t.prototype.getChildren=function(){this.assertAlive(),this._autoUnbox=!1;var t=this.type.getChildren(this);return this._autoUnbox=!0,t},t.prototype.getChildType=function(t){return this.type.getChildType(t)},Object.defineProperty(t.prototype,"isProtected",{get:function(){return this.root.isProtectionEnabled},enumerable:!0,configurable:!0}),t.prototype.assertWritable=function(){this.assertAlive(),!this.isRunningAction()&&this.isProtected&&u("Cannot modify '"+this+"', the object is protected and can only be modified by using an action.")},t.prototype.removeChild=function(t){this.type.removeChild(this,t)},t.prototype.detach=function(){this._isAlive||u("Error while detaching, node is not alive."),this.isRoot||(this.fireHook("beforeDetach"),this._environment=this.root._environment,this._isDetaching=!0,this.identifierCache=this.root.identifierCache.splitCache(this),this.parent.removeChild(this.subpath),this._parent=null,this.subpath="",this._isDetaching=!1)},t.prototype.unbox=function(t){return t&&!0===this._autoUnbox?t.value:t},t.prototype.fireHook=function(t){var e=this.storedValue&&"object"==typeof this.storedValue&&this.storedValue[t];"function"==typeof e&&e.apply(this.storedValue)},t.prototype.toString=function(){var t=this.identifier?"(id: "+this.identifier+")":"";return this.type.name+"@"+(this.path||"<root>")+t+(this.isAlive?"":"[dead]")},r([e.observable],t.prototype,"_parent",void 0),r([e.observable],t.prototype,"subpath",void 0),r([e.computed],t.prototype,"path",null),r([e.computed],t.prototype,"value",null),r([e.computed],t.prototype,"snapshot",null),t}(),Ot=function(){function t(t){this.isType=!0,this.name=t}return t.prototype.create=function(t,e){return void 0===t&&(t=this.getDefaultSnapshot()),ot(this,t),this.instantiate(null,"",e,t).value},t.prototype.isAssignableFrom=function(t){return t===this},t.prototype.validate=function(t,e){return q(t)?k(t)===this||this.isAssignableFrom(k(t))?nt():rt(e,t):this.isValidSnapshot(t,e)},t.prototype.is=function(t){return 0===this.validate(t,[{path:"",type:this}]).length},t.prototype.reconcile=function(t,e){var n=t.parent,r=t.subpath;if(q(e)&&G(e)===t)return t;if(t.type===this&&v(e)&&!q(e)&&(!t.identifierAttribute||t.identifier===e[t.identifierAttribute]))return t.applySnapshot(e),t;if(t.die(),q(e)&&this.isAssignableFrom(k(e))){var i=G(e);return i.setParent(n,r),i}return this.instantiate(n,r,t._environment,e)},Object.defineProperty(t.prototype,"Type",{get:function(){return u("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 u("Factory.SnapshotType should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.SnapshotType`")},enumerable:!0,configurable:!0}),r([e.action],t.prototype,"create",null),t}(),xt=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){u("Immutable types do not support applying snapshots")},e.prototype.applyPatchLocally=function(t,e,n){u("Immutable types do not support applying patches")},e.prototype.getChildren=function(t){return At},e.prototype.getChildNode=function(t,e){return u("No child '"+e+"' available in type: "+this.name)},e.prototype.getChildType=function(t){return u("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 u("No child '"+e+"' available in type: "+this.name)},e}(Ot),_t=function(t){function o(n,r){var i=t.call(this,n)||this;return i.shouldAttachNode=!0,i.flags=wt.Map,i.createNewInstance=function(){var t=e.observable.shallowMap();return P(t,"put",st),P(t,"toString",at),t},i.finalizeNewInstance=function(t,n){var r=t.storedValue;e.extras.interceptReads(r,t.unbox),e.intercept(r,function(t){return i.willChange(t)}),t.applySnapshot(n),e.observe(r,i.didChange)},i.subType=r,i}return n(o,t),o.prototype.instantiate=function(t,e,n,r){return X(this,t,e,n,r,this.createNewInstance,this.finalizeNewInstance)},o.prototype.describe=function(){return"Map<string, "+this.subType.describe()+">"},o.prototype.getChildren=function(t){return t.storedValue.values()},o.prototype.getChildNode=function(t,e){var n=t.storedValue.get(e);return n||u("Not a child "+e),n},o.prototype.willChange=function(t){var e=G(t.object);switch(e.assertWritable(),t.type){case"update":var n=t.newValue;if(n===t.object.get(t.name))return null;ot(this.subType,n),t.newValue=this.subType.reconcile(e.getChildNode(t.name),t.newValue),this.verifyIdentifier(t.name,t.newValue);break;case"add":ot(this.subType,t.newValue),t.newValue=this.subType.instantiate(e,t.name,void 0,t.newValue),this.verifyIdentifier(t.name,t.newValue);break;case"delete":e.getChildNode(t.name).die()}return t},o.prototype.verifyIdentifier=function(t,e){var n=e.identifier;null!==n&&""+n!=""+t&&u("A map of objects containing an identifier should always store the object under their own identifier. Trying to store key '"+n+"', but expected: '"+t+"'")},o.prototype.getValue=function(t){return t.storedValue},o.prototype.getSnapshot=function(t){var e={};return t.getChildren().forEach(function(t){e[t.subpath]=t.snapshot}),e},o.prototype.didChange=function(t){var e=G(t.object);switch(t.type){case"update":case"add":return void e.emitPatch({op:"add"===t.type?"add":"replace",path:i(t.name),value:e.getChildNode(t.name).snapshot},e);case"delete":return void e.emitPatch({op:"remove",path:i(t.name)},e)}},o.prototype.applyPatchLocally=function(t,e,n){var r=t.storedValue;switch(n.op){case"add":case"replace":r.set(e,n.value);break;case"remove":r.delete(e)}},o.prototype.applySnapshot=function(t,e){ot(this,e);var n=t.storedValue,r={};n.keys().forEach(function(t){r[t]=!1}),Object.keys(e).forEach(function(t){n.set(t,e[t]),r[t]=!0}),Object.keys(r).forEach(function(t){!1===r[t]&&n.delete(t)})},o.prototype.getChildType=function(t){return this.subType},o.prototype.isValidSnapshot=function(t,e){var n=this;return y(t)?it(Object.keys(t).map(function(r){return n.subType.validate(t[r],et(e,r,n.subType))})):rt(e,t)},o.prototype.getDefaultSnapshot=function(){return{}},o.prototype.removeChild=function(t,e){t.storedValue.delete(e)},r([e.action],o.prototype,"applySnapshot",null),o}(Ot),Nt=function(t){function i(n,r){var i=t.call(this,n)||this;return i.shouldAttachNode=!0,i.flags=wt.Array,i.createNewInstance=function(){var t=e.observable.shallowArray();return P(t,"toString",ut),t},i.finalizeNewInstance=function(t,n){var r=t.storedValue;e.extras.getAdministration(r).dehancer=t.unbox,e.intercept(r,function(t){return i.willChange(t)}),t.applySnapshot(n),e.observe(r,i.didChange)},i.subType=r,i}return n(i,t),i.prototype.describe=function(){return this.subType.describe()+"[]"},i.prototype.instantiate=function(t,e,n,r){return X(this,t,e,n,r,this.createNewInstance,this.finalizeNewInstance)},i.prototype.getChildren=function(t){return t.storedValue.peek()},i.prototype.getChildNode=function(t,e){var n=parseInt(e,10);return n<t.storedValue.length?t.storedValue[n]:u("Not a child: "+e)},i.prototype.willChange=function(t){var e=G(t.object);e.assertWritable();var n=e.getChildren();switch(t.type){case"update":if(t.newValue===t.object[t.index])return null;t.newValue=pt(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=pt(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},i.prototype.getValue=function(t){return t.storedValue},i.prototype.getSnapshot=function(t){return t.getChildren().map(function(t){return t.snapshot})},i.prototype.didChange=function(t){var e=G(t.object);switch(t.type){case"update":return void e.emitPatch({op:"replace",path:""+t.index,value:e.getChildNode(""+t.index).snapshot},e);case"splice":for(n=t.index+t.removedCount-1;n>=t.index;n--)e.emitPatch({op:"remove",path:""+n},e);for(var n=0;n<t.addedCount;n++)e.emitPatch({op:"add",path:""+(t.index+n),value:e.getChildNode(""+(t.index+n)).snapshot},e);return}},i.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)}},i.prototype.applySnapshot=function(t,e){ot(this,e),t.storedValue.replace(e)},i.prototype.getChildType=function(t){return this.subType},i.prototype.isValidSnapshot=function(t,e){var n=this;return l(t)?it(t.map(function(t,r){return n.subType.validate(t,et(e,""+r,n.subType))})):rt(e,t)},i.prototype.getDefaultSnapshot=function(){return[]},i.prototype.removeChild=function(t,e){t.storedValue.splice(parseInt(e,10),1)},r([e.action],i.prototype,"applySnapshot",null),i}(Ot),zt=function(t){function e(e,n,r,i){void 0===i&&(i=p);var o=t.call(this,e)||this;return o.flags=n,o.checker=r,o.initializer=i,o}return n(e,t),e.prototype.describe=function(){return this.name},e.prototype.instantiate=function(t,e,n,r){return X(this,t,e,n,r,this.initializer)},e.prototype.isValidSnapshot=function(t,e){return b(t)&&this.checker(t)?nt():rt(e,t)},e}(xt),Dt=new zt("string",wt.String,function(t){return"string"==typeof t}),It=new zt("number",wt.Number,function(t){return"number"==typeof t}),Et=new zt("boolean",wt.Boolean,function(t){return"boolean"==typeof t}),Rt=new zt("Date",wt.Date,function(t){return"number"==typeof t||t instanceof Date},function(t){return t instanceof Date?t:new Date(t)});Rt.getSnapshot=function(t){return t.storedValue.getTime()};var kt=function(t){function e(e){var n=t.call(this,"identifier("+e.name+")")||this;return n.identifierType=e,n.flags=wt.Identifier,n}return n(e,t),e.prototype.instantiate=function(t,e,n,r){return t&&q(t.storedValue)?(t.identifierAttribute&&u("Cannot define property '"+e+"' as object identifier, property '"+t.identifierAttribute+"' is already defined as identifier property"),t.identifierAttribute=e,X(this,t,e,n,r)):u("Identifier types can only be instantiated as direct child of a model type")},e.prototype.reconcile=function(t,e){return t.storedValue!==e?u("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):rt(e,t,"References should be a primitive value")},e}(xt),Ft=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|wt.Optional},enumerable:!0,configurable:!0}),e.prototype.describe=function(){return this.type.describe()+"?"},e.prototype.instantiate=function(t,e,n,r){if(void 0===r){var i=this.getDefaultValue(),o=q(i)?G(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&&ot(this,t),t},e.prototype.isValidSnapshot=function(t,e){return void 0===t?nt():this.type.validate(t,e)},e}(xt),Lt=function(){function t(t){this.name=t}return t.prototype.initializePrototype=function(t){},t.prototype.initialize=function(t,e){},t.prototype.willChange=function(t){return null},t.prototype.didChange=function(t){},t.prototype.serialize=function(t,e){},t.prototype.deserialize=function(t,e){},t}(),Mt=function(t){function r(e,n,r){var i=t.call(this,e)||this;return i.getter=n,i.setter=r,i}return n(r,t),r.prototype.initializePrototype=function(t){Object.defineProperty(t,this.name,e.computed(t,this.name,{get:this.getter,set:this.setter,configurable:!0,enumerable:!1}))},r.prototype.validate=function(t,e){return this.name in t?rt(et(e,this.name),t[this.name],"Computed properties should not be provided in the snapshot"):nt()},r}(Lt),Ht=function(t){function e(e){var n=t.call(this,""+e)||this;return n.flags=wt.Literal,n.value=e,n}return n(e,t),e.prototype.instantiate=function(t,e,n,r){return X(this,t,e,n,r)},e.prototype.describe=function(){return JSON.stringify(this.value)},e.prototype.isValidSnapshot=function(t,e){return b(t)&&t===this.value?nt():rt(e,t)},e}(xt),Ut=ht(void 0),$t=function(t){function r(e,n){var r=t.call(this,e)||this;return r.type=n,r}return n(r,t),r.prototype.initializePrototype=function(t){e.observable.ref(t,this.name,{value:Ut.instantiate(null,"",null,void 0)})},r.prototype.initialize=function(t,n){var r=G(t);t[this.name]=this.type.instantiate(r,this.name,r._environment,n[this.name]),e.extras.interceptReads(t,this.name,r.unbox)},r.prototype.getValueNode=function(t){var e=t.$mobx.values[this.name].value;return e||u("Node not available for property "+this.name)},r.prototype.willChange=function(t){var e=G(t.object);return ot(this.type,t.newValue),t.newValue=this.type.reconcile(e.getChildNode(t.name),t.newValue),t},r.prototype.didChange=function(t){var e=G(t.object);e.emitPatch({op:"replace",path:i(this.name),value:this.getValueNode(t.object).snapshot},e)},r.prototype.serialize=function(t,n){e.extras.getAtom(t,this.name).reportObserved(),n[this.name]=this.getValueNode(t).snapshot},r.prototype.deserialize=function(t,e){t[this.name]=e[this.name]},r.prototype.validate=function(t,e){return this.type.validate(t[this.name],et(e,this.name,this.type))},r}(Lt),Jt=function(t){function e(e,n){var r=t.call(this,e)||this;return r.invokeAction=O(e,n),r}return n(e,t),e.prototype.initialize=function(t){P(t,this.name,this.invokeAction.bind(t))},e.prototype.validate=function(t,e){return this.name in t?rt(et(e,this.name),t[this.name],"Action properties should not be provided in the snapshot"):nt()},e}(Lt),Wt=function(t){function e(e,n){var r=t.call(this,e)||this;return r.invokeView=ft(e,n),r}return n(e,t),e.prototype.initialize=function(t){P(t,this.name,this.invokeView.bind(t))},e.prototype.validate=function(t,e){return this.name in t?rt(et(e,this.name),t[this.name],"View properties should not be provided in the snapshot"):nt()},e}(Lt),Bt=function(t){function r(e,n){var r=t.call(this,e)||this;return r.initialValue=n,null!==n&&"object"==typeof n?u("Trying to declare property "+e+" with a non-primitive value. Please provide an initializer function to avoid accidental sharing of local state, like `"+e+": () => initialValue`"):r}return n(r,t),r.prototype.initialize=function(t,n){var r="function"==typeof this.initialValue?this.initialValue.call(t,t):this.initialValue;e.extendObservable(t,(i={},i[this.name]=r,i));var i},r.prototype.willChange=function(t){return t},r.prototype.validate=function(t,e){return this.name in t?rt(et(e,this.name),t[this.name],"volatile state should not be provided in the snapshot"):nt()},r}(Lt),Yt=["preProcessSnapshot","afterCreate","afterAttach","postProcessSnapshot","beforeDetach","beforeDestroy"],qt=function(t){function i(n,r,i,o){var a=t.call(this,n)||this;return a.shouldAttachNode=!0,a.flags=wt.Object,a.props={},a.createNewInstance=function(){var t=new a.modelConstructor;return e.extendShallowObservable(t,{}),t},a.finalizeNewInstance=function(t,n){var r=t.storedValue;a.forAllProps(function(t){return t.initialize(r,n)}),e.intercept(r,function(t){return a.willChange(t)}),e.observe(r,a.didChange)},a.didChange=function(t){a.props[t.name].didChange(t)},Object.freeze(r),Object.freeze(o),a.properties=r,a.state=i,a.actions=o,/^\w[\w\d_]*$/.test(n)||u("Typename should be a valid identifier: "+n),a.modelConstructor=new Function("return function "+n+" (){}")(),a.modelConstructor.prototype.toString=dt,a.parseModelProps(),a.forAllProps(function(t){return t.initializePrototype(a.modelConstructor.prototype)}),a}return n(i,t),i.prototype.instantiate=function(t,e,n,r){return X(this,t,e,n,this.preProcessSnapshot(r),this.createNewInstance,this.finalizeNewInstance)},i.prototype.willChange=function(t){return G(t.object).assertWritable(),this.props[t.name].willChange(t)},i.prototype.parseModelProps=function(){var t=this,e=t.properties,n=t.state,r=t.actions;for(var i in e)if(V(e,i)){-1!==Yt.indexOf(i)&&console.warn("Hook '"+i+"' was defined as property. Hooks should be defined as part of the actions");var o=Object.getOwnPropertyDescriptor(e,i);if("get"in o){this.props[i]=new Mt(i,o.get,o.set);continue}if(null===(s=o.value))u("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(b(s)){var a=ct(s);this.props[i]=new $t(i,lt(a,s))}else D(s)?this.props[i]=new $t(i,s):"function"==typeof s?this.props[i]=new Wt(i,s):u("object"==typeof s?"In property '"+i+"': base model's should not contain complex values: '"+s+"'":"Unexpected value for property '"+i+"'")}for(var i in n)if(V(n,i)){-1!==Yt.indexOf(i)&&console.warn("Hook '"+i+"' was defined as local state. Hooks should be defined as part of the actions");s=n[i];i in this.properties&&u("Property '"+i+"' was also defined as local state. Local state fields and properties should not collide"),this.props[i]=new Bt(i,s)}for(var i in r)if(V(r,i)){var s=r[i];i in this.properties&&u("Property '"+i+"' was also defined as action. Actions and properties should not collide"),i in this.state&&u("Property '"+i+"' was also defined as local state. Actions and state should not collide"),"function"==typeof s?this.props[i]=new Jt(i,s):u("Unexpected value for action '"+i+"'. Expected function, got "+typeof s)}},i.prototype.getChildren=function(t){var e=[];return this.forAllProps(function(n){n instanceof $t&&e.push(n.getValueNode(t.storedValue))}),e},i.prototype.getChildNode=function(t,e){return this.props[e]instanceof $t?this.props[e].getValueNode(t.storedValue):u("Not a value property: "+e)},i.prototype.getValue=function(t){return t.storedValue},i.prototype.getSnapshot=function(t){var e={};return this.forAllProps(function(n){return n.serialize(t.storedValue,e)}),this.postProcessSnapshot(e)},i.prototype.applyPatchLocally=function(t,e,n){"replace"!==n.op&&"add"!==n.op&&u("object does not support operation "+n.op),t.storedValue[e]=n.value},i.prototype.applySnapshot=function(t,e){var n=this.preProcessSnapshot(e);ot(this,n);for(var r in this.props)this.props[r].deserialize(t.storedValue,n)},i.prototype.preProcessSnapshot=function(t){return"function"==typeof this.actions.preProcessSnapshot?this.actions.preProcessSnapshot.call(null,t):t},i.prototype.postProcessSnapshot=function(t){return"function"==typeof this.actions.postProcessSnapshot?this.actions.postProcessSnapshot.call(null,t):t},i.prototype.getChildType=function(t){return this.props[t].type},i.prototype.isValidSnapshot=function(t,e){var n=this,r=this.preProcessSnapshot(t);return y(r)?it(Object.keys(this.props).map(function(t){return n.props[t].validate(r,e)})):rt(e,r)},i.prototype.forAllProps=function(t){var e=this;Object.keys(this.props).forEach(function(n){return t(e.props[n])})},i.prototype.describe=function(){var t=this;return"{ "+Object.keys(this.props).map(function(e){var n=t.props[e];return n instanceof $t?e+": "+n.type.describe():""}).filter(Boolean).join("; ")+" }"},i.prototype.getDefaultSnapshot=function(){return{}},i.prototype.removeChild=function(t,e){t.storedValue[e]=null},r([e.action],i.prototype,"applySnapshot",null),i}(Ot),Gt=function(){return function(t,e){if(this.mode=t,this.value=e,"object"===t){if(!q(e))return u("Can only store references to tree nodes, got: '"+e+"'");if(!G(e).identifierAttribute)return u("Can only store references with a defined identifier attribute.")}}}(),Kt=function(t){function e(e){var n=t.call(this,"reference("+e.name+")")||this;return n.targetType=e,n.flags=wt.Reference,n}return n(e,t),e.prototype.describe=function(){return this.name},e.prototype.getValue=function(t){var e=t.storedValue;if("object"===e.mode)return e.value;if(t.isAlive){var n=t.root.identifierCache.resolve(this.targetType,e.value);return n?n.value:u("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 G(e.value).identifier}},e.prototype.instantiate=function(t,e,n,r){var i=q(r);return X(this,t,e,n,new Gt(i?"object":"identifier",r))},e.prototype.reconcile=function(t,e){var n=q(e)?"object":"identifier";if(R(t.type)){var r=t.storedValue;if(n===r.mode&&r.value===e)return t}var i=this.instantiate(t.parent,t.subpath,t._environment,e);return t.die(),i},e.prototype.isAssignableFrom=function(t){return this.targetType.isAssignableFrom(t)},e.prototype.isValidSnapshot=function(t,e){return"string"==typeof t||"number"==typeof t?nt():rt(e,t,"Value '"+Z(t)+"' is not a valid reference. Expected a string or number.")},e}(xt),Qt=function(t){function e(e,n,r){var i=t.call(this,e)||this;return i.dispatcher=null,i.dispatcher=r,i.types=n,i}return n(e,t),Object.defineProperty(e.prototype,"flags",{get:function(){var t=wt.Union;return this.types.forEach(function(e){t|=e.flags}),t},enumerable:!0,configurable:!0}),e.prototype.isAssignableFrom=function(t){return this.types.some(function(e){return e.isAssignableFrom(t)})},e.prototype.describe=function(){return"("+this.types.map(function(t){return t.describe()}).join(" | ")+")"},e.prototype.instantiate=function(t,e,n,r){return this.determineType(r).instantiate(t,e,n,r)},e.prototype.reconcile=function(t,e){return this.determineType(e).reconcile(t,e)},e.prototype.determineType=function(t){if(null!==this.dispatcher)return this.dispatcher(t);var e=this.types.filter(function(e){return e.is(t)});return e.length>1?u("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?rt(e,t,"Multiple types are applicable and no dispatch method is defined for the union"):r.length<1?rt(e,t,"No type is applicable and no dispatch method is defined for the union").concat(it(n)):nt()},e}(xt),Xt=new(function(t){function e(){var e=t.call(this,"frozen")||this;return e.flags=wt.Frozen,e}return n(e,t),e.prototype.describe=function(){return"<any immutable value>"},e.prototype.instantiate=function(t,e,n,r){return X(this,t,e,n,m(r))},e.prototype.isValidSnapshot=function(t,e){return w(t)?nt():rt(e,t)},e}(xt)),Zt=lt(ht(null),null),te=function(t){function e(e,n,r){var i=t.call(this,e)||this;return i.type=n,i.predicate=r,i}return n(e,t),Object.defineProperty(e.prototype,"flags",{get:function(){return this.type.flags|wt.Refinement},enumerable:!0,configurable:!0}),e.prototype.describe=function(){return this.name},e.prototype.instantiate=function(t,e,n,r){return this.type.instantiate(t,e,n,r)},e.prototype.isAssignableFrom=function(t){return this.type.isAssignableFrom(t)},e.prototype.isValidSnapshot=function(t,e){if(this.type.is(t)){var n=q(t)?G(t).snapshot:t;if(this.predicate(n))return nt()}return rt(e,t)},e}(xt),ee=function(t){function e(e,n){var r=t.call(this,e)||this;return r._subType=null,"function"==typeof n&&0===n.length||u("Invalid late type, expected a function with zero arguments that returns a type, got: "+n),r.definition=n,r}return n(e,t),Object.defineProperty(e.prototype,"flags",{get:function(){return this.subType.flags|wt.Late},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"subType",{get:function(){return null===this._subType&&(this._subType=this.definition()),this._subType},enumerable:!0,configurable:!0}),e.prototype.instantiate=function(t,e,n,r){return this.subType.instantiate(t,e,n,r)},e.prototype.reconcile=function(t,e){return this.subType.reconcile(t,e)},e.prototype.describe=function(){return this.subType.name},e.prototype.isValidSnapshot=function(t,e){return this.subType.validate(t,e)},e.prototype.isAssignableFrom=function(t){return this.subType.isAssignableFrom(t)},e}(xt),ne={model:yt,compose:vt,reference:function(t){return 2===arguments.length&&"string"==typeof arguments[1]&&u("References with base path are no longer supported. Please remove the base path."),new Kt(t)},union:bt,optional:lt,literal:ht,maybe:function(t){return t===Xt&&u("Unable to declare `types.maybe(types.frozen)`. Frozen already accepts `null`. Consider using `types.optional(types.frozen, null)` instead."),bt(Zt,t)},refinement:function(t,e,n){return new te(t,e,n)},string:Dt,boolean:Et,number:It,Date:Rt,map:function(t){return new _t("map<string, "+t.name+">",t)},array:function(t){return new Nt(t.name+"[]",t)},frozen:Xt,identifier:function(t){return void 0===t&&(t=Dt),new kt(t)},late:function(t,e){var n="string"==typeof t?t:"late("+t.toString()+")";return new ee(n,"string"==typeof t?e:t)}};t.types=ne,t.escapeJsonPath=i,t.unescapeJsonPath=o,t.onAction=z,t.isStateTreeNode=q,t.asReduxStore=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];q(t)||u("Expected model object");var r={getState:function(){return J(t)},dispatch:function(e){mt(e,i.slice(),function(e){return N(t,gt(e))})},subscribe:function(e){return M(t,e)}},i=e.map(function(t){return t(r)});return r},t.connectReduxDevtools=function(t,e){var n=t.connectViaExtension(),r=!1;n.subscribe(function(n){var i=t.extractState(n);i&&(r=!0,$(e,i),r=!1)}),z(e,function(t){if(!r){var i={};i.type=t.name,t.args&&t.args.forEach(function(t,e){return i[e]=t}),n.send(i,J(e))}})},t.getType=k,t.getChildType=function(t,e){return G(t).getChildType(e)},t.addMiddleware=F,t.onPatch=L,t.onSnapshot=M,t.applyPatch=H,t.recordPatches=function(t){var e={patches:[],stop:function(){return n()},replay:function(t){H(t,e.patches)}},n=L(t,function(t){e.patches.push(t)});return e},t.applyAction=U,t.recordActions=function(t){var e={actions:[],stop:function(){return n()},replay:function(t){U(t,e.actions)}},n=z(t,e.actions.push.bind(e.actions));return e},t.protect=function(t){var e=G(t);e.isRoot||u("`protect` can only be invoked on root nodes"),e.isProtectionEnabled=!0},t.unprotect=function(t){var e=G(t);e.isRoot||u("`unprotect` can only be invoked on root nodes"),e.isProtectionEnabled=!1},t.isProtected=function(t){return G(t).isProtected},t.applySnapshot=$,t.getSnapshot=J,t.hasParent=function(t,e){void 0===e&&(e=1),e<0&&u("Invalid depth: "+e+", should be >= 1");for(var n=G(t).parent;n;){if(0==--e)return!0;n=n.parent}return!1},t.getParent=function(t,e){void 0===e&&(e=1),e<0&&u("Invalid depth: "+e+", should be >= 1");for(var n=e,r=G(t).parent;r;){if(0==--n)return r.storedValue;r=r.parent}return u("Failed to find the parent of "+G(t)+" at depth "+e)},t.getRoot=function(t){return G(t).root.storedValue},t.getPath=function(t){return G(t).path},t.getPathParts=function(t){return s(G(t).path)},t.isRoot=function(t){return G(t).isRoot},t.resolvePath=W,t.resolveIdentifier=function(t,e,n){D(t)||u("Expected a type as first argument");var r=G(e).root.identifierCache.resolve(t,""+n);return r?r.value:void 0},t.tryResolve=B,t.getRelativePath=function(t,e){return G(t).getRelativePathTo(G(e))},t.clone=function(t,e){void 0===e&&(e=!0);var n=G(t);return n.type.create(n.snapshot,!0===e?n.root._environment:!1===e?void 0:e)},t.detach=function(t){return G(t).detach(),t},t.destroy=function(t){var e=G(t);e.isRoot?e.die():e.parent.removeChild(e.subpath)},t.isAlive=function(t){return G(t).isAlive},t.addDisposer=function(t,e){G(t).addDisposer(e)},t.getEnv=function(t){var e=G(t),n=e.root._environment;return n||u("Node '"+e+"' is not part of state tree that was initialized with an environment. Environment can be passed as second argumentt to .create()"),n},t.walk=Y,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("mobx")):"function"==typeof define&&define.amd?define(["exports","mobx"],e):e(t.mobxStateTree=t.mobxStateTree||{},t.mobx)}(this,function(t,e){"use strict";function n(t,e){function n(){this.constructor=t}At(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}function r(t,e,n,r){var i,o=arguments.length,a=o<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,n,r);else for(var s=t.length-1;s>=0;s--)(i=t[s])&&(a=(o<3?i(a):o>3?i(e,n,a):i(e,n))||a);return o>3&&a&&Object.defineProperty(e,n,a),a}function i(t){throw void 0===t&&(t="Illegal state"),new Error("[mobx-state-tree] "+t)}function o(t){return t}function a(){}function s(t){return!(!Array.isArray(t)&&!e.isObservableArray(t))}function u(t){return t?s(t)?t:[t]:St}function p(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];for(var r=0;r<e.length;r++){var i=e[r];for(var o in i)t[o]=i[o]}return t}function c(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];for(var r=0;r<e.length;r++){var i=e[r];for(var o in i){var a=Object.getOwnPropertyDescriptor(i,o);"get"in a?Object.defineProperty(t,o,Ct({},a,{configurable:!0})):t[o]=i[o]}}return t}function l(t){if(null===t||"object"!=typeof t)return!1;var e=Object.getPrototypeOf(t);return e===Object.prototype||null===e}function h(t){return!(null===t||"object"!=typeof t||t instanceof Date||t instanceof RegExp)}function f(t){return null===t||void 0===t||("string"==typeof t||"number"==typeof t||"boolean"==typeof t||t instanceof Date)}function d(t){return f(t)?t:Object.freeze(t)}function y(t){return d(t),l(t)&&Object.keys(t).forEach(function(e){f(t[e])||Object.isFrozen(t[e])||y(t[e])}),t}function v(t){return"function"!=typeof t}function b(t,e,n){Object.defineProperty(t,e,{enumerable:!1,writable:!1,configurable:!0,value:n})}function g(t,e,n){Object.defineProperty(t,e,{enumerable:!0,writable:!1,configurable:!0,value:n})}function m(t,e){return t.push(e),function(){var n=t.indexOf(e);-1!==n&&t.splice(n,1)}}function w(t,e){return Tt.call(t,e)}function V(t){for(var e=new Array(t.length),n=0;n<t.length;n++)e[n]=t[n];return e}function P(t){switch("oldValue"in t||i("Patches without `oldValue` field cannot be inversed"),t.op){case"add":return{op:"remove",path:t.path,oldValue:t.value};case"remove":return{op:"add",path:t.path,value:t.oldValue};case"replace":return{op:"replace",path:t.path,value:t.oldValue,oldValue:t.value}}}function j(t){var e=Ct({},t);return delete e.oldValue,e}function A(t){return t.replace(/~/g,"~1").replace(/\//g,"~0")}function C(t){return t.replace(/~0/g,"\\").replace(/~1/g,"~")}function S(t){return 0===t.length?"":"/"+t.map(A).join("/")}function T(t){var e=t.split("/").map(C);return""===e[0]?e.slice(1):e}function O(t){for(var e=t.middlewares.slice(),n=t;n.parent;)n=n.parent,e=e.concat(n.middlewares);return e}function x(t,e,n){function r(t){var o=i.shift();return o?o(t,r):n.apply(e.object,e.args)}var i=O(t);return i.length?r(e):n.apply(e.object,e.args)}function _(t,n){var r=e.action(t,n);return function(){var e=X(this);if(e.assertAlive(),e.isRunningAction())return r.apply(this,arguments);var n={name:t,object:e.storedValue,args:V(arguments)},i=e.root;i._isRunningAction=!0;try{return x(e,n,r)}finally{i._isRunningAction=!1}}}function N(t,n,r,i){if(f(i))return i;if(Q(i)){var o=X(i);if(t.root!==o.root)throw new Error("Argument "+r+" that was passed to action '"+n+"' is a model that is not part of the same state tree. Consider passing a snapshot or some representative ID instead");return{$ref:t.getRelativePathTo(X(i))}}if("function"==typeof i)throw new Error("Argument "+r+" that was passed to action '"+n+"' should be a primitive, model object or plain object, received a function");if("object"==typeof i&&!l(i)&&!s(i))throw new Error("Argument "+r+" that was passed to action '"+n+"' should be a primitive, model object or plain object, received a "+(i&&i.constructor?i.constructor.name:"Complex Object"));if(e.isObservable(i))throw new Error("Argument "+r+" that was passed to action '"+n+"' should be a primitive, model object or plain object, received an mobx observable.");try{return JSON.stringify(i),i}catch(t){throw new Error("Argument "+r+" that was passed to action '"+n+"' is not serializable.")}}function z(t,e){if("object"==typeof e){var n=Object.keys(e);if(1===n.length&&"$ref"===n[0])return q(t.storedValue,e.$ref)}return e}function D(t,e){var n=G(t,e.path||"");if(!n)return i("Invalid action path: "+(e.path||""));var r=X(n);return"@APPLY_PATCHES"===e.name?$.call(null,n,e.args[0]):"@APPLY_SNAPSHOT"===e.name?B.call(null,n,e.args[0]):("function"!=typeof n[e.name]&&i("Action '"+e.name+"' does not exist in '"+r.path+"'"),n[e.name].apply(n,e.args?e.args.map(function(t){return z(r,t)}):[]))}function I(t,e){return M(t,function(n,r){var i=X(n.object);return e({name:n.name,path:X(t).getRelativePathTo(i),args:n.args.map(function(t,e){return N(i,n.name,e,t)})}),r(n)})}function E(t){return"object"==typeof t&&t&&!0===t.isType}function R(t){return E(t)&&(t.flags&(jt.String|jt.Number|jt.Boolean|jt.Date))>0}function k(t){return E(t)&&(t.flags&jt.Object)>0}function F(t){return(t.flags&jt.Reference)>0}function L(t){return X(t).type}function M(t,e){var n=X(t);return n.isProtectionEnabled||console.warn("It is recommended to protect the state tree before attaching action middleware, as otherwise it cannot be guaranteed that all changes are passed through middleware. See `protect`"),n.addMiddleWare(e)}function H(t,e,n){return void 0===n&&(n=!1),X(t).onPatch(e,n)}function U(t,e){return X(t).onSnapshot(e)}function $(t,e){X(t).applyPatches(u(e))}function J(t,e){var n=u(e).map(P);n.reverse(),X(t).applyPatches(n)}function W(t,n){e.runInAction(function(){u(n).forEach(function(e){return D(t,e)})})}function B(t,e){return X(t).applySnapshot(e)}function Y(t){return X(t).snapshot}function q(t,e){var n=X(t).resolve(e);return n?n.value:void 0}function G(t,e){var n=X(t).resolve(e,!1);if(void 0!==n)return n?n.value:void 0}function K(t,e){var n=X(t);n.getChildren().forEach(function(t){Q(t.storedValue)&&K(t.storedValue,e)}),e(n.storedValue)}function Q(t){return!(!t||!t.$treenode)}function X(t){return Q(t)?t.$treenode:i("Value "+t+" is no MST Node")}function Z(t){return t&&"object"==typeof t&&!(t instanceof Date)&&!Q(t)&&!Object.isFrozen(t)}function tt(){return X(this).snapshot}function et(t,e,n,r,s,u,p){if(void 0===u&&(u=o),void 0===p&&(p=a),Q(s)){var c=X(s);return c.isRoot||i("Cannot add an object to a state tree if it is already part of the same or another state tree. Tried to assign an object to '"+(e?e.path:"")+"/"+n+"', but it lives already at '"+c.path+"'"),c.setParent(e,n),c}var l=u(s),h=Z(l),f=new _t(t,e,n,r,l);e||(f.identifierCache=new Ot),h&&b(l,"$treenode",f);var d=!0;try{return h&&g(l,"toJSON",tt),f._isRunningAction=!0,p(f,s),f._isRunningAction=!1,e?e.root.identifierCache.addNodeToCache(f):f.identifierCache.addNodeToCache(f),f.fireHook("afterCreate"),e&&f.fireHook("afterAttach"),d=!1,f}finally{d&&(f._isAlive=!1)}}function nt(t){return"function"==typeof t?"<function"+(t.name?" "+t.name:"")+">":Q(t)?"<"+t+">":"`"+JSON.stringify(t)+"`"}function rt(t){var e=t.value,n=t.context[t.context.length-1].type,r=t.context.map(function(t){return t.path}).filter(function(t){return t.length>0}).join("/"),i=r.length>0?'at path "/'+r+'" ':"",o=Q(e)?"value of type "+X(e).type.name+":":f(e)?"value":"snapshot",a=n&&Q(e)&&n.is(X(e).snapshot);return""+i+o+" "+nt(e)+" is not assignable "+(n?"to type: `"+n.name+"`":"")+(t.message?" ("+t.message+")":"")+(n?R(n)?".":", expected an instance of `"+n.name+"` or a snapshot like `"+n.describe()+"` instead."+(a?" (Note that a snapshot of the provided value is compatible with the targeted type)":""):".")}function it(t,e,n){return t.concat([{path:e,type:n}])}function ot(){return St}function at(t,e,n){return[{context:t,value:e,message:n}]}function st(t){return t.reduce(function(t,e){return t.concat(e)},[])}function ut(t,e){var n=t.validate(e,[{path:"",type:t}]);n.length>0&&i("Error while converting "+nt(e)+" to `"+t.name+"`:\n"+n.map(rt).join("\n"))}function pt(){return X(this)+"("+this.size+" items)"}function ct(t){t||i("Map.put cannot be used to set empty values");var e;if(Q(t))e=X(t);else{if(!h(t))return i("Map.put can only be used to store complex values");e=X(X(this).type.subType.create(t))}return e.identifierAttribute||i("Map.put can only be used to store complex values that have an identifier type attribute"),this.set(e.identifier,e.value),this}function lt(){return X(this)+"("+this.length+" items)"}function ht(t,e,n,r,o){function a(t){for(var e in p){var n=t[e];if(("string"==typeof n||"number"==typeof n)&&p[e][n])return p[e][n]}return null}var s=new Array(r.length),u={},p={};n.forEach(function(t){t.identifierAttribute&&((p[t.identifierAttribute]||(p[t.identifierAttribute]={}))[t.identifier]=t),u[t.nodeId]=t}),r.forEach(function(n,r){var p=""+o[r];if(Q(n))(l=X(n)).assertAlive(),l.parent===t?(u[l.nodeId]||i("Cannot add an object to a state tree if it is already part of the same or another state tree. Tried to assign an object to '"+t.path+"/"+p+"', but it lives already at '"+l.path+"'"),u[l.nodeId]=void 0,l.setParent(t,p),s[r]=l):s[r]=e.instantiate(t,p,void 0,n);else if(h(n)){var c=a(n);if(c){var l=e.reconcile(c,n);u[c.nodeId]=void 0,l.setParent(t,p),s[r]=l}else s[r]=e.instantiate(t,p,void 0,n)}else s[r]=e.instantiate(t,p,void 0,n)});for(var c in u)void 0!==u[c]&&u[c].die();return s}function ft(t){switch(typeof t){case"string":return Rt;case"number":return kt;case"boolean":return Ft;case"object":if(t instanceof Date)return Lt}return i("Cannot determine primtive type from value "+t)}function dt(t,e){var n="function"==typeof e?e():e;return ut(t,Q(n)?X(n).snapshot:n),new Ht(t,e)}function yt(t){return f(t)||i("Literal types can be built only on top of primitives"),new Jt(t)}function vt(t,n){return function(){var t=this,r=arguments;return X(this).assertAlive(),e.extras.allowStateChanges(!1,function(){return n.apply(t,r)})}}function bt(){return X(this).toString()}function gt(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n="string"==typeof t[0]?t.shift():"AnonymousModel",r=t.shift()||i("types.model must specify properties"),o=t.length>1&&t.shift()||{},a=t.shift()||{};return new Qt(n,r,o,a)}function mt(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n="string"==typeof t[0]?t.shift():"AnonymousModel";if(t.every(function(t){return E(t)}))return t.reduce(function(t,e){return mt(n,t,e.properties,e.state,e.actions)});var r=t.shift(),o=t.shift()||i("types.compose must specify properties or `{}`"),a=t.length>1&&t.shift()||{},s=t.shift()||{};return k(r)?gt(n,c({},r.properties,o),c({},r.state,a),c({},r.actions,s)):i("Only model types can be composed")}function wt(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var r=E(t)?null:t,i=E(t)?e.concat(t):e,o=i.map(function(t){return t.name}).join(" | ");return new te(o,i,r)}function Vt(t){var e=p({},t);return delete e.type,{name:t.type,args:[e]}}function Pt(t,e,n){function r(t){var i=e.shift();i?i(r)(t):n(t)}r(t)}var jt,At=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])},Ct=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++){e=arguments[n];for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])}return t},St=Object.freeze([]),Tt=Object.prototype.hasOwnProperty;!function(t){t[t.String=1]="String",t[t.Number=2]="Number",t[t.Boolean=4]="Boolean",t[t.Date=8]="Date",t[t.Literal=16]="Literal",t[t.Array=32]="Array",t[t.Map=64]="Map",t[t.Object=128]="Object",t[t.Frozen=256]="Frozen",t[t.Optional=512]="Optional",t[t.Reference=1024]="Reference",t[t.Identifier=2048]="Identifier",t[t.Late=4096]="Late",t[t.Refinement=8192]="Refinement",t[t.Union=16384]="Union"}(jt||(jt={}));var Ot=function(){function t(){this.cache=e.observable.map()}return t.prototype.addNodeToCache=function(t){if(t.identifierAttribute){var n=t.identifier;this.cache.has(n)||this.cache.set(n,e.observable.shallowArray());var r=this.cache.get(n);-1!==r.indexOf(t)&&i("Already registered"),r.push(t)}return this},t.prototype.mergeCache=function(t){var e=this;t.identifierCache.cache.values().forEach(function(t){return t.forEach(function(t){e.addNodeToCache(t)})})},t.prototype.notifyDied=function(t){if(t.identifierAttribute){var e=this.cache.get(t.identifier);e&&e.remove(t)}},t.prototype.splitCache=function(e){var n=new t,r=e.path;return this.cache.values().forEach(function(t){for(var e=t.length-1;e>=0;e--)0===t[e].path.indexOf(r)&&(n.addNodeToCache(t[e]),t.splice(e,1))}),n},t.prototype.resolve=function(t,e){var n=this.cache.get(e);if(!n)return null;var r=n.filter(function(e){return t.isAssignableFrom(e.type)});switch(r.length){case 0:return null;case 1:return r[0];default:return i("Cannot resolve a reference to type '"+t.name+"' with id: '"+e+"' unambigously, there are multiple candidates: "+r.map(function(t){return t.path}).join(", "))}},t}(),xt=1,_t=function(){function t(t,n,r,i,o){var a=this;this.nodeId=++xt,this._parent=null,this.subpath="",this.isProtectionEnabled=!0,this.identifierAttribute=void 0,this._environment=void 0,this._isRunningAction=!1,this._autoUnbox=!0,this._isAlive=!0,this._isDetaching=!1,this.middlewares=[],this.snapshotSubscribers=[],this.patchSubscribers=[],this.disposers=[],this.type=t,this._parent=n,this.subpath=r,this.storedValue=o,this._environment=i,this.unbox=this.unbox.bind(this),this.applyPatches=_("@APPLY_PATCHES",function(t){t.forEach(function(t){var e=T(t.path);a.resolvePath(e.slice(0,-1)).applyPatchLocally(e[e.length-1],t)})}).bind(this.storedValue),this.applySnapshot=_("@APPLY_SNAPSHOT",function(t){return a.type.applySnapshot(a,t)}).bind(this.storedValue);var s=e.reaction(function(){return a.snapshot},function(t){a.emitSnapshot(t)});s.onError(function(t){throw t}),this.addDisposer(s)}return Object.defineProperty(t.prototype,"identifier",{get:function(){return this.identifierAttribute?this.storedValue[this.identifierAttribute]:null},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"path",{get:function(){return this.parent?this.parent.path+"/"+A(this.subpath):""},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isRoot",{get:function(){return null===this.parent},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"parent",{get:function(){return this._parent},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"root",{get:function(){for(var t,e=this;t=e.parent;)e=t;return e},enumerable:!0,configurable:!0}),t.prototype.getRelativePathTo=function(t){this.root!==t.root&&i("Cannot calculate relative path: objects '"+this+"' and '"+t+"' are not part of the same object tree");for(var e=T(this.path),n=T(t.path),r=0;r<e.length&&e[r]===n[r];r++);return e.slice(r).map(function(t){return".."}).join("/")+S(n.slice(r))},t.prototype.resolve=function(t,e){return void 0===e&&(e=!0),this.resolvePath(T(t),e)},t.prototype.resolvePath=function(t,e){void 0===e&&(e=!0);for(var n=this,r=0;r<t.length;r++){if(""===t[r])n=n.root;else if(".."===t[r])n=n.parent;else{if("."===t[r]||""===t[r])continue;if(n){n=n.getChildNode(t[r]);continue}}if(!n)return e?i("Could not resolve '"+t[r]+"' in '"+S(t.slice(0,r-1))+"', path of the patch does not resolve"):void 0}return n},Object.defineProperty(t.prototype,"value",{get:function(){if(this._isAlive)return this.type.getValue(this)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isAlive",{get:function(){return this._isAlive},enumerable:!0,configurable:!0}),t.prototype.die=function(){this._isDetaching||Q(this.storedValue)&&(K(this.storedValue,function(t){return X(t).aboutToDie()}),K(this.storedValue,function(t){return X(t).finalizeDeath()}))},t.prototype.aboutToDie=function(){this.disposers.splice(0).forEach(function(t){return t()}),this.fireHook("beforeDestroy")},t.prototype.finalizeDeath=function(){this.root.identifierCache.notifyDied(this);var t=this,e=this.path;g(this,"snapshot",this.snapshot),this.patchSubscribers.splice(0),this.snapshotSubscribers.splice(0),this.patchSubscribers.splice(0),this._isAlive=!1,this._parent=null,this.subpath="",Object.defineProperty(this.storedValue,"$mobx",{get:function(){i("This object has died and is no longer part of a state tree. It cannot be used anymore. The object (of type '"+t.type.name+"') used to live at '"+e+"'. It is possible to access the last snapshot of this object using 'getSnapshot', or to create a fresh copy using 'clone'. If you want to remove an object from the tree without killing it, use 'detach' instead.")}})},t.prototype.assertAlive=function(){this._isAlive||i(this+" cannot be used anymore as it has died; it has been removed from a state tree. If you want to remove an element from a tree and let it live on, use 'detach' or 'clone' the value")},Object.defineProperty(t.prototype,"snapshot",{get:function(){if(this._isAlive)return d(this.type.getSnapshot(this))},enumerable:!0,configurable:!0}),t.prototype.onSnapshot=function(t){return m(this.snapshotSubscribers,t)},t.prototype.emitSnapshot=function(t){this.snapshotSubscribers.forEach(function(e){return e(t)})},t.prototype.applyPatchLocally=function(t,e){this.assertWritable(),this.type.applyPatchLocally(this,t,e)},t.prototype.onPatch=function(t,e){return m(this.patchSubscribers,e?t:function(e){return t(j(e))})},t.prototype.emitPatch=function(t,e){if(this.patchSubscribers.length){var n=p({},t,{path:e.path.substr(this.path.length)+"/"+t.path});this.patchSubscribers.forEach(function(t){return t(n)})}this.parent&&this.parent.emitPatch(t,e)},t.prototype.setParent=function(t,e){void 0===e&&(e=null),this.parent===t&&this.subpath===e||(this._parent&&t&&t!==this._parent&&i("A node cannot exists twice in the state tree. Failed to add "+this+" to path '"+t.path+"/"+e+"'."),!this._parent&&t&&t.root===this&&i("A state tree is not allowed to contain itself. Cannot assign "+this+" to path '"+t.path+"/"+e+"'"),!this._parent&&this._environment&&i("A state tree that has been initialized with an environment cannot be made part of another state tree."),this.parent&&!t?this.die():(this.subpath=e||"",t&&t!==this._parent&&(t.root.identifierCache.mergeCache(this),this._parent=t,this.fireHook("afterAttach"))))},t.prototype.addDisposer=function(t){this.disposers.unshift(t)},t.prototype.isRunningAction=function(){return!!this._isRunningAction||!this.isRoot&&this.parent.isRunningAction()},t.prototype.addMiddleWare=function(t){return m(this.middlewares,t)},t.prototype.getChildNode=function(t){this.assertAlive(),this._autoUnbox=!1;var e=this.type.getChildNode(this,t);return this._autoUnbox=!0,e},t.prototype.getChildren=function(){this.assertAlive(),this._autoUnbox=!1;var t=this.type.getChildren(this);return this._autoUnbox=!0,t},t.prototype.getChildType=function(t){return this.type.getChildType(t)},Object.defineProperty(t.prototype,"isProtected",{get:function(){return this.root.isProtectionEnabled},enumerable:!0,configurable:!0}),t.prototype.assertWritable=function(){this.assertAlive(),!this.isRunningAction()&&this.isProtected&&i("Cannot modify '"+this+"', the object is protected and can only be modified by using an action.")},t.prototype.removeChild=function(t){this.type.removeChild(this,t)},t.prototype.detach=function(){this._isAlive||i("Error while detaching, node is not alive."),this.isRoot||(this.fireHook("beforeDetach"),this._environment=this.root._environment,this._isDetaching=!0,this.identifierCache=this.root.identifierCache.splitCache(this),this.parent.removeChild(this.subpath),this._parent=null,this.subpath="",this._isDetaching=!1)},t.prototype.unbox=function(t){return t&&!0===this._autoUnbox?t.value:t},t.prototype.fireHook=function(t){var e=this.storedValue&&"object"==typeof this.storedValue&&this.storedValue[t];"function"==typeof e&&e.apply(this.storedValue)},t.prototype.toString=function(){var t=this.identifier?"(id: "+this.identifier+")":"";return this.type.name+"@"+(this.path||"<root>")+t+(this.isAlive?"":"[dead]")},r([e.observable],t.prototype,"_parent",void 0),r([e.observable],t.prototype,"subpath",void 0),r([e.computed],t.prototype,"path",null),r([e.computed],t.prototype,"value",null),r([e.computed],t.prototype,"snapshot",null),t}(),Nt=function(){function t(t){this.isType=!0,this.name=t}return t.prototype.create=function(t,e){return void 0===t&&(t=this.getDefaultSnapshot()),ut(this,t),this.instantiate(null,"",e,t).value},t.prototype.isAssignableFrom=function(t){return t===this},t.prototype.validate=function(t,e){return Q(t)?L(t)===this||this.isAssignableFrom(L(t))?ot():at(e,t):this.isValidSnapshot(t,e)},t.prototype.is=function(t){return 0===this.validate(t,[{path:"",type:this}]).length},t.prototype.reconcile=function(t,e){var n=t.parent,r=t.subpath;if(Q(e)&&X(e)===t)return t;if(t.type===this&&h(e)&&!Q(e)&&(!t.identifierAttribute||t.identifier===e[t.identifierAttribute]))return t.applySnapshot(e),t;if(t.die(),Q(e)&&this.isAssignableFrom(L(e))){var i=X(e);return i.setParent(n,r),i}return this.instantiate(n,r,t._environment,e)},Object.defineProperty(t.prototype,"Type",{get:function(){return i("Factory.Type should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.Type`")},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"SnapshotType",{get:function(){return i("Factory.SnapshotType should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.SnapshotType`")},enumerable:!0,configurable:!0}),r([e.action],t.prototype,"create",null),t}(),zt=function(t){function e(e){return t.call(this,e)||this}return n(e,t),e.prototype.getValue=function(t){return t.storedValue},e.prototype.getSnapshot=function(t){return t.storedValue},e.prototype.getDefaultSnapshot=function(){},e.prototype.applySnapshot=function(t,e){i("Immutable types do not support applying snapshots")},e.prototype.applyPatchLocally=function(t,e,n){i("Immutable types do not support applying patches")},e.prototype.getChildren=function(t){return St},e.prototype.getChildNode=function(t,e){return i("No child '"+e+"' available in type: "+this.name)},e.prototype.getChildType=function(t){return i("No child '"+t+"' available in type: "+this.name)},e.prototype.reconcile=function(t,e){if(t.type===this&&t.storedValue===e)return t;var n=this.instantiate(t.parent,t.subpath,t._environment,e);return t.die(),n},e.prototype.removeChild=function(t,e){return i("No child '"+e+"' available in type: "+this.name)},e}(Nt),Dt=function(t){function o(n,r){var i=t.call(this,n)||this;return i.shouldAttachNode=!0,i.flags=jt.Map,i.createNewInstance=function(){var t=e.observable.shallowMap();return b(t,"put",ct),b(t,"toString",pt),t},i.finalizeNewInstance=function(t,n){var r=t.storedValue;e.extras.interceptReads(r,t.unbox),e.intercept(r,function(t){return i.willChange(t)}),t.applySnapshot(n),e.observe(r,i.didChange)},i.subType=r,i}return n(o,t),o.prototype.instantiate=function(t,e,n,r){return et(this,t,e,n,r,this.createNewInstance,this.finalizeNewInstance)},o.prototype.describe=function(){return"Map<string, "+this.subType.describe()+">"},o.prototype.getChildren=function(t){return t.storedValue.values()},o.prototype.getChildNode=function(t,e){var n=t.storedValue.get(e);return n||i("Not a child "+e),n},o.prototype.willChange=function(t){var e=X(t.object);switch(e.assertWritable(),t.type){case"update":var n=t.newValue;if(n===t.object.get(t.name))return null;ut(this.subType,n),t.newValue=this.subType.reconcile(e.getChildNode(t.name),t.newValue),this.verifyIdentifier(t.name,t.newValue);break;case"add":ut(this.subType,t.newValue),t.newValue=this.subType.instantiate(e,t.name,void 0,t.newValue),this.verifyIdentifier(t.name,t.newValue);break;case"delete":e.getChildNode(t.name).die()}return t},o.prototype.verifyIdentifier=function(t,e){var n=e.identifier;null!==n&&""+n!=""+t&&i("A map of objects containing an identifier should always store the object under their own identifier. Trying to store key '"+n+"', but expected: '"+t+"'")},o.prototype.getValue=function(t){return t.storedValue},o.prototype.getSnapshot=function(t){var e={};return t.getChildren().forEach(function(t){e[t.subpath]=t.snapshot}),e},o.prototype.didChange=function(t){var e=X(t.object);switch(t.type){case"update":return void e.emitPatch({op:"replace",path:A(t.name),value:t.newValue.snapshot,oldValue:t.oldValue?t.oldValue.snapshot:void 0},e);case"add":return void e.emitPatch({op:"add",path:A(t.name),value:t.newValue.snapshot,oldValue:void 0},e);case"delete":return void e.emitPatch({op:"remove",path:A(t.name),oldValue:t.oldValue.snapshot},e)}},o.prototype.applyPatchLocally=function(t,e,n){var r=t.storedValue;switch(n.op){case"add":case"replace":r.set(e,n.value);break;case"remove":r.delete(e)}},o.prototype.applySnapshot=function(t,e){ut(this,e);var n=t.storedValue,r={};n.keys().forEach(function(t){r[t]=!1}),Object.keys(e).forEach(function(t){n.set(t,e[t]),r[t]=!0}),Object.keys(r).forEach(function(t){!1===r[t]&&n.delete(t)})},o.prototype.getChildType=function(t){return this.subType},o.prototype.isValidSnapshot=function(t,e){var n=this;return l(t)?st(Object.keys(t).map(function(r){return n.subType.validate(t[r],it(e,r,n.subType))})):at(e,t)},o.prototype.getDefaultSnapshot=function(){return{}},o.prototype.removeChild=function(t,e){t.storedValue.delete(e)},r([e.action],o.prototype,"applySnapshot",null),o}(Nt),It=function(t){function o(n,r){var i=t.call(this,n)||this;return i.shouldAttachNode=!0,i.flags=jt.Array,i.createNewInstance=function(){var t=e.observable.shallowArray();return b(t,"toString",lt),t},i.finalizeNewInstance=function(t,n){var r=t.storedValue;e.extras.getAdministration(r).dehancer=t.unbox,e.intercept(r,function(t){return i.willChange(t)}),t.applySnapshot(n),e.observe(r,i.didChange)},i.subType=r,i}return n(o,t),o.prototype.describe=function(){return this.subType.describe()+"[]"},o.prototype.instantiate=function(t,e,n,r){return et(this,t,e,n,r,this.createNewInstance,this.finalizeNewInstance)},o.prototype.getChildren=function(t){return t.storedValue.peek()},o.prototype.getChildNode=function(t,e){var n=parseInt(e,10);return n<t.storedValue.length?t.storedValue[n]:i("Not a child: "+e)},o.prototype.willChange=function(t){var e=X(t.object);e.assertWritable();var n=e.getChildren();switch(t.type){case"update":if(t.newValue===t.object[t.index])return null;t.newValue=ht(e,this.subType,[n[t.index]],[t.newValue],[t.index])[0];break;case"splice":var r=t.index,i=t.removedCount,o=t.added;t.added=ht(e,this.subType,n.slice(r,r+i),o,o.map(function(t,e){return r+e}));for(var a=r+i;a<n.length;a++)n[a].setParent(e,""+(a+o.length-i))}return t},o.prototype.getValue=function(t){return t.storedValue},o.prototype.getSnapshot=function(t){return t.getChildren().map(function(t){return t.snapshot})},o.prototype.didChange=function(t){var e=X(t.object);switch(t.type){case"update":return void e.emitPatch({op:"replace",path:""+t.index,value:t.newValue.snapshot,oldValue:t.oldValue?t.oldValue.snapshot:void 0},e);case"splice":for(n=t.removedCount-1;n>=0;n--)e.emitPatch({op:"remove",path:""+(t.index+n),oldValue:t.removed[n].snapshot},e);for(var n=0;n<t.addedCount;n++)e.emitPatch({op:"add",path:""+(t.index+n),value:e.getChildNode(""+(t.index+n)).snapshot,oldValue:void 0},e);return}},o.prototype.applyPatchLocally=function(t,e,n){var r=t.storedValue,i="-"===e?r.length:parseInt(e);switch(n.op){case"replace":r[i]=n.value;break;case"add":r.splice(i,0,n.value);break;case"remove":r.splice(i,1)}},o.prototype.applySnapshot=function(t,e){ut(this,e),t.storedValue.replace(e)},o.prototype.getChildType=function(t){return this.subType},o.prototype.isValidSnapshot=function(t,e){var n=this;return s(t)?st(t.map(function(t,r){return n.subType.validate(t,it(e,""+r,n.subType))})):at(e,t)},o.prototype.getDefaultSnapshot=function(){return[]},o.prototype.removeChild=function(t,e){t.storedValue.splice(parseInt(e,10),1)},r([e.action],o.prototype,"applySnapshot",null),o}(Nt),Et=function(t){function e(e,n,r,i){void 0===i&&(i=o);var a=t.call(this,e)||this;return a.flags=n,a.checker=r,a.initializer=i,a}return n(e,t),e.prototype.describe=function(){return this.name},e.prototype.instantiate=function(t,e,n,r){return et(this,t,e,n,r,this.initializer)},e.prototype.isValidSnapshot=function(t,e){return f(t)&&this.checker(t)?ot():at(e,t)},e}(zt),Rt=new Et("string",jt.String,function(t){return"string"==typeof t}),kt=new Et("number",jt.Number,function(t){return"number"==typeof t}),Ft=new Et("boolean",jt.Boolean,function(t){return"boolean"==typeof t}),Lt=new Et("Date",jt.Date,function(t){return"number"==typeof t||t instanceof Date},function(t){return t instanceof Date?t:new Date(t)});Lt.getSnapshot=function(t){return t.storedValue.getTime()};var Mt=function(t){function e(e){var n=t.call(this,"identifier("+e.name+")")||this;return n.identifierType=e,n.flags=jt.Identifier,n}return n(e,t),e.prototype.instantiate=function(t,e,n,r){return t&&Q(t.storedValue)?(t.identifierAttribute&&i("Cannot define property '"+e+"' as object identifier, property '"+t.identifierAttribute+"' is already defined as identifier property"),t.identifierAttribute=e,et(this,t,e,n,r)):i("Identifier types can only be instantiated as direct child of a model type")},e.prototype.reconcile=function(t,e){return t.storedValue!==e?i("Tried to change identifier from '"+t.storedValue+"' to '"+e+"'. Changing identifiers is not allowed."):t},e.prototype.describe=function(){return"identifier("+this.identifierType.describe()+")"},e.prototype.isValidSnapshot=function(t,e){return void 0===t||null===t||"string"==typeof t||"number"==typeof t?this.identifierType.validate(t,e):at(e,t,"References should be a primitive value")},e}(zt),Ht=function(t){function e(e,n){var r=t.call(this,e.name)||this;return r.type=e,r.defaultValue=n,r}return n(e,t),Object.defineProperty(e.prototype,"flags",{get:function(){return this.type.flags|jt.Optional},enumerable:!0,configurable:!0}),e.prototype.describe=function(){return this.type.describe()+"?"},e.prototype.instantiate=function(t,e,n,r){if(void 0===r){var i=this.getDefaultValue(),o=Q(i)?X(i).snapshot:i;return this.type.instantiate(t,e,n,o)}return this.type.instantiate(t,e,n,r)},e.prototype.reconcile=function(t,e){return this.type.reconcile(t,this.type.is(e)?e:this.getDefaultValue())},e.prototype.getDefaultValue=function(){var t="function"==typeof this.defaultValue?this.defaultValue():this.defaultValue;return"function"==typeof this.defaultValue&&ut(this,t),t},e.prototype.isValidSnapshot=function(t,e){return void 0===t?ot():this.type.validate(t,e)},e}(zt),Ut=function(){function t(t){this.name=t}return t.prototype.initializePrototype=function(t){},t.prototype.initialize=function(t,e){},t.prototype.willChange=function(t){return null},t.prototype.didChange=function(t){},t.prototype.serialize=function(t,e){},t.prototype.deserialize=function(t,e){},t}(),$t=function(t){function r(e,n,r){var i=t.call(this,e)||this;return i.getter=n,i.setter=r,i}return n(r,t),r.prototype.initializePrototype=function(t){Object.defineProperty(t,this.name,e.computed(t,this.name,{get:this.getter,set:this.setter,configurable:!0,enumerable:!1}))},r.prototype.validate=function(t,e){return this.name in t?at(it(e,this.name),t[this.name],"Computed properties should not be provided in the snapshot"):ot()},r}(Ut),Jt=function(t){function e(e){var n=t.call(this,""+e)||this;return n.flags=jt.Literal,n.value=e,n}return n(e,t),e.prototype.instantiate=function(t,e,n,r){return et(this,t,e,n,r)},e.prototype.describe=function(){return JSON.stringify(this.value)},e.prototype.isValidSnapshot=function(t,e){return f(t)&&t===this.value?ot():at(e,t)},e}(zt),Wt=yt(void 0),Bt=function(t){function r(e,n){var r=t.call(this,e)||this;return r.type=n,r}return n(r,t),r.prototype.initializePrototype=function(t){e.observable.ref(t,this.name,{value:Wt.instantiate(null,"",null,void 0)})},r.prototype.initialize=function(t,n){var r=X(t);t[this.name]=this.type.instantiate(r,this.name,r._environment,n[this.name]),e.extras.interceptReads(t,this.name,r.unbox)},r.prototype.getValueNode=function(t){var e=t.$mobx.values[this.name].value;return e||i("Node not available for property "+this.name)},r.prototype.willChange=function(t){var e=X(t.object);return ut(this.type,t.newValue),t.newValue=this.type.reconcile(e.getChildNode(t.name),t.newValue),t},r.prototype.didChange=function(t){var e=X(t.object);e.emitPatch({op:"replace",path:A(this.name),value:t.newValue.snapshot,oldValue:t.oldValue?t.oldValue.snapshot:void 0},e)},r.prototype.serialize=function(t,n){e.extras.getAtom(t,this.name).reportObserved(),n[this.name]=this.getValueNode(t).snapshot},r.prototype.deserialize=function(t,e){t[this.name]=e[this.name]},r.prototype.validate=function(t,e){return this.type.validate(t[this.name],it(e,this.name,this.type))},r}(Ut),Yt=function(t){function e(e,n){var r=t.call(this,e)||this;return r.invokeAction=_(e,n),r}return n(e,t),e.prototype.initialize=function(t){b(t,this.name,this.invokeAction.bind(t))},e.prototype.validate=function(t,e){return this.name in t?at(it(e,this.name),t[this.name],"Action properties should not be provided in the snapshot"):ot()},e}(Ut),qt=function(t){function e(e,n){var r=t.call(this,e)||this;return r.invokeView=vt(e,n),r}return n(e,t),e.prototype.initialize=function(t){b(t,this.name,this.invokeView.bind(t))},e.prototype.validate=function(t,e){return this.name in t?at(it(e,this.name),t[this.name],"View properties should not be provided in the snapshot"):ot()},e}(Ut),Gt=function(t){function r(e,n){var r=t.call(this,e)||this;return r.initialValue=n,null!==n&&"object"==typeof n?i("Trying to declare property "+e+" with a non-primitive value. Please provide an initializer function to avoid accidental sharing of local state, like `"+e+": () => initialValue`"):r}return n(r,t),r.prototype.initialize=function(t,n){var r="function"==typeof this.initialValue?this.initialValue.call(t,t):this.initialValue;e.extendObservable(t,(i={},i[this.name]=r,i));var i},r.prototype.willChange=function(t){return t},r.prototype.validate=function(t,e){return this.name in t?at(it(e,this.name),t[this.name],"volatile state should not be provided in the snapshot"):ot()},r}(Ut),Kt=["preProcessSnapshot","afterCreate","afterAttach","postProcessSnapshot","beforeDetach","beforeDestroy"],Qt=function(t){function o(n,r,o,a){var s=t.call(this,n)||this;return s.shouldAttachNode=!0,s.flags=jt.Object,s.props={},s.createNewInstance=function(){var t=new s.modelConstructor;return e.extendShallowObservable(t,{}),t},s.finalizeNewInstance=function(t,n){var r=t.storedValue;s.forAllProps(function(t){return t.initialize(r,n)}),e.intercept(r,function(t){return s.willChange(t)}),e.observe(r,s.didChange)},s.didChange=function(t){s.props[t.name].didChange(t)},Object.freeze(r),Object.freeze(a),s.properties=r,s.state=o,s.actions=a,/^\w[\w\d_]*$/.test(n)||i("Typename should be a valid identifier: "+n),s.modelConstructor=new Function("return function "+n+" (){}")(),s.modelConstructor.prototype.toString=bt,s.parseModelProps(),s.forAllProps(function(t){return t.initializePrototype(s.modelConstructor.prototype)}),s}return n(o,t),o.prototype.instantiate=function(t,e,n,r){return et(this,t,e,n,this.preProcessSnapshot(r),this.createNewInstance,this.finalizeNewInstance)},o.prototype.willChange=function(t){return X(t.object).assertWritable(),this.props[t.name].willChange(t)},o.prototype.parseModelProps=function(){var t=this,e=t.properties,n=t.state,r=t.actions;for(var o in e)if(w(e,o)){-1!==Kt.indexOf(o)&&console.warn("Hook '"+o+"' was defined as property. Hooks should be defined as part of the actions");var a=Object.getOwnPropertyDescriptor(e,o);if("get"in a){this.props[o]=new $t(o,a.get,a.set);continue}if(null===(u=a.value))i("The default value of an attribute cannot be null or undefined as the type cannot be inferred. Did you mean `types.maybe(someType)`?");else if(f(u)){var s=ft(u);this.props[o]=new Bt(o,dt(s,u))}else E(u)?this.props[o]=new Bt(o,u):"function"==typeof u?this.props[o]=new qt(o,u):i("object"==typeof u?"In property '"+o+"': base model's should not contain complex values: '"+u+"'":"Unexpected value for property '"+o+"'")}for(var o in n)if(w(n,o)){-1!==Kt.indexOf(o)&&console.warn("Hook '"+o+"' was defined as local state. Hooks should be defined as part of the actions");u=n[o];o in this.properties&&i("Property '"+o+"' was also defined as local state. Local state fields and properties should not collide"),this.props[o]=new Gt(o,u)}for(var o in r)if(w(r,o)){var u=r[o];o in this.properties&&i("Property '"+o+"' was also defined as action. Actions and properties should not collide"),o in this.state&&i("Property '"+o+"' was also defined as local state. Actions and state should not collide"),"function"==typeof u?this.props[o]=new Yt(o,u):i("Unexpected value for action '"+o+"'. Expected function, got "+typeof u)}},o.prototype.getChildren=function(t){var e=[];return this.forAllProps(function(n){n instanceof Bt&&e.push(n.getValueNode(t.storedValue))}),e},o.prototype.getChildNode=function(t,e){return this.props[e]instanceof Bt?this.props[e].getValueNode(t.storedValue):i("Not a value property: "+e)},o.prototype.getValue=function(t){return t.storedValue},o.prototype.getSnapshot=function(t){var e={};return this.forAllProps(function(n){return n.serialize(t.storedValue,e)}),this.postProcessSnapshot(e)},o.prototype.applyPatchLocally=function(t,e,n){"replace"!==n.op&&"add"!==n.op&&i("object does not support operation "+n.op),t.storedValue[e]=n.value},o.prototype.applySnapshot=function(t,e){var n=this.preProcessSnapshot(e);ut(this,n);for(var r in this.props)this.props[r].deserialize(t.storedValue,n)},o.prototype.preProcessSnapshot=function(t){return"function"==typeof this.actions.preProcessSnapshot?this.actions.preProcessSnapshot.call(null,t):t},o.prototype.postProcessSnapshot=function(t){return"function"==typeof this.actions.postProcessSnapshot?this.actions.postProcessSnapshot.call(null,t):t},o.prototype.getChildType=function(t){return this.props[t].type},o.prototype.isValidSnapshot=function(t,e){var n=this,r=this.preProcessSnapshot(t);return l(r)?st(Object.keys(this.props).map(function(t){return n.props[t].validate(r,e)})):at(e,r)},o.prototype.forAllProps=function(t){var e=this;Object.keys(this.props).forEach(function(n){return t(e.props[n])})},o.prototype.describe=function(){var t=this;return"{ "+Object.keys(this.props).map(function(e){var n=t.props[e];return n instanceof Bt?e+": "+n.type.describe():""}).filter(Boolean).join("; ")+" }"},o.prototype.getDefaultSnapshot=function(){return{}},o.prototype.removeChild=function(t,e){t.storedValue[e]=null},r([e.action],o.prototype,"applySnapshot",null),o}(Nt),Xt=function(){return function(t,e){if(this.mode=t,this.value=e,"object"===t){if(!Q(e))return i("Can only store references to tree nodes, got: '"+e+"'");if(!X(e).identifierAttribute)return i("Can only store references with a defined identifier attribute.")}}}(),Zt=function(t){function e(e){var n=t.call(this,"reference("+e.name+")")||this;return n.targetType=e,n.flags=jt.Reference,n}return n(e,t),e.prototype.describe=function(){return this.name},e.prototype.getValue=function(t){var e=t.storedValue;if("object"===e.mode)return e.value;if(t.isAlive){var n=t.root.identifierCache.resolve(this.targetType,e.value);return n?n.value:i("Failed to resolve reference of type "+this.targetType.name+": '"+e.value+"' (in: "+t.path+")")}},e.prototype.getSnapshot=function(t){var e=t.storedValue;switch(e.mode){case"identifier":return e.value;case"object":return X(e.value).identifier}},e.prototype.instantiate=function(t,e,n,r){var i=Q(r);return et(this,t,e,n,new Xt(i?"object":"identifier",r))},e.prototype.reconcile=function(t,e){var n=Q(e)?"object":"identifier";if(F(t.type)){var r=t.storedValue;if(n===r.mode&&r.value===e)return t}var i=this.instantiate(t.parent,t.subpath,t._environment,e);return t.die(),i},e.prototype.isAssignableFrom=function(t){return this.targetType.isAssignableFrom(t)},e.prototype.isValidSnapshot=function(t,e){return"string"==typeof t||"number"==typeof t?ot():at(e,t,"Value '"+nt(t)+"' is not a valid reference. Expected a string or number.")},e}(zt),te=function(t){function e(e,n,r){var i=t.call(this,e)||this;return i.dispatcher=null,i.dispatcher=r,i.types=n,i}return n(e,t),Object.defineProperty(e.prototype,"flags",{get:function(){var t=jt.Union;return this.types.forEach(function(e){t|=e.flags}),t},enumerable:!0,configurable:!0}),e.prototype.isAssignableFrom=function(t){return this.types.some(function(e){return e.isAssignableFrom(t)})},e.prototype.describe=function(){return"("+this.types.map(function(t){return t.describe()}).join(" | ")+")"},e.prototype.instantiate=function(t,e,n,r){return this.determineType(r).instantiate(t,e,n,r)},e.prototype.reconcile=function(t,e){return this.determineType(e).reconcile(t,e)},e.prototype.determineType=function(t){if(null!==this.dispatcher)return this.dispatcher(t);var e=this.types.filter(function(e){return e.is(t)});return e.length>1?i("Ambiguos snapshot "+JSON.stringify(t)+" for union "+this.name+". Please provide a dispatch in the union declaration."):e[0]},e.prototype.isValidSnapshot=function(t,e){if(null!==this.dispatcher)return this.dispatcher(t).validate(t,e);var n=this.types.map(function(n){return n.validate(t,e)}),r=n.filter(function(t){return 0===t.length});return r.length>1?at(e,t,"Multiple types are applicable and no dispatch method is defined for the union"):r.length<1?at(e,t,"No type is applicable and no dispatch method is defined for the union").concat(st(n)):ot()},e}(zt),ee=new(function(t){function e(){var e=t.call(this,"frozen")||this;return e.flags=jt.Frozen,e}return n(e,t),e.prototype.describe=function(){return"<any immutable value>"},e.prototype.instantiate=function(t,e,n,r){return et(this,t,e,n,y(r))},e.prototype.isValidSnapshot=function(t,e){return v(t)?ot():at(e,t)},e}(zt)),ne=dt(yt(null),null),re=function(t){function e(e,n,r){var i=t.call(this,e)||this;return i.type=n,i.predicate=r,i}return n(e,t),Object.defineProperty(e.prototype,"flags",{get:function(){return this.type.flags|jt.Refinement},enumerable:!0,configurable:!0}),e.prototype.describe=function(){return this.name},e.prototype.instantiate=function(t,e,n,r){return this.type.instantiate(t,e,n,r)},e.prototype.isAssignableFrom=function(t){return this.type.isAssignableFrom(t)},e.prototype.isValidSnapshot=function(t,e){if(this.type.is(t)){var n=Q(t)?X(t).snapshot:t;if(this.predicate(n))return ot()}return at(e,t)},e}(zt),ie=function(t){function e(e,n){var r=t.call(this,e)||this;return r._subType=null,"function"==typeof n&&0===n.length||i("Invalid late type, expected a function with zero arguments that returns a type, got: "+n),r.definition=n,r}return n(e,t),Object.defineProperty(e.prototype,"flags",{get:function(){return this.subType.flags|jt.Late},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"subType",{get:function(){return null===this._subType&&(this._subType=this.definition()),this._subType},enumerable:!0,configurable:!0}),e.prototype.instantiate=function(t,e,n,r){return this.subType.instantiate(t,e,n,r)},e.prototype.reconcile=function(t,e){return this.subType.reconcile(t,e)},e.prototype.describe=function(){return this.subType.name},e.prototype.isValidSnapshot=function(t,e){return this.subType.validate(t,e)},e.prototype.isAssignableFrom=function(t){return this.subType.isAssignableFrom(t)},e}(zt),oe={model:gt,compose:mt,reference:function(t){return 2===arguments.length&&"string"==typeof arguments[1]&&i("References with base path are no longer supported. Please remove the base path."),new Zt(t)},union:wt,optional:dt,literal:yt,maybe:function(t){return t===ee&&i("Unable to declare `types.maybe(types.frozen)`. Frozen already accepts `null`. Consider using `types.optional(types.frozen, null)` instead."),wt(ne,t)},refinement:function(t,e,n){return new re(t,e,n)},string:Rt,boolean:Ft,number:kt,Date:Lt,map:function(t){return new Dt("map<string, "+t.name+">",t)},array:function(t){return new It(t.name+"[]",t)},frozen:ee,identifier:function(t){return void 0===t&&(t=Rt),new Mt(t)},late:function(t,e){var n="string"==typeof t?t:"late("+t.toString()+")";return new ie(n,"string"==typeof t?e:t)}};t.types=oe,t.escapeJsonPath=A,t.unescapeJsonPath=C,t.onAction=I,t.isStateTreeNode=Q,t.asReduxStore=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];Q(t)||i("Expected model object");var r={getState:function(){return Y(t)},dispatch:function(e){Pt(e,o.slice(),function(e){return D(t,Vt(e))})},subscribe:function(e){return U(t,e)}},o=e.map(function(t){return t(r)});return r},t.connectReduxDevtools=function(t,e){var n=t.connectViaExtension(),r=!1;n.subscribe(function(n){var i=t.extractState(n);i&&(r=!0,B(e,i),r=!1)}),I(e,function(t){if(!r){var i={};i.type=t.name,t.args&&t.args.forEach(function(t,e){return i[e]=t}),n.send(i,Y(e))}})},t.getType=L,t.getChildType=function(t,e){return X(t).getChildType(e)},t.addMiddleware=M,t.onPatch=H,t.onSnapshot=U,t.applyPatch=$,t.revertPatch=J,t.recordPatches=function(t){var e={patches:[],get cleanPatches(){return this.patches.map(j)},stop:function(){n()},replay:function(n){$(n||t,e.patches)},undo:function(e){J(t||t,this.patches)}},n=H(t,function(t){e.patches.push(t)},!0);return e},t.applyAction=W,t.recordActions=function(t){var e={actions:[],stop:function(){return n()},replay:function(t){W(t,e.actions)}},n=I(t,e.actions.push.bind(e.actions));return e},t.protect=function(t){var e=X(t);e.isRoot||i("`protect` can only be invoked on root nodes"),e.isProtectionEnabled=!0},t.unprotect=function(t){var e=X(t);e.isRoot||i("`unprotect` can only be invoked on root nodes"),e.isProtectionEnabled=!1},t.isProtected=function(t){return X(t).isProtected},t.applySnapshot=B,t.getSnapshot=Y,t.hasParent=function(t,e){void 0===e&&(e=1),e<0&&i("Invalid depth: "+e+", should be >= 1");for(var n=X(t).parent;n;){if(0==--e)return!0;n=n.parent}return!1},t.getParent=function(t,e){void 0===e&&(e=1),e<0&&i("Invalid depth: "+e+", should be >= 1");for(var n=e,r=X(t).parent;r;){if(0==--n)return r.storedValue;r=r.parent}return i("Failed to find the parent of "+X(t)+" at depth "+e)},t.getRoot=function(t){return X(t).root.storedValue},t.getPath=function(t){return X(t).path},t.getPathParts=function(t){return T(X(t).path)},t.isRoot=function(t){return X(t).isRoot},t.resolvePath=q,t.resolveIdentifier=function(t,e,n){E(t)||i("Expected a type as first argument");var r=X(e).root.identifierCache.resolve(t,""+n);return r?r.value:void 0},t.tryResolve=G,t.getRelativePath=function(t,e){return X(t).getRelativePathTo(X(e))},t.clone=function(t,e){void 0===e&&(e=!0);var n=X(t);return n.type.create(n.snapshot,!0===e?n.root._environment:!1===e?void 0:e)},t.detach=function(t){return X(t).detach(),t},t.destroy=function(t){var e=X(t);e.isRoot?e.die():e.parent.removeChild(e.subpath)},t.isAlive=function(t){return X(t).isAlive},t.addDisposer=function(t,e){X(t).addDisposer(e)},t.getEnv=function(t){var e=X(t),n=e.root._environment;return n||i("Node '"+e+"' is not part of state tree that was initialized with an environment. Environment can be passed as second argumentt to .create()"),n},t.walk=K,Object.defineProperty(t,"__esModule",{value:!0})}); |
{ | ||
"name": "mobx-state-tree", | ||
"version": "0.9.1", | ||
"version": "0.9.2", | ||
"description": "Opinionated, transactional, MobX powered state container", | ||
@@ -5,0 +5,0 @@ "main": "dist/mobx-state-tree.js", |
@@ -118,3 +118,3 @@ <p align="center"> | ||
Since MST uses MobX behind the scenes, it integrates seamlessly with [mobx](https://mobx.js.org) and [mobx-react](github.com/mobxjs/mobx-react). | ||
Since MST uses MobX behind the scenes, it integrates seamlessly with [mobx](https://mobx.js.org) and [mobx-react](https://github.com/mobxjs/mobx-react). | ||
But even cooler; because it supports snapshots, middleware and replayable actions out of the box, it is even possible to replace a Redux store and reducer with a MobX state tree. | ||
@@ -209,3 +209,3 @@ This makes it even possible to connect the Redux devtools to MST. See the [Redux / MST TodoMVC example](https://github.com/mobxjs/mobx-state-tree/blob/4c2b19ec4a6a8d74064e4b8a87c0f8b46e97e621/examples/redux-todomvc/src/index.js#L6). | ||
findTodosByUser(user) { // 7 | ||
return this.todos.filter(t => t.assignee = user) | ||
return this.todos.filter(t => t.assignee === user) | ||
} | ||
@@ -360,2 +360,3 @@ }, { | ||
- A single mutation can result in multiple patches, for example when splicing an array | ||
- Patches can be reverse applied, which enables many powerful patterns like undo / redo | ||
@@ -365,3 +366,4 @@ Useful methods: | ||
- `onPatch(model, listener)` attaches a patch listener to the provided model, which will be invoked whenever the model or any of its descendants is mutated | ||
- `applyPatch(model, patch)` applies a patch to the provided model | ||
- `applyPatch(model, patch)` applies a patch (or array of patches) to the provided model | ||
- `revertPatch(model, patch)` reverse applies a patch (or array of patches) to the provided model, this replays the inverse of a set of patches to an model, which can be used to bring it back to it's original state | ||
@@ -626,3 +628,3 @@ ### References and identifiers | ||
| `applyAction(node, actionDescription)` | Replays an action on the targeted node | | ||
| `applyPatch(node, jsonPatch)` | Applies a JSON patch to a node in the tree | | ||
| `applyPatch(node, jsonPatch)` | Applies a JSON patch or array of patches to a node in the tree | | ||
| `applySnapshot(node, snapshot)` | Updates a node with the given snapshot | | ||
@@ -656,2 +658,3 @@ | `asReduxStore(node)` | Wraps a node in a Redux store compatible api | | ||
| `resolve(node, path)` | Resolves a `path` (json path) relatively to the given `node` | | ||
| `revertPatch(node, jsonPatch)` | Inverse applies a JSON patch or array of patches to a node in the tree | | ||
| `splitJsonPath(path)` | Splits and unescapes the given json path into path parts | | ||
@@ -658,0 +661,0 @@ | `tryResolve(node, path)` | Like `resolve`, but just returns `null` if resolving fails at any point in the path | |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
397007
7137
802