mobx-state-tree
Advanced tools
Comparing version 0.10.3 to 0.11.0
@@ -0,1 +1,23 @@ | ||
# 0.11.0 | ||
### Breaking changes | ||
* **BREAKING** `onAction` middleware no longer throws when encountering unserializable arguments. Rather, it serializes a struct like `{ $MST_UNSERIALIZABLE: true, type: "someType" }`. MST Nodes are no longer automatically serialized. Rather, one should either pass 1: an id, 2: a (relative) path, 3: a snapshot | ||
* **BREAKING** `revertPatch` has been dropped. `IReversableJsonPatch` is no longer exposed, instead use the inverse patches generated by `onPatch` | ||
* **BREAKING** some middleware events have been renamed: `process_yield` -> `process_resume`, `process_yield_error` -> `process_resume_error`, to make it less confusing how these events relate to `yield` statements. | ||
* **BREAKING** patchRecorder's field `patches` has been renamed to `rawPatches, `cleanPatches` to `patches`, and `inversePatches` was added. | ||
### New features | ||
* Introduced `decorate(middleware, action)` to easily attach middleware to a specific action | ||
* Handlers passed to `onPatch(handler: (patch, inversePatch) => void)` now receive as second argument the inverse patch of the emitted patch | ||
* `onAction` lister now supports an `attachAfter` parameter | ||
* Middleware events now also contain `parentId` (id of the causing action, `0` if none) and `tree` (the root of context) | ||
### Fixes | ||
* ReduxDevTools connection is no longer one step behind [#287](https://github.com/mobxjs/mobx-state-tree/issues/287) | ||
* Middleware is no longer run as part of the transaction of the targeted action | ||
* Fixed representation of `union` types in error messages | ||
# 0.10.3 | ||
@@ -2,0 +24,0 @@ |
@@ -1,33 +0,31 @@ | ||
export declare type ISerializedActionCall = { | ||
name: string; | ||
path?: string; | ||
args?: any[]; | ||
}; | ||
export declare type IMiddlewareEventType = "action" | "process_spawn" | "process_yield" | "process_yield_error" | "process_return" | "process_throw"; | ||
export declare type IMiddleWareEvent = { | ||
export declare type IMiddlewareEventType = "action" | "process_spawn" | "process_resume" | "process_resume_error" | "process_return" | "process_throw"; | ||
export declare type IMiddlewareEvent = { | ||
type: IMiddlewareEventType; | ||
name: string; | ||
id: number; | ||
parentId: number; | ||
rootId: number; | ||
context: IStateTreeNode; | ||
tree: IStateTreeNode; | ||
args: any[]; | ||
}; | ||
export declare type IMiddlewareHandler = (actionCall: IMiddlewareEvent, next: (actionCall: IMiddlewareEvent) => any) => any; | ||
export declare function getNextActionId(): number; | ||
export declare function runWithActionContext(context: IMiddleWareEvent, fn: Function): any; | ||
export declare function getActionContext(): IMiddleWareEvent; | ||
export declare function createActionInvoker<T extends Function>(target: IStateTreeNode, name: string, fn: T): T; | ||
export declare type IMiddleWareHandler = (actionCall: IMiddleWareEvent, next: (actionCall: IMiddleWareEvent) => any) => any; | ||
export declare function applyAction(target: IStateTreeNode, action: ISerializedActionCall): any; | ||
export declare function runWithActionContext(context: IMiddlewareEvent, fn: Function): any; | ||
export declare function getActionContext(): IMiddlewareEvent; | ||
export declare function createActionInvoker<T extends Function>(target: IStateTreeNode, name: string, fn: T): () => any; | ||
/** | ||
* Registers a function that will be invoked for each action that is called on the provided model instance, or to any of its children. | ||
* See [actions](https://github.com/mobxjs/mobx-state-tree#actions) for more details. onAction events are emitted only for the outermost called action in the stack. | ||
* Action can also be intercepted by middleware using addMiddleware to change the function call before it will be run. | ||
* Middleware can be used to intercept any action is invoked on the subtree where it is attached. | ||
* If a tree is protected (by default), this means that any mutation of the tree will pass through your middleware. | ||
* | ||
* For more details, see the [middleware docs](docs/middleware.md) | ||
* | ||
* @export | ||
* @param {IStateTreeNode} target | ||
* @param {(call: ISerializedActionCall) => void} listener | ||
* @param {(action: IRawActionCall, next: (call: IRawActionCall) => any) => any} middleware | ||
* @returns {IDisposer} | ||
*/ | ||
export declare function onAction(target: IStateTreeNode, listener: (call: ISerializedActionCall) => void): IDisposer; | ||
export declare function addMiddleware(target: IStateTreeNode, middleware: IMiddlewareHandler): IDisposer; | ||
export declare function decorate<T extends Function>(middleware: IMiddlewareHandler, fn: T): T; | ||
import { IStateTreeNode } from "./node"; | ||
import { IDisposer } from "../utils"; |
@@ -0,0 +0,0 @@ import { IType } from "../types/type"; |
export * from "./node"; | ||
export { onAction, createActionInvoker } from "./action"; | ||
export { createActionInvoker } from "./action"; | ||
export * from "./json-patch"; | ||
export * from "./mst-operations"; |
@@ -7,5 +7,5 @@ export declare type IJsonPatch = { | ||
export declare type IReversibleJsonPatch = IJsonPatch & { | ||
oldValue?: any; | ||
oldValue: any; | ||
}; | ||
export declare function invertPatch(patch: IReversibleJsonPatch): IReversibleJsonPatch; | ||
export declare function splitPatch(patch: IReversibleJsonPatch): [IJsonPatch, IJsonPatch]; | ||
export declare function stripPatch(patch: IReversibleJsonPatch): IJsonPatch; | ||
@@ -12,0 +12,0 @@ /** |
@@ -13,3 +13,2 @@ /** | ||
* @example | ||
* ```typescript | ||
* const Box = types.model({ x: 0, y: 0 }) | ||
@@ -19,3 +18,2 @@ * const box = Box.create() | ||
* console.log(getChildType(box, "x").name) // 'number' | ||
* ``` | ||
* | ||
@@ -29,15 +27,13 @@ * @export | ||
/** | ||
* Middleware can be used to intercept any action is invoked on the subtree where it is attached. | ||
* If a tree is protected (by default), this means that any mutation of the tree will pass through your middleware. | ||
* Registers a function that will be invoked for each mutation that is applied to the provided model instance, or to any of its children. | ||
* See [patches](https://github.com/mobxjs/mobx-state-tree#patches) for more details. onPatch events are emitted immediately and will not await the end of a transaction. | ||
* Patches can be used to deep observe a model tree. | ||
* | ||
* For more details, see the [middleware docs](docs/middleware.md) | ||
* | ||
* @export | ||
* @param {IStateTreeNode} target | ||
* @param {(action: IRawActionCall, next: (call: IRawActionCall) => any) => any} middleware | ||
* @returns {IDisposer} | ||
* @param {Object} target the model instance from which to receive patches | ||
* @param {(patch: IJsonPatch, reversePatch) => void} callback the callback that is invoked for each patch. The reversePatch is a patch that would actually undo the emitted 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 addMiddleware(target: IStateTreeNode, middleware: (action: IMiddleWareEvent, next: (call: IMiddleWareEvent) => any) => any): IDisposer; | ||
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 onPatch(target: IStateTreeNode, callback: (patch: IJsonPatch, reversePatch: IJsonPatch) => void): IDisposer; | ||
export declare function onSnapshot<S>(target: ObservableMap<S>, callback: (snapshot: { | ||
@@ -60,17 +56,5 @@ [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: ReadonlyArray<IReversibleJsonPatch>; | ||
cleanPatches: ReadonlyArray<IJsonPatch>; | ||
patches: ReadonlyArray<IJsonPatch>; | ||
inversePatches: ReadonlyArray<IJsonPatch>; | ||
stop(): any; | ||
@@ -84,10 +68,12 @@ replay(target?: IStateTreeNode): any; | ||
* | ||
* ```typescript | ||
* @example | ||
* export interface IPatchRecorder { | ||
* // the recorded patches | ||
* patches: IJsonPatch[] | ||
* // the same set of recorded patches, but without undo information, making them smaller and compliant with json-patch spec | ||
* cleanPatches: IJSonPatch[] | ||
* // the inverse of the recorded patches | ||
* inversePatches: IJsonPatch[] | ||
* // stop recording patches | ||
* stop(target?: IStateTreeNode): any | ||
* // resume recording patches | ||
* resume() | ||
* // apply all the recorded patches on the given target (the original subject if omitted) | ||
@@ -99,3 +85,2 @@ * replay(target?: IStateTreeNode): any | ||
* } | ||
* ``` | ||
* | ||
@@ -108,38 +93,2 @@ * @export | ||
/** | ||
* Applies an action or a series of actions in a single MobX transaction. | ||
* Does not return any value | ||
* Takes an action description as produced by the `onAction` middleware. | ||
* | ||
* @export | ||
* @param {Object} target | ||
* @param {IActionCall[]} actions | ||
* @param {IActionCallOptions} [options] | ||
*/ | ||
export declare function applyAction(target: IStateTreeNode, actions: ISerializedActionCall | ISerializedActionCall[]): void; | ||
export interface IActionRecorder { | ||
actions: ReadonlyArray<ISerializedActionCall>; | ||
stop(): any; | ||
replay(target: IStateTreeNode): any; | ||
} | ||
/** | ||
* Small abstraction around `onAction` and `applyAction`, attaches an action listener to a tree and records all the actions emitted. | ||
* Returns an recorder object with the following signature: | ||
* | ||
* ```typescript | ||
* export interface IActionRecorder { | ||
* // the recorded actions | ||
* actions: ISerializedActionCall[] | ||
* // stop recording actions | ||
* stop(): any | ||
* // apply all the recorded actions on the given object | ||
* replay(target: IStateTreeNode): any | ||
* } | ||
* ``` | ||
* | ||
* @export | ||
* @param {IStateTreeNode} subject | ||
* @returns {IPatchRecorder} | ||
*/ | ||
export declare function recordActions(subject: IStateTreeNode): IActionRecorder; | ||
/** | ||
* The inverse of `unprotect` | ||
@@ -307,3 +256,2 @@ * | ||
* @example | ||
* ```javascript | ||
* const Todo = types.model({ | ||
@@ -322,3 +270,2 @@ * title: types.string | ||
* }) | ||
* ``` | ||
* | ||
@@ -343,7 +290,6 @@ * @export | ||
export declare function walk(target: IStateTreeNode, processor: (item: IStateTreeNode) => void): void; | ||
import { IMiddleWareEvent, ISerializedActionCall } from "./action"; | ||
import { IObservableArray, ObservableMap } from "mobx"; | ||
import { IStateTreeNode } from "./node"; | ||
import { IJsonPatch, IReversibleJsonPatch } from "./json-patch"; | ||
import { IJsonPatch } from "./json-patch"; | ||
import { IDisposer } from "../utils"; | ||
import { ISnapshottable, IType } from "../types/type"; |
@@ -15,7 +15,7 @@ export declare class Node { | ||
private _isDetaching; | ||
readonly middlewares: IMiddleWareHandler[]; | ||
readonly middlewares: IMiddlewareHandler[]; | ||
private readonly snapshotSubscribers; | ||
private readonly patchSubscribers; | ||
private readonly disposers; | ||
applyPatches: (patches: IReversibleJsonPatch[]) => void; | ||
applyPatches: (patches: IJsonPatch[]) => void; | ||
applySnapshot: (snapshot: any) => void; | ||
@@ -42,9 +42,9 @@ constructor(type: IType<any, any>, parent: Node | null, subpath: string, environment: any, initialValue: any, createNewInstance?: (initialValue: any) => any, finalizeNewInstance?: (node: Node, initialValue: any) => void); | ||
emitSnapshot(snapshot: any): void; | ||
applyPatchLocally(subpath: string, patch: IReversibleJsonPatch): void; | ||
onPatch(onPatch: (patch: IReversibleJsonPatch) => void, includeOldValue: boolean): IDisposer; | ||
emitPatch(patch: IReversibleJsonPatch, source: Node): void; | ||
applyPatchLocally(subpath: string, patch: IJsonPatch): void; | ||
onPatch(handler: (patch: IJsonPatch, reversePatch: IJsonPatch) => void): IDisposer; | ||
emitPatch(basePatch: IReversibleJsonPatch, source: Node): void; | ||
setParent(newParent: Node | null, subpath?: string | null): void; | ||
addDisposer(disposer: () => void): void; | ||
isRunningAction(): boolean; | ||
addMiddleWare(handler: IMiddleWareHandler): IDisposer; | ||
addMiddleWare(handler: IMiddlewareHandler): IDisposer; | ||
getChildNode(subpath: string): Node; | ||
@@ -77,5 +77,5 @@ getChildren(): Node[]; | ||
import { IType } from "../types/type"; | ||
import { IReversibleJsonPatch } from "./json-patch"; | ||
import { IMiddleWareHandler } from "./action"; | ||
import { IReversibleJsonPatch, IJsonPatch } from "./json-patch"; | ||
import { IMiddlewareHandler } from "./action"; | ||
import { IDisposer } from "../utils"; | ||
import { IdentifierCache } from "./identifier-cache"; |
@@ -0,0 +0,0 @@ export declare function process<R>(generator: () => IterableIterator<any>): () => Promise<R>; |
@@ -6,5 +6,6 @@ import "./core/node"; | ||
export { escapeJsonPath, unescapeJsonPath, IJsonPatch } from "./core/json-patch"; | ||
export { onAction, ISerializedActionCall, IMiddleWareEvent, IMiddlewareEventType, IMiddleWareHandler } from "./core/action"; | ||
export { decorate, addMiddleware, IMiddlewareEvent, IMiddlewareHandler, IMiddlewareEventType } from "./core/action"; | ||
export { process } from "./core/process"; | ||
export { isStateTreeNode, IStateTreeNode } from "./core/node"; | ||
export { asReduxStore, IReduxStore, connectReduxDevtools } from "./interop/redux"; | ||
export { applyAction, onAction, IActionRecorder, ISerializedActionCall, recordActions } from "./middlewares/on-action"; |
@@ -1,2 +0,2 @@ | ||
import { IMiddleWareEvent } from "../core/action"; | ||
import { IMiddlewareEvent } from "../core/action"; | ||
export interface IMiddleWareApi { | ||
@@ -9,3 +9,3 @@ getState: () => any; | ||
} | ||
export declare type MiddleWare = (middlewareApi: IMiddleWareApi) => ((next: (action: IMiddleWareEvent) => void) => void); | ||
export declare type MiddleWare = (middlewareApi: IMiddleWareApi) => ((next: (action: IMiddlewareEvent) => void) => void); | ||
/** | ||
@@ -12,0 +12,0 @@ * Creates a tiny proxy around a MST tree that conforms to the redux store api. |
@@ -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}mt(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]:Vt}function p(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];for(var r=0;r<e.length;r++){var i=e[r];for(var o in i)t[o]=i[o]}return t}function c(t){if(null===t||"object"!=typeof t)return!1;var e=Object.getPrototypeOf(t);return e===Object.prototype||null===e}function l(t){return!(null===t||"object"!=typeof t||t instanceof Date||t instanceof RegExp)}function f(t){return null===t||void 0===t||("string"==typeof t||"number"==typeof t||"boolean"==typeof t||t instanceof Date)}function h(t){return f(t)?t:Object.freeze(t)}function d(t){return h(t),c(t)&&Object.keys(t).forEach(function(e){f(t[e])||Object.isFrozen(t[e])||d(t[e])}),t}function y(t){return"function"!=typeof t}function v(t,e,n){Object.defineProperty(t,e,{enumerable:!1,writable:!1,configurable:!0,value:n})}function b(t,e,n){Object.defineProperty(t,e,{enumerable:!0,writable:!1,configurable:!0,value:n})}function g(t,e){return t.push(e),function(){var n=t.indexOf(e);-1!==n&&t.splice(n,1)}}function m(t){for(var e=new Array(t.length),n=0;n<t.length;n++)e[n]=t[n];return e}function w(t){switch("oldValue"in t||i("Patches without `oldValue` field cannot be inversed"),t.op){case"add":return{op:"remove",path:t.path,oldValue:t.value};case"remove":return{op:"add",path:t.path,value:t.oldValue};case"replace":return{op:"replace",path:t.path,value:t.oldValue,oldValue:t.value}}}function V(t){var e=wt({},t);return delete e.oldValue,e}function P(t){return t.replace(/~/g,"~1").replace(/\//g,"~0")}function j(t){return t.replace(/~0/g,"\\").replace(/~1/g,"~")}function A(t){return 0===t.length?"":"/"+t.map(P).join("/")}function S(t){var e=t.split("/").map(j);return""===e[0]?e.slice(1):e}function C(){return jt++}function T(t,e){var n=Q(t.context),r=n._isRunningAction,i=At;n.assertAlive(),n._isRunningAction=!0,At=t;try{return N(n,t,e)}finally{At=i,n._isRunningAction=r}}function O(){return At||i("Not running an action!")}function x(t,n,r){return e.action(n,function(){var e=C();return T({type:"action",name:n,id:e,args:m(arguments),context:t,rootId:At?At.rootId:e},r)})}function _(t){for(var e=t.middlewares.slice(),n=t;n.parent;)n=n.parent,e=e.concat(n.middlewares);return e}function N(t,e,n){function r(t){var o=i.shift();return o?o(t,r):n.apply(e.context,e.args)}var i=_(t);return i.length?r(e):n.apply(e.context,e.args)}function I(t,n,r,i){if(f(i))return i;if(K(i)){var o=Q(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(Q(i))}}if("function"==typeof i)throw new Error("Argument "+r+" that was passed to action '"+n+"' should be a primitive, model object or plain object, received a function");if("object"==typeof i&&!c(i)&&!s(i))throw new Error("Argument "+r+" that was passed to action '"+n+"' should be a primitive, model object or plain object, received a "+(i&&i.constructor?i.constructor.name:"Complex Object"));if(e.isObservable(i))throw new Error("Argument "+r+" that was passed to action '"+n+"' should be a primitive, model object or plain object, received an mobx observable.");try{return JSON.stringify(i),i}catch(t){throw new Error("Argument "+r+" that was passed to action '"+n+"' is not serializable.")}}function D(t,e){if(e&&"object"==typeof e){var n=Object.keys(e);if(1===n.length&&"$ref"===n[0])return B(t.storedValue,e.$ref)}return e}function E(t,e){var n=q(t,e.path||"");if(!n)return i("Invalid action path: "+(e.path||""));var r=Q(n);return"@APPLY_PATCHES"===e.name?H.call(null,n,e.args[0]):"@APPLY_SNAPSHOT"===e.name?W.call(null,n,e.args[0]):("function"!=typeof n[e.name]&&i("Action '"+e.name+"' does not exist in '"+r.path+"'"),n[e.name].apply(n,e.args?e.args.map(function(t){return D(r,t)}):[]))}function R(t,e){return L(t,function(n,r){var i=Q(n.context);return"action"===n.type&&n.id===n.rootId&&e({name:n.name,path:Q(t).getRelativePathTo(i),args:n.args.map(function(t,e){return I(i,n.name,e,t)})}),r(n)})}function z(t){return"object"==typeof t&&t&&!0===t.isType}function k(t){return(t.flags>.Reference)>0}function F(t){return Q(t).type}function L(t,e){return Q(t).addMiddleWare(e)}function M(t,e,n){return void 0===n&&(n=!1),Q(t).onPatch(e,n)}function U(t,e){return Q(t).onSnapshot(e)}function H(t,e){Q(t).applyPatches(u(e))}function $(t,e){var n=u(e).map(w);n.reverse(),Q(t).applyPatches(n)}function J(t,n){e.runInAction(function(){u(n).forEach(function(e){return E(t,e)})})}function W(t,e){return Q(t).applySnapshot(e)}function Y(t){return Q(t).snapshot}function B(t,e){var n=Q(t).resolve(e);return n?n.value:void 0}function q(t,e){var n=Q(t).resolve(e,!1);if(void 0!==n)return n?n.value:void 0}function G(t,e){var n=Q(t);n.getChildren().forEach(function(t){K(t.storedValue)&&G(t.storedValue,e)}),e(n.storedValue)}function K(t){return!(!t||!t.$treenode)}function Q(t){return K(t)?t.$treenode:i("Value "+t+" is no MST Node")}function X(t){return t&&"object"==typeof t&&!(t instanceof Date)&&!K(t)&&!Object.isFrozen(t)}function Z(){return Q(this).snapshot}function tt(t,e,n,r,s,u,p){if(void 0===u&&(u=o),void 0===p&&(p=a),K(s)){var c=Q(s);return c.isRoot||i("Cannot add an object to a state tree if it is already part of the same or another state tree. Tried to assign an object to '"+(e?e.path:"")+"/"+n+"', but it lives already at '"+c.path+"'"),c.setParent(e,n),c}return new Tt(t,e,n,r,s,u,p)}function et(t,e,n){return t.concat([{path:e,type:n}])}function nt(){return Vt}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(){return Q(this)+"("+this.size+" items)"}function at(t){t||i("Map.put cannot be used to set empty values");var e;if(K(t))e=Q(t);else{if(!l(t))return i("Map.put can only be used to store complex values");e=Q(Q(this).type.subType.create(t))}return e.identifierAttribute||i("Map.put can only be used to store complex values that have an identifier type attribute"),this.set(e.identifier,e.value),this}function st(){return Q(this)+"("+this.length+" items)"}function ut(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(K(n))(f=Q(n)).assertAlive(),f.parent===t?(u[f.nodeId]||i("Cannot add an object to a state tree if it is already part of the same or another state tree. Tried to assign an object to '"+t.path+"/"+p+"', but it lives already at '"+f.path+"'"),u[f.nodeId]=void 0,f.setParent(t,p),s[r]=f):s[r]=e.instantiate(t,p,void 0,n);else if(l(n)){var c=a(n);if(c){var f=e.reconcile(c,n);u[c.nodeId]=void 0,f.setParent(t,p),s[r]=f}else s[r]=e.instantiate(t,p,void 0,n)}else s[r]=e.instantiate(t,p,void 0,n)});for(var c in u)void 0!==u[c]&&u[c].die();return s}function pt(t){switch(typeof t){case"string":return Dt;case"number":return Et;case"boolean":return Rt;case"object":if(t instanceof Date)return Ft}return i("Cannot determine primtive type from value "+t)}function ct(t,e){return new Mt(t,e)}function lt(){return Q(this).toString()}function ft(t){return Object.keys(t).reduce(function(t,e){if(e in Ut)return i("Hook '"+e+"' was defined as property. Hooks should be defined as part of the actions");var n=Object.getOwnPropertyDescriptor(t,e);"get"in n&&i("Getters are not supported as properties. Please use views instead");var r=n.value;if(null===r)i("The default value of an attribute cannot be null or undefined as the type cannot be inferred. Did you mean `types.maybe(someType)`?");else{if(f(r))return Object.assign({},t,(o={},o[e]=ct(pt(r),r),o));if(z(r))return t;i("function"==typeof r?"Functions are not supported as properties, use views instead":"object"==typeof r?"In property '"+e+"': base model's should not contain complex values: '"+r+"'":"Unexpected value for property '"+e+"'")}var o},t)}function ht(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var r=z(t)?null:t,i=z(t)?e.concat(t):e,o=i.map(function(t){return t.name}).join(" | ");return new Yt(o,i,r)}function dt(t){return new Bt(t)}function yt(t,e){return function(){function n(e,n,i){T({name:t,type:n,id:r,args:[i],context:o.context,rootId:o.rootId},e)}var r=C(),o=O(),a=arguments;return new Promise(function(s,u){function p(t,e){void 0===e&&(e=!0);var r;try{e?n(function(t){r=f.next(t)},"process_yield",t):r=f.next(t)}catch(t){return void setImmediate(function(){n(function(e){u(t)},"process_throw",t)})}l(r)}function c(t){var e;try{n(function(t){e=f.throw(t)},"process_yield_error",t)}catch(t){return void setImmediate(function(){n(function(e){u(t)},"process_throw",t)})}l(e)}function l(t){if(!t.done)return t.value&&"function"==typeof t.value.then||i("Only promises can be yielded to `async`, got: "+t),t.value.then(p,c);setImmediate(function(){n(function(t){s(t)},"process_return",t.value)})}var f;T({name:t,type:"process_spawn",id:r,args:m(a),context:o.context,rootId:o.rootId},function(){f=e.apply(null,arguments),p(void 0,!1)})})}}function vt(t){var e=p({},t);return delete e.type,{name:t.type,args:[e]}}function bt(t,e,n){function r(t){var i=e.shift();i?i(r)(t):n(t)}r(t)}var gt,mt=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])},wt=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},Vt=Object.freeze([]),Pt=Object.freeze({}),jt=1,At=null;!function(t){t[t.String=1]="String",t[t.Number=2]="Number",t[t.Boolean=4]="Boolean",t[t.Date=8]="Date",t[t.Literal=16]="Literal",t[t.Array=32]="Array",t[t.Map=64]="Map",t[t.Object=128]="Object",t[t.Frozen=256]="Frozen",t[t.Optional=512]="Optional",t[t.Reference=1024]="Reference",t[t.Identifier=2048]="Identifier",t[t.Late=4096]="Late",t[t.Refinement=8192]="Refinement",t[t.Union=16384]="Union",t[t.Null=32768]="Null",t[t.Undefined=65536]="Undefined"}(gt||(gt={}));var St=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}(),Ct=1,Tt=function(){function t(t,n,r,i,s,u,p){void 0===u&&(u=o),void 0===p&&(p=a);var c=this;this.nodeId=++Ct,this._parent=null,this.subpath="",this.isProtectionEnabled=!0,this.identifierAttribute=void 0,this._environment=void 0,this._isRunningAction=!1,this._autoUnbox=!0,this._isAlive=!0,this._isDetaching=!1,this.middlewares=[],this.snapshotSubscribers=[],this.patchSubscribers=[],this.disposers=[],this.type=t,this._parent=n,this.subpath=r,this._environment=i,this.unbox=this.unbox.bind(this),this.storedValue=u(s);var l=X(this.storedValue);this.applyPatches=x(this.storedValue,"@APPLY_PATCHES",function(t){t.forEach(function(t){var e=S(t.path);c.resolvePath(e.slice(0,-1)).applyPatchLocally(e[e.length-1],t)})}).bind(this.storedValue),this.applySnapshot=x(this.storedValue,"@APPLY_SNAPSHOT",function(t){if(t!==c.snapshot)return c.type.applySnapshot(c,t)}).bind(this.storedValue),n||(this.identifierCache=new St),l&&v(this.storedValue,"$treenode",this);var f=!0;try{l&&v(this.storedValue,"toJSON",Z),this._isRunningAction=!0,p(this,s),this._isRunningAction=!1,n?n.root.identifierCache.addNodeToCache(this):this.identifierCache.addNodeToCache(this),this.fireHook("afterCreate"),n&&this.fireHook("afterAttach"),f=!1}finally{f&&(this._isAlive=!1)}var h=e.reaction(function(){return c.snapshot},function(t){c.emitSnapshot(t)});h.onError(function(t){throw t}),this.addDisposer(h)}return Object.defineProperty(t.prototype,"identifier",{get:function(){return this.identifierAttribute?this.storedValue[this.identifierAttribute]:null},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"path",{get:function(){return this.parent?this.parent.path+"/"+P(this.subpath):""},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isRoot",{get:function(){return null===this.parent},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"parent",{get:function(){return this._parent},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"root",{get:function(){for(var t,e=this;t=e.parent;)e=t;return e},enumerable:!0,configurable:!0}),t.prototype.getRelativePathTo=function(t){this.root!==t.root&&i("Cannot calculate relative path: objects '"+this+"' and '"+t+"' are not part of the same object tree");for(var e=S(this.path),n=S(t.path),r=0;r<e.length&&e[r]===n[r];r++);return e.slice(r).map(function(t){return".."}).join("/")+A(n.slice(r))},t.prototype.resolve=function(t,e){return void 0===e&&(e=!0),this.resolvePath(S(t),e)},t.prototype.resolvePath=function(t,e){void 0===e&&(e=!0);for(var n=this,r=0;r<t.length;r++){if(""===t[r])n=n.root;else if(".."===t[r])n=n.parent;else{if("."===t[r]||""===t[r])continue;if(n){n=n.getChildNode(t[r]);continue}}if(!n)return e?i("Could not resolve '"+t[r]+"' in '"+A(t.slice(0,r-1))+"', path of the patch does not resolve"):void 0}return n},Object.defineProperty(t.prototype,"value",{get:function(){if(this._isAlive)return this.type.getValue(this)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"isAlive",{get:function(){return this._isAlive},enumerable:!0,configurable:!0}),t.prototype.die=function(){this._isDetaching||K(this.storedValue)&&(G(this.storedValue,function(t){return Q(t).aboutToDie()}),G(this.storedValue,function(t){return Q(t).finalizeDeath()}))},t.prototype.aboutToDie=function(){this.disposers.splice(0).forEach(function(t){return t()}),this.fireHook("beforeDestroy")},t.prototype.finalizeDeath=function(){this.root.identifierCache.notifyDied(this);var t=this,e=this.path;b(this,"snapshot",this.snapshot),this.patchSubscribers.splice(0),this.snapshotSubscribers.splice(0),this.patchSubscribers.splice(0),this._isAlive=!1,this._parent=null,this.subpath="",Object.defineProperty(this.storedValue,"$mobx",{get:function(){i("This object has died and is no longer part of a state tree. It cannot be used anymore. The object (of type '"+t.type.name+"') used to live at '"+e+"'. It is possible to access the last snapshot of this object using 'getSnapshot', or to create a fresh copy using 'clone'. If you want to remove an object from the tree without killing it, use 'detach' instead.")}})},t.prototype.assertAlive=function(){this._isAlive||i(this+" cannot be used anymore as it has died; it has been removed from a state tree. If you want to remove an element from a tree and let it live on, use 'detach' or 'clone' the value")},Object.defineProperty(t.prototype,"snapshot",{get:function(){if(this._isAlive)return h(this.type.getSnapshot(this))},enumerable:!0,configurable:!0}),t.prototype.onSnapshot=function(t){return g(this.snapshotSubscribers,t)},t.prototype.emitSnapshot=function(t){this.snapshotSubscribers.forEach(function(e){return e(t)})},t.prototype.applyPatchLocally=function(t,e){this.assertWritable(),this.type.applyPatchLocally(this,t,e)},t.prototype.onPatch=function(t,e){return g(this.patchSubscribers,e?t:function(e){return t(V(e))})},t.prototype.emitPatch=function(t,e){if(this.patchSubscribers.length){var n=p({},t,{path:e.path.substr(this.path.length)+"/"+t.path});this.patchSubscribers.forEach(function(t){return t(n)})}this.parent&&this.parent.emitPatch(t,e)},t.prototype.setParent=function(t,e){void 0===e&&(e=null),this.parent===t&&this.subpath===e||(this._parent&&t&&t!==this._parent&&i("A node cannot exists twice in the state tree. Failed to add "+this+" to path '"+t.path+"/"+e+"'."),!this._parent&&t&&t.root===this&&i("A state tree is not allowed to contain itself. Cannot assign "+this+" to path '"+t.path+"/"+e+"'"),!this._parent&&this._environment&&i("A state tree that has been initialized with an environment cannot be made part of another state tree."),this.parent&&!t?this.die():(this.subpath=e||"",t&&t!==this._parent&&(t.root.identifierCache.mergeCache(this),this._parent=t,this.fireHook("afterAttach"))))},t.prototype.addDisposer=function(t){this.disposers.unshift(t)},t.prototype.isRunningAction=function(){return!!this._isRunningAction||!this.isRoot&&this.parent.isRunningAction()},t.prototype.addMiddleWare=function(t){return g(this.middlewares,t)},t.prototype.getChildNode=function(t){this.assertAlive(),this._autoUnbox=!1;var e=this.type.getChildNode(this,t);return this._autoUnbox=!0,e},t.prototype.getChildren=function(){this.assertAlive(),this._autoUnbox=!1;var t=this.type.getChildren(this);return this._autoUnbox=!0,t},t.prototype.getChildType=function(t){return this.type.getChildType(t)},Object.defineProperty(t.prototype,"isProtected",{get:function(){return this.root.isProtectionEnabled},enumerable:!0,configurable:!0}),t.prototype.assertWritable=function(){this.assertAlive(),!this.isRunningAction()&&this.isProtected&&i("Cannot modify '"+this+"', the object is protected and can only be modified by using an action.")},t.prototype.removeChild=function(t){this.type.removeChild(this,t)},t.prototype.detach=function(){this._isAlive||i("Error while detaching, node is not alive."),this.isRoot||(this.fireHook("beforeDetach"),this._environment=this.root._environment,this._isDetaching=!0,this.identifierCache=this.root.identifierCache.splitCache(this),this.parent.removeChild(this.subpath),this._parent=null,this.subpath="",this._isDetaching=!1)},t.prototype.unbox=function(t){return t&&!0===this._autoUnbox?t.value:t},t.prototype.fireHook=function(t){var e=this.storedValue&&"object"==typeof this.storedValue&&this.storedValue[t];"function"==typeof e&&e.apply(this.storedValue)},t.prototype.toString=function(){var t=this.identifier?"(id: "+this.identifier+")":"";return this.type.name+"@"+(this.path||"<root>")+t+(this.isAlive?"":"[dead]")},r([e.observable],t.prototype,"_parent",void 0),r([e.observable],t.prototype,"subpath",void 0),r([e.computed],t.prototype,"path",null),r([e.computed],t.prototype,"value",null),r([e.computed],t.prototype,"snapshot",null),t}(),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()),this.instantiate(null,"",e,t).value},t.prototype.isAssignableFrom=function(t){return t===this},t.prototype.validate=function(t,e){return K(t)?F(t)===this||this.isAssignableFrom(F(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){if(t.snapshot===e)return t;if(K(e)&&Q(e)===t)return t;if(t.type===this&&l(e)&&!K(e)&&(!t.identifierAttribute||t.identifier===e[t.identifierAttribute]))return t.applySnapshot(e),t;var n=t.parent,r=t.subpath;if(t.die(),K(e)&&this.isAssignableFrom(F(e))){var i=Q(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}(),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){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 Vt},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}(Ot),_t=function(t){function o(n,r){var i=t.call(this,n)||this;return i.shouldAttachNode=!0,i.flags=gt.Map,i.createNewInstance=function(){var t=e.observable.shallowMap();return v(t,"put",at),v(t,"toString",ot),t},i.finalizeNewInstance=function(t,n){var r=t.storedValue;e.extras.interceptReads(r,t.unbox),e.intercept(r,function(t){return i.willChange(t)}),t.applySnapshot(n),e.observe(r,i.didChange)},i.subType=r,i}return n(o,t),o.prototype.instantiate=function(t,e,n,r){return tt(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=Q(t.object);switch(e.assertWritable(),t.type){case"update":var n=t.newValue;if(n===t.object.get(t.name))return null;this.subType,t.newValue=this.subType.reconcile(e.getChildNode(t.name),t.newValue),this.verifyIdentifier(t.name,t.newValue);break;case"add":this.subType,t.newValue,t.newValue=this.subType.instantiate(e,t.name,void 0,t.newValue),this.verifyIdentifier(t.name,t.newValue);break;case"delete":e.storedValue.has(t.name)&&e.getChildNode(t.name).die()}return t},o.prototype.verifyIdentifier=function(t,e){var n=e.identifier;null!==n&&""+n!=""+t&&i("A map of objects containing an identifier should always store the object under their own identifier. Trying to store key '"+n+"', but expected: '"+t+"'")},o.prototype.getValue=function(t){return t.storedValue},o.prototype.getSnapshot=function(t){var e={};return t.getChildren().forEach(function(t){e[t.subpath]=t.snapshot}),e},o.prototype.didChange=function(t){var e=Q(t.object);switch(t.type){case"update":return void e.emitPatch({op:"replace",path:P(t.name),value:t.newValue.snapshot,oldValue:t.oldValue?t.oldValue.snapshot:void 0},e);case"add":return void e.emitPatch({op:"add",path:P(t.name),value:t.newValue.snapshot,oldValue:void 0},e);case"delete":return void e.emitPatch({op:"remove",path:P(t.name),oldValue:t.oldValue.snapshot},e)}},o.prototype.applyPatchLocally=function(t,e,n){var r=t.storedValue;switch(n.op){case"add":case"replace":r.set(e,n.value);break;case"remove":r.delete(e)}},o.prototype.applySnapshot=function(t,e){var n=t.storedValue,r={};n.keys().forEach(function(t){r[t]=!1}),Object.keys(e).forEach(function(t){n.set(t,e[t]),r[t]=!0}),Object.keys(r).forEach(function(t){!1===r[t]&&n.delete(t)})},o.prototype.getChildType=function(t){return this.subType},o.prototype.isValidSnapshot=function(t,e){var n=this;return c(t)?it(Object.keys(t).map(function(r){return n.subType.validate(t[r],et(e,r,n.subType))})):rt(e,t,"Value is not a plain object")},o.prototype.getDefaultSnapshot=function(){return{}},o.prototype.removeChild=function(t,e){t.storedValue.delete(e)},r([e.action],o.prototype,"applySnapshot",null),o}(Ot),Nt=function(t){function o(n,r){var i=t.call(this,n)||this;return i.shouldAttachNode=!0,i.flags=gt.Array,i.createNewInstance=function(){var t=e.observable.shallowArray();return v(t,"toString",st),t},i.finalizeNewInstance=function(t,n){var r=t.storedValue;e.extras.getAdministration(r).dehancer=t.unbox,e.intercept(r,function(t){return i.willChange(t)}),t.applySnapshot(n),e.observe(r,i.didChange)},i.subType=r,i}return n(o,t),o.prototype.describe=function(){return this.subType.describe()+"[]"},o.prototype.instantiate=function(t,e,n,r){return tt(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=this,n=Q(t.object);n.assertWritable();var r=n.getChildren();switch(t.type){case"update":if(this.subType,t.newValue,t.newValue===t.object[t.index])return null;t.newValue=ut(n,this.subType,[r[t.index]],[t.newValue],[t.index])[0];break;case"splice":var i=t.index,o=t.removedCount,a=t.added;a.forEach(function(t){return void e.subType}),t.added=ut(n,this.subType,r.slice(i,i+o),a,a.map(function(t,e){return i+e}));for(var s=i+o;s<r.length;s++)r[s].setParent(n,""+(s+a.length-o))}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=Q(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){t.storedValue.replace(e)},o.prototype.getChildType=function(t){return this.subType},o.prototype.isValidSnapshot=function(t,e){var n=this;return s(t)?it(t.map(function(t,r){return n.subType.validate(t,et(e,""+r,n.subType))})):rt(e,t,"Value is not an array")},o.prototype.getDefaultSnapshot=function(){return[]},o.prototype.removeChild=function(t,e){t.storedValue.splice(parseInt(e,10),1)},r([e.action],o.prototype,"applySnapshot",null),o}(Ot),It=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 tt(this,t,e,n,r,this.initializer)},e.prototype.isValidSnapshot=function(t,e){return f(t)&&this.checker(t)?nt():rt(e,t,"Value is not a "+("Date"===this.name?"Date or a unix milliseconds timestamp":this.name))},e}(xt),Dt=new It("string",gt.String,function(t){return"string"==typeof t}),Et=new It("number",gt.Number,function(t){return"number"==typeof t}),Rt=new It("boolean",gt.Boolean,function(t){return"boolean"==typeof t}),zt=new It("null",gt.Null,function(t){return null===t}),kt=new It("undefined",gt.Undefined,function(t){return void 0===t}),Ft=new It("Date",gt.Date,function(t){return"number"==typeof t||t instanceof Date},function(t){return t instanceof Date?t:new Date(t)});Ft.getSnapshot=function(t){return t.storedValue.getTime()};var Lt=function(t){function e(e){var n=t.call(this,"identifier("+e.name+")")||this;return n.identifierType=e,n.flags=gt.Identifier,n}return n(e,t),e.prototype.instantiate=function(t,e,n,r){return t&&K(t.storedValue)?(t.identifierAttribute&&i("Cannot define property '"+e+"' as object identifier, property '"+t.identifierAttribute+"' is already defined as identifier property"),t.identifierAttribute=e,tt(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):rt(e,t,"Value is not a valid identifier, which is a string or a number")},e}(xt),Mt=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|gt.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=K(i)?Q(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 this.defaultValue,t},e.prototype.isValidSnapshot=function(t,e){return void 0===t?nt():this.type.validate(t,e)},e.prototype.isAssignableFrom=function(t){return this.type.isAssignableFrom(t)},e}(xt),Ut={afterCreate:"afterCreate",afterAttach:"afterAttach",postProcessSnapshot:"postProcessSnapshot",beforeDetach:"beforeDetach",beforeDestroy:"beforeDestroy"},Ht={name:"AnonymousModel",properties:{},initializers:Vt},$t=function(t){function o(n){var r=t.call(this,n.name||Ht.name)||this;r.flags=gt.Object,r.createNewInstance=function(){var t=e.observable.shallowObject(Pt);return v(t,"toString",lt),t},r.finalizeNewInstance=function(t,n){var i=t.storedValue;r.forAllProps(function(r,o){e.extendShallowObservable(i,(a={},a[r]=e.observable.ref(o.instantiate(t,r,t._environment,n[r])),a)),e.extras.interceptReads(t.storedValue,r,t.unbox);var a}),r.initializers.reduce(function(t,e){return e(t)},i),e.intercept(i,function(t){return r.willChange(t)}),e.observe(i,r.didChange)},r.didChange=function(t){var e=Q(t.object);e.emitPatch({op:"replace",path:P(t.name),value:t.newValue.snapshot,oldValue:t.oldValue?t.oldValue.snapshot:void 0},e)};var o=n.name||Ht.name;return/^\w[\w\d_]*$/.test(o)||i("Typename should be a valid identifier: "+o),Object.assign(r,Ht,n),r.properties=ft(r.properties),r.propertiesNames=Object.keys(r.properties),Object.freeze(r.properties),r}return n(o,t),o.prototype.extend=function(t){return new o({name:t.name||this.name,properties:Object.assign({},this.properties,t.properties),initializers:this.initializers.concat(t.initializers||[]),preProcessor:t.preProcessor||this.preProcessor})},o.prototype.actions=function(t){return this.extend({initializers:[function(e){var n=t(e);return c(n)||i("actions initializer should return a plain object containing actions"),Object.keys(n).forEach(function(t){if("preProcessSnapshot"===t)return i("Cannot define action 'preProcessSnapshot', it should be defined using 'type.preProcessSnapshot(fn)' instead");var r=n[t],o=e[t];if(t in Ut&&o){var a=r;r=t===Ut.postProcessSnapshot?function(t){return a(o(t))}:function(){o.apply(null,arguments),a.apply(null,arguments)}}v(e,t,x(e,t,r))}),e}]})},o.prototype.named=function(t){return this.extend({name:t})},o.prototype.props=function(t){return this.extend({properties:t})},o.prototype.views=function(t){return this.extend({initializers:[function(n){var r=t(n);return c(r)||i("views initializer should return a plain object containing views"),Object.keys(r).forEach(function(t){var o=Object.getOwnPropertyDescriptor(r,t),a=o.value;if("get"in o)if(e.isComputed(n.$mobx.values[t]))n.$mobx.values[t]=e.computed(o.get,{name:t,setter:o.set,context:n});else{var s={};Object.defineProperty(s,t,{get:o.get,set:o.set,enumerable:!0}),e.extendShallowObservable(n,s)}else"function"==typeof a?v(n,t,a):i("A view member should either be a function or getter based property")}),n}]})},o.prototype.preProcessSnapshot=function(t){var e=this.preProcessor;return e?this.extend({preProcessor:function(n){return e(t(n))}}):this.extend({preProcessor:t})},o.prototype.instantiate=function(t,e,n,r){return tt(this,t,e,n,this.applySnapshotPreProcessor(r),this.createNewInstance,this.finalizeNewInstance)},o.prototype.willChange=function(t){var e=Q(t.object),n=this.properties[t.name];return e.assertWritable(),t.newValue,t.newValue=n.reconcile(e.getChildNode(t.name),t.newValue),t},o.prototype.getChildren=function(t){var e=this,n=[];return this.forAllProps(function(r,i){n.push(e.getChildNode(t,r))}),n},o.prototype.getChildNode=function(t,e){if(!(e in this.properties))return i("Not a value property: "+e);var n=t.storedValue.$mobx.values[e].value;return n||i("Node not available for property "+e)},o.prototype.getValue=function(t){return t.storedValue},o.prototype.getSnapshot=function(t){var n=this,r={};return this.forAllProps(function(i,o){e.extras.getAtom(t.storedValue,i).reportObserved(),r[i]=n.getChildNode(t,i).snapshot}),"function"==typeof t.storedValue.postProcessSnapshot?t.storedValue.postProcessSnapshot.call(null,r):r},o.prototype.applyPatchLocally=function(t,e,n){"replace"!==n.op&&"add"!==n.op&&i("object does not support operation "+n.op),t.storedValue[e]=n.value},o.prototype.applySnapshot=function(t,e){var n=this.applySnapshotPreProcessor(e);this.forAllProps(function(e,r){t.storedValue[e]=n[e]})},o.prototype.applySnapshotPreProcessor=function(t){return this.preProcessor?this.preProcessor.call(null,t):t},o.prototype.getChildType=function(t){return this.properties[t]},o.prototype.isValidSnapshot=function(t,e){var n=this,r=this.applySnapshotPreProcessor(t);return c(r)?it(this.propertiesNames.map(function(t){return n.properties[t].validate(r[t],et(e,t,n.properties[t]))})):rt(e,r,"Value is not a plain object")},o.prototype.forAllProps=function(t){var e=this;this.propertiesNames.forEach(function(n){return t(n,e.properties[n])})},o.prototype.describe=function(){var t=this;return"{ "+this.propertiesNames.map(function(e){return e+": "+t.properties[e].describe()}).join("; ")+" }"},o.prototype.getDefaultSnapshot=function(){return{}},o.prototype.removeChild=function(t,e){t.storedValue[e]=null},r([e.action],o.prototype,"applySnapshot",null),o}(Ot),Jt=function(){return function(t,e){if(this.mode=t,this.value=e,"object"===t){if(!K(e))return i("Can only store references to tree nodes, got: '"+e+"'");if(!Q(e).identifierAttribute)return i("Can only store references with a defined identifier attribute.")}}}(),Wt=function(t){function e(e){var n=t.call(this,"reference("+e.name+")")||this;return n.targetType=e,n.flags=gt.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 Q(e.value).identifier}},e.prototype.instantiate=function(t,e,n,r){var i=K(r);return tt(this,t,e,n,new Jt(i?"object":"identifier",r))},e.prototype.reconcile=function(t,e){var n=K(e)?"object":"identifier";if(k(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 is not a valid identifier, which is a string or a number")},e}(xt),Yt=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=gt.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?rt(e,t,"Multiple types are applicable for the union (hint: provide a dispatch function)"):0===r.length?rt(e,t,"No type is applicable for the union").concat(it(n)):nt()},e}(xt),Bt=function(t){function e(e){var n=t.call(this,JSON.stringify(e))||this;return n.flags=gt.Literal,n.value=e,n}return n(e,t),e.prototype.instantiate=function(t,e,n,r){return tt(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?nt():rt(e,t,"Value is not a literal "+JSON.stringify(this.value))},e}(xt),qt=new(function(t){function e(){var e=t.call(this,"frozen")||this;return e.flags=gt.Frozen,e}return n(e,t),e.prototype.describe=function(){return"<any immutable value>"},e.prototype.instantiate=function(t,e,n,r){return tt(this,t,e,n,d(r))},e.prototype.isValidSnapshot=function(t,e){return y(t)?nt():rt(e,t,"Value is not serializable and cannot be frozen")},e}(xt)),Gt=ct(zt,null),Kt=function(t){function e(e,n,r,i){var o=t.call(this,e)||this;return o.type=n,o.predicate=r,o.message=i,o}return n(e,t),Object.defineProperty(e.prototype,"flags",{get:function(){return this.type.flags|gt.Refinement},enumerable:!0,configurable:!0}),e.prototype.describe=function(){return this.name},e.prototype.instantiate=function(t,e,n,r){return this.type.instantiate(t,e,n,r)},e.prototype.isAssignableFrom=function(t){return this.type.isAssignableFrom(t)},e.prototype.isValidSnapshot=function(t,e){var n=this.type.validate(t,e);if(n.length>0)return n;var r=K(t)?Q(t).snapshot:t;return this.predicate(r)?nt():rt(e,t,this.message(t))},e}(xt),Qt=function(t){function e(e,n){var r=t.call(this,e)||this;return r._subType=null,r.definition=n,r}return n(e,t),Object.defineProperty(e.prototype,"flags",{get:function(){return this.subType.flags|gt.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),Xt={enumeration:function(t,e){var n="string"==typeof t?e:t,r=ht.apply(void 0,n.map(function(t){return dt(""+t)}));return"string"==typeof t&&(r.name=t),r},model:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n="string"==typeof t[0]?t.shift():"AnonymousModel",r=t.shift()||{};return new $t({name:n,properties:r})},compose:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n="string"==typeof t[0]?t.shift():"AnonymousModel";return t.reduce(function(t,e){return t.extend({name:t.name+"_"+e.name,properties:e.properties,initializers:e.initializers})}).named(n)},reference:function(t){return new Wt(t)},union:ht,optional:ct,literal:dt,maybe:function(t){return ht(Gt,t)},refinement:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n="string"==typeof t[0]?t.shift():z(t[0])?t[0].name:null,r=t[0],i=t[1],o=t[2]?t[2]:function(t){return"Value does not respect the refinement predicate"};return new Kt(n,r,i,o)},string:Dt,boolean:Rt,number:Et,Date:Ft,map:function(t){return new _t("map<string, "+t.name+">",t)},array:function(t){return new Nt(t.name+"[]",t)},frozen:qt,identifier:function(t){return void 0===t&&(t=Dt),new Lt(t)},late:function(t,e){var n="string"==typeof t?t:"late("+t.toString()+")";return new Qt(n,"string"==typeof t?e:t)},undefined:kt,null:zt};t.types=Xt,t.escapeJsonPath=P,t.unescapeJsonPath=j,t.onAction=R,t.process=function(t){return yt(t.name,t)},t.isStateTreeNode=K,t.asReduxStore=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];K(t)||i("Expected model object");var r={getState:function(){return Y(t)},dispatch:function(e){bt(e,o.slice(),function(e){return E(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,W(e,i),r=!1)}),R(e,function(t){if(!r){var i={};i.type=t.name,t.args&&t.args.forEach(function(t,e){return i[e]=t}),n.send(i,Y(e))}})},t.getType=F,t.getChildType=function(t,e){return Q(t).getChildType(e)},t.addMiddleware=L,t.onPatch=M,t.onSnapshot=U,t.applyPatch=H,t.revertPatch=$,t.recordPatches=function(t){var e={patches:[],get cleanPatches(){return this.patches.map(V)},stop:function(){n()},replay:function(n){H(n||t,e.patches)},undo:function(e){$(t||t,this.patches)}},n=M(t,function(t){e.patches.push(t)},!0);return e},t.applyAction=J,t.recordActions=function(t){var e={actions:[],stop:function(){return n()},replay:function(t){J(t,e.actions)}},n=R(t,e.actions.push.bind(e.actions));return e},t.protect=function(t){var e=Q(t);e.isRoot||i("`protect` can only be invoked on root nodes"),e.isProtectionEnabled=!0},t.unprotect=function(t){var e=Q(t);e.isRoot||i("`unprotect` can only be invoked on root nodes"),e.isProtectionEnabled=!1},t.isProtected=function(t){return Q(t).isProtected},t.applySnapshot=W,t.getSnapshot=Y,t.hasParent=function(t,e){void 0===e&&(e=1);for(var n=Q(t).parent;n;){if(0==--e)return!0;n=n.parent}return!1},t.getParent=function(t,e){void 0===e&&(e=1);for(var n=e,r=Q(t).parent;r;){if(0==--n)return r.storedValue;r=r.parent}return i("Failed to find the parent of "+Q(t)+" at depth "+e)},t.getRoot=function(t){return Q(t).root.storedValue},t.getPath=function(t){return Q(t).path},t.getPathParts=function(t){return S(Q(t).path)},t.isRoot=function(t){return Q(t).isRoot},t.resolvePath=B,t.resolveIdentifier=function(t,e,n){var r=Q(e).root.identifierCache.resolve(t,""+n);return r?r.value:void 0},t.tryResolve=q,t.getRelativePath=function(t,e){return Q(t).getRelativePathTo(Q(e))},t.clone=function(t,e){void 0===e&&(e=!0);var n=Q(t);return n.type.create(n.snapshot,!0===e?n.root._environment:!1===e?void 0:e)},t.detach=function(t){return Q(t).detach(),t},t.destroy=function(t){var e=Q(t);e.isRoot?e.die():e.parent.removeChild(e.subpath)},t.isAlive=function(t){return Q(t).isAlive},t.addDisposer=function(t,e){Q(t).addDisposer(e)},t.getEnv=function(t){var e=Q(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=G,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}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){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]:At}function p(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];for(var r=0;r<e.length;r++){var i=e[r];for(var o in i)t[o]=i[o]}return t}function c(t){if(null===t||"object"!=typeof t)return!1;var e=Object.getPrototypeOf(t);return e===Object.prototype||null===e}function l(t){return!(null===t||"object"!=typeof t||t instanceof Date||t instanceof RegExp)}function f(t){return null===t||void 0===t||("string"==typeof t||"number"==typeof t||"boolean"==typeof t||t instanceof Date)}function h(t){return f(t)?t:Object.freeze(t)}function d(t){return h(t),c(t)&&Object.keys(t).forEach(function(e){f(t[e])||Object.isFrozen(t[e])||d(t[e])}),t}function y(t){return"function"!=typeof t}function v(t,e,n){Object.defineProperty(t,e,{enumerable:!1,writable:!1,configurable:!0,value:n})}function b(t,e,n){Object.defineProperty(t,e,{enumerable:!0,writable:!1,configurable:!0,value:n})}function m(t,e){var n=t.indexOf(e);-1!==n&&t.splice(n,1)}function g(t,e){return t.push(e),function(){m(t,e)}}function w(t){for(var e=new Array(t.length),n=0;n<t.length;n++)e[n]=t[n];return e}function V(t){return"oldValue"in t||i("Patches without `oldValue` field cannot be inversed"),[P(t),A(t)]}function P(t){switch(t.op){case"add":return{op:"add",path:t.path,value:t.value};case"remove":return{op:"remove",path:t.path};case"replace":return{op:"replace",path:t.path,value:t.value}}}function A(t){switch(t.op){case"add":return{op:"remove",path:t.path};case"remove":return{op:"add",path:t.path,value:t.oldValue};case"replace":return{op:"replace",path:t.path,value:t.oldValue}}}function S(t){return t.replace(/~/g,"~1").replace(/\//g,"~0")}function j(t){return t.replace(/~0/g,"\\").replace(/~1/g,"~")}function T(t){return 0===t.length?"":"/"+t.map(S).join("/")}function C(t){var e=t.split("/").map(j);return""===e[0]?e.slice(1):e}function _(t){return"object"==typeof t&&t&&!0===t.isType}function O(t){return(t.flags&Vt.Reference)>0}function x(t){return Y(t).type}function N(t,e){return Y(t).onPatch(e)}function I(t,e){return Y(t).onSnapshot(e)}function D(t,e){Y(t).applyPatches(u(e))}function R(t,e){return Y(t).applySnapshot(e)}function E(t){return Y(t).snapshot}function z(t){return Y(t).root.storedValue}function k(t,e){var n=Y(t).resolve(e,!1);if(void 0!==n)return n?n.value:void 0}function F(t,e){var n=Y(t);n.getChildren().forEach(function(t){B(t.storedValue)&&F(t.storedValue,e)}),e(n.storedValue)}function M(){return jt++}function $(t,e){var n=Y(t.context),r=n._isRunningAction,i=Tt;n.assertAlive(),n._isRunningAction=!0,Tt=t;try{return W(n,t,e)}finally{Tt=i,n._isRunningAction=r}}function L(){return Tt||i("Not running an action!")}function U(t,n,r){var i=e.action(n,r);return i.$mst_middleware=r.$mst_middleware,function(){var e=M();return $({type:"action",name:n,id:e,args:w(arguments),context:t,tree:z(t),rootId:Tt?Tt.rootId:e,parentId:Tt?Tt.id:0},i)}}function H(t,e){return Y(t).addMiddleWare(e)}function J(t,e,n){for(var r=n.$mst_middleware||[],i=t;i;)r=r.concat(i.middlewares),i=i.parent;return r}function W(t,e,n){function r(t){var o=i.shift();return o?o(t,r):n.apply(null,e.args)}var i=J(t,e,n);return i.length?r(e):n.apply(null,e.args)}function B(t){return!(!t||!t.$treenode)}function Y(t){return B(t)?t.$treenode:i("Value "+t+" is no MST Node")}function q(t){return t&&"object"==typeof t&&!(t instanceof Date)&&!B(t)&&!Object.isFrozen(t)}function G(){return Y(this).snapshot}function Z(t,e,n,r,s,u,p){if(void 0===u&&(u=o),void 0===p&&(p=a),B(s)){var c=Y(s);return c.isRoot||i("Cannot add an object to a state tree if it is already part of the same or another state tree. Tried to assign an object to '"+(e?e.path:"")+"/"+n+"', but it lives already at '"+c.path+"'"),c.setParent(e,n),c}return new Ot(t,e,n,r,s,u,p)}function K(t,e,n){return t.concat([{path:e,type:n}])}function Q(){return At}function X(t,e,n){return[{context:t,value:e,message:n}]}function tt(t){return t.reduce(function(t,e){return t.concat(e)},[])}function et(t,e){return}function nt(){return Y(this)+"("+this.size+" items)"}function rt(t){t||i("Map.put cannot be used to set empty values");var e;if(B(t))e=Y(t);else{if(!l(t))return i("Map.put can only be used to store complex values");e=Y(Y(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 it(){return Y(this)+"("+this.length+" items)"}function ot(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){n instanceof Ot&&(n=n.storedValue),et(e,n);var p=""+o[r];if(B(n))(f=Y(n)).assertAlive(),f.parent===t?(u[f.nodeId]||i("Cannot add an object to a state tree if it is already part of the same or another state tree. Tried to assign an object to '"+t.path+"/"+p+"', but it lives already at '"+f.path+"'"),u[f.nodeId]=void 0,f.setParent(t,p),s[r]=f):s[r]=e.instantiate(t,p,void 0,n);else if(l(n)){var c=a(n);if(c){var f=e.reconcile(c,n);u[c.nodeId]=void 0,f.setParent(t,p),s[r]=f}else s[r]=e.instantiate(t,p,void 0,n)}else s[r]=e.instantiate(t,p,void 0,n)});for(var c in u)void 0!==u[c]&&u[c].die();return s}function at(t){switch(typeof t){case"string":return Et;case"number":return zt;case"boolean":return kt;case"object":if(t instanceof Date)return $t}return i("Cannot determine primtive type from value "+t)}function st(t,e){return new Ut(t,e)}function ut(){return Y(this).toString()}function pt(t){return Object.keys(t).reduce(function(t,e){if(e in Ht)return i("Hook '"+e+"' was defined as property. Hooks should be defined as part of the actions");var n=Object.getOwnPropertyDescriptor(t,e);"get"in n&&i("Getters are not supported as properties. Please use views instead");var r=n.value;if(null===r)i("The default value of an attribute cannot be null or undefined as the type cannot be inferred. Did you mean `types.maybe(someType)`?");else{if(f(r))return Object.assign({},t,(o={},o[e]=st(at(r),r),o));if(_(r))return t;i("function"==typeof r?"Functions are not supported as properties, use views instead":"object"==typeof r?"In property '"+e+"': base model's should not contain complex values: '"+r+"'":"Unexpected value for property '"+e+"'")}var o},t)}function ct(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var r=_(t)?null:t,i=_(t)?e.concat(t):e,o="("+i.map(function(t){return t.name}).join(" | ")+")";return new qt(o,i,r)}function lt(t){return new Gt(t)}function ft(t,e){var n=function(){function r(e,r,i){e.$mst_middleware=n.$mst_middleware,$({name:t,type:r,id:o,args:[i],tree:a.tree,context:a.context,parentId:a.id,rootId:a.rootId},e)}var o=M(),a=L(),s=arguments;return new Promise(function(u,p){function c(t){var e;try{r(function(t){e=h.next(t)},"process_resume",t)}catch(t){return void setImmediate(function(){r(function(e){p(t)},"process_throw",t)})}f(e)}function l(t){var e;try{r(function(t){e=h.throw(t)},"process_resume_error",t)}catch(t){return void setImmediate(function(){r(function(e){p(t)},"process_throw",t)})}f(e)}function f(t){if(!t.done)return t.value&&"function"==typeof t.value.then||i("Only promises can be yielded to `async`, got: "+t),t.value.then(c,l);setImmediate(function(){r(function(t){u(t)},"process_return",t.value)})}var h,d=function(){h=e.apply(null,arguments),c(void 0)};d.$mst_middleware=n.$mst_middleware,$({name:t,type:"process_spawn",id:o,args:w(s),tree:a.tree,context:a.context,parentId:a.id,rootId:a.rootId},d)})};return n}function ht(t,e,n,r){if(r instanceof Date)return{$MST_DATE:r.getTime()};if(f(r))return r;if(B(r))return yt("[MSTNode: "+x(r).name+"]");if("function"==typeof r)return yt("[function]");if("object"==typeof r&&!c(r)&&!s(r))return yt("[object "+(r&&r.constructor&&r.constructor.name||"Complex Object")+"]");try{return JSON.stringify(r),r}catch(t){return yt(""+t)}}function dt(t,e){return e&&"object"==typeof e&&"$MST_DATE"in e?new Date(e.$MST_DATE):e}function yt(t){return{$MST_UNSERIALIZABLE:!0,type:t}}function vt(t,n){e.runInAction(function(){u(n).forEach(function(e){return bt(t,e)})})}function bt(t,e){var n=k(t,e.path||"");if(!n)return i("Invalid action path: "+(e.path||""));var r=Y(n);return"@APPLY_PATCHES"===e.name?D.call(null,n,e.args[0]):"@APPLY_SNAPSHOT"===e.name?R.call(null,n,e.args[0]):("function"!=typeof n[e.name]&&i("Action '"+e.name+"' does not exist in '"+r.path+"'"),n[e.name].apply(n,e.args?e.args.map(function(t){return dt(r,t)}):[]))}function mt(t,e,n){function r(n){if("action"===n.type&&n.id===n.rootId){var r=Y(n.context);e({name:n.name,path:Y(t).getRelativePathTo(r),args:n.args.map(function(t,e){return ht(r,n.name,e,t)})})}}return void 0===n&&(n=!1),H(t,n?function(t,e){var n=e(t);return r(t),n}:function(t,e){return r(t),e(t)})}function gt(t){var e=p({},t);return delete e.type,{name:t.type,args:[e]}}function wt(t,e,n){function r(t){var i=e.shift();i?i(r)(t):n(t)}r(t)}var Vt,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])},At=Object.freeze([]),St=Object.freeze({});!function(t){t[t.String=1]="String",t[t.Number=2]="Number",t[t.Boolean=4]="Boolean",t[t.Date=8]="Date",t[t.Literal=16]="Literal",t[t.Array=32]="Array",t[t.Map=64]="Map",t[t.Object=128]="Object",t[t.Frozen=256]="Frozen",t[t.Optional=512]="Optional",t[t.Reference=1024]="Reference",t[t.Identifier=2048]="Identifier",t[t.Late=4096]="Late",t[t.Refinement=8192]="Refinement",t[t.Union=16384]="Union",t[t.Null=32768]="Null",t[t.Undefined=65536]="Undefined"}(Vt||(Vt={}));var jt=1,Tt=null,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)&&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}(),_t=1,Ot=function(){function t(t,n,r,i,s,u,p){void 0===u&&(u=o),void 0===p&&(p=a);var c=this;this.nodeId=++_t,this._parent=null,this.subpath="",this.isProtectionEnabled=!0,this.identifierAttribute=void 0,this._environment=void 0,this._isRunningAction=!1,this._autoUnbox=!0,this._isAlive=!0,this._isDetaching=!1,this.middlewares=[],this.snapshotSubscribers=[],this.patchSubscribers=[],this.disposers=[],this.type=t,this._parent=n,this.subpath=r,this._environment=i,this.unbox=this.unbox.bind(this),this.storedValue=u(s);var l=q(this.storedValue);this.applyPatches=U(this.storedValue,"@APPLY_PATCHES",function(t){t.forEach(function(t){var e=C(t.path);c.resolvePath(e.slice(0,-1)).applyPatchLocally(e[e.length-1],t)})}).bind(this.storedValue),this.applySnapshot=U(this.storedValue,"@APPLY_SNAPSHOT",function(t){if(t!==c.snapshot)return c.type.applySnapshot(c,t)}).bind(this.storedValue),n||(this.identifierCache=new Ct),l&&v(this.storedValue,"$treenode",this);var f=!0;try{l&&v(this.storedValue,"toJSON",G),this._isRunningAction=!0,p(this,s),this._isRunningAction=!1,n?n.root.identifierCache.addNodeToCache(this):this.identifierCache.addNodeToCache(this),this.fireHook("afterCreate"),n&&this.fireHook("afterAttach"),f=!1}finally{f&&(this._isAlive=!1)}var h=e.reaction(function(){return c.snapshot},function(t){c.emitSnapshot(t)});h.onError(function(t){throw t}),this.addDisposer(h)}return Object.defineProperty(t.prototype,"identifier",{get:function(){return this.identifierAttribute?this.storedValue[this.identifierAttribute]:null},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"path",{get:function(){return this.parent?this.parent.path+"/"+S(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=C(this.path),n=C(t.path),r=0;r<e.length&&e[r]===n[r];r++);return e.slice(r).map(function(t){return".."}).join("/")+T(n.slice(r))},t.prototype.resolve=function(t,e){return void 0===e&&(e=!0),this.resolvePath(C(t),e)},t.prototype.resolvePath=function(t,e){void 0===e&&(e=!0);for(var n=this,r=0;r<t.length;r++){if(""===t[r])n=n.root;else if(".."===t[r])n=n.parent;else{if("."===t[r]||""===t[r])continue;if(n){n=n.getChildNode(t[r]);continue}}if(!n)return e?i("Could not resolve '"+t[r]+"' in '"+T(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||B(this.storedValue)&&(F(this.storedValue,function(t){return Y(t).aboutToDie()}),F(this.storedValue,function(t){return Y(t).finalizeDeath()}))},t.prototype.aboutToDie=function(){this.disposers.splice(0).forEach(function(t){return t()}),this.fireHook("beforeDestroy")},t.prototype.finalizeDeath=function(){this.root.identifierCache.notifyDied(this);var t=this,e=this.path;b(this,"snapshot",this.snapshot),this.patchSubscribers.splice(0),this.snapshotSubscribers.splice(0),this.patchSubscribers.splice(0),this._isAlive=!1,this._parent=null,this.subpath="",Object.defineProperty(this.storedValue,"$mobx",{get:function(){i("This object has died and is no longer part of a state tree. It cannot be used anymore. The object (of type '"+t.type.name+"') used to live at '"+e+"'. It is possible to access the last snapshot of this object using 'getSnapshot', or to create a fresh copy using 'clone'. If you want to remove an object from the tree without killing it, use 'detach' instead.")}})},t.prototype.assertAlive=function(){this._isAlive||i(this+" cannot be used anymore as it has died; it has been removed from a state tree. If you want to remove an element from a tree and let it live on, use 'detach' or 'clone' the value")},Object.defineProperty(t.prototype,"snapshot",{get:function(){if(this._isAlive)return h(this.type.getSnapshot(this))},enumerable:!0,configurable:!0}),t.prototype.onSnapshot=function(t){return g(this.snapshotSubscribers,t)},t.prototype.emitSnapshot=function(t){this.snapshotSubscribers.forEach(function(e){return e(t)})},t.prototype.applyPatchLocally=function(t,e){this.assertWritable(),this.type.applyPatchLocally(this,t,e)},t.prototype.onPatch=function(t){return g(this.patchSubscribers,t)},t.prototype.emitPatch=function(t,e){if(this.patchSubscribers.length){var n=V(p({},t,{path:e.path.substr(this.path.length)+"/"+t.path})),r=n[0],i=n[1];this.patchSubscribers.forEach(function(t){return t(r,i)})}this.parent&&this.parent.emitPatch(t,e)},t.prototype.setParent=function(t,e){void 0===e&&(e=null),this.parent===t&&this.subpath===e||(this._parent&&t&&t!==this._parent&&i("A node cannot exists twice in the state tree. Failed to add "+this+" to path '"+t.path+"/"+e+"'."),!this._parent&&t&&t.root===this&&i("A state tree is not allowed to contain itself. Cannot assign "+this+" to path '"+t.path+"/"+e+"'"),!this._parent&&this._environment&&i("A state tree that has been initialized with an environment cannot be made part of another state tree."),this.parent&&!t?this.die():(this.subpath=e||"",t&&t!==this._parent&&(t.root.identifierCache.mergeCache(this),this._parent=t,this.fireHook("afterAttach"))))},t.prototype.addDisposer=function(t){this.disposers.unshift(t)},t.prototype.isRunningAction=function(){return!!this._isRunningAction||!this.isRoot&&this.parent.isRunningAction()},t.prototype.addMiddleWare=function(t){return g(this.middlewares,t)},t.prototype.getChildNode=function(t){this.assertAlive(),this._autoUnbox=!1;var e=this.type.getChildNode(this,t);return this._autoUnbox=!0,e},t.prototype.getChildren=function(){this.assertAlive(),this._autoUnbox=!1;var t=this.type.getChildren(this);return this._autoUnbox=!0,t},t.prototype.getChildType=function(t){return this.type.getChildType(t)},Object.defineProperty(t.prototype,"isProtected",{get:function(){return this.root.isProtectionEnabled},enumerable:!0,configurable:!0}),t.prototype.assertWritable=function(){this.assertAlive(),!this.isRunningAction()&&this.isProtected&&i("Cannot modify '"+this+"', the object is protected and can only be modified by using an action.")},t.prototype.removeChild=function(t){this.type.removeChild(this,t)},t.prototype.detach=function(){this._isAlive||i("Error while detaching, node is not alive."),this.isRoot||(this.fireHook("beforeDetach"),this._environment=this.root._environment,this._isDetaching=!0,this.identifierCache=this.root.identifierCache.splitCache(this),this.parent.removeChild(this.subpath),this._parent=null,this.subpath="",this._isDetaching=!1)},t.prototype.unbox=function(t){return t&&!0===this._autoUnbox?t.value:t},t.prototype.fireHook=function(t){var e=this.storedValue&&"object"==typeof this.storedValue&&this.storedValue[t];"function"==typeof e&&e.apply(this.storedValue)},t.prototype.toString=function(){var t=this.identifier?"(id: "+this.identifier+")":"";return this.type.name+"@"+(this.path||"<root>")+t+(this.isAlive?"":"[dead]")},r([e.observable],t.prototype,"_parent",void 0),r([e.observable],t.prototype,"subpath",void 0),r([e.computed],t.prototype,"path",null),r([e.computed],t.prototype,"value",null),r([e.computed],t.prototype,"snapshot",null),t}(),xt=function(){function t(t){this.isType=!0,this.name=t}return t.prototype.create=function(t,e){return void 0===t&&(t=this.getDefaultSnapshot()),et(this,t),this.instantiate(null,"",e,t).value},t.prototype.isAssignableFrom=function(t){return t===this},t.prototype.validate=function(t,e){return B(t)?x(t)===this||this.isAssignableFrom(x(t))?Q():X(e,t):this.isValidSnapshot(t,e)},t.prototype.is=function(t){return 0===this.validate(t,[{path:"",type:this}]).length},t.prototype.reconcile=function(t,e){if(t.snapshot===e)return t;if(B(e)&&Y(e)===t)return t;if(t.type===this&&l(e)&&!B(e)&&(!t.identifierAttribute||t.identifier===e[t.identifierAttribute]))return t.applySnapshot(e),t;var n=t.parent,r=t.subpath;if(t.die(),B(e)&&this.isAssignableFrom(x(e))){var i=Y(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}(),Nt=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 At},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}(xt),It=function(t){function o(n,r){var i=t.call(this,n)||this;return i.shouldAttachNode=!0,i.flags=Vt.Map,i.createNewInstance=function(){var t=e.observable.shallowMap();return v(t,"put",rt),v(t,"toString",nt),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 Z(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=Y(t.object);switch(e.assertWritable(),t.type){case"update":var n=t.newValue;if(n===t.object.get(t.name))return null;et(this.subType,n),t.newValue=this.subType.reconcile(e.getChildNode(t.name),t.newValue),this.verifyIdentifier(t.name,t.newValue);break;case"add":et(this.subType,t.newValue),t.newValue=this.subType.instantiate(e,t.name,void 0,t.newValue),this.verifyIdentifier(t.name,t.newValue);break;case"delete":e.storedValue.has(t.name)&&e.getChildNode(t.name).die()}return t},o.prototype.verifyIdentifier=function(t,e){var n=e.identifier;null!==n&&""+n!=""+t&&i("A map of objects containing an identifier should always store the object under their own identifier. Trying to store key '"+n+"', but expected: '"+t+"'")},o.prototype.getValue=function(t){return t.storedValue},o.prototype.getSnapshot=function(t){var e={};return t.getChildren().forEach(function(t){e[t.subpath]=t.snapshot}),e},o.prototype.didChange=function(t){var e=Y(t.object);switch(t.type){case"update":return void e.emitPatch({op:"replace",path:S(t.name),value:t.newValue.snapshot,oldValue:t.oldValue?t.oldValue.snapshot:void 0},e);case"add":return void e.emitPatch({op:"add",path:S(t.name),value:t.newValue.snapshot,oldValue:void 0},e);case"delete":return void e.emitPatch({op:"remove",path:S(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){et(this,e);var n=t.storedValue,r={};n.keys().forEach(function(t){r[t]=!1}),Object.keys(e).forEach(function(t){n.set(t,e[t]),r[t]=!0}),Object.keys(r).forEach(function(t){!1===r[t]&&n.delete(t)})},o.prototype.getChildType=function(t){return this.subType},o.prototype.isValidSnapshot=function(t,e){var n=this;return c(t)?tt(Object.keys(t).map(function(r){return n.subType.validate(t[r],K(e,r,n.subType))})):X(e,t,"Value is not a plain object")},o.prototype.getDefaultSnapshot=function(){return{}},o.prototype.removeChild=function(t,e){t.storedValue.delete(e)},r([e.action],o.prototype,"applySnapshot",null),o}(xt),Dt=function(t){function o(n,r){var i=t.call(this,n)||this;return i.shouldAttachNode=!0,i.flags=Vt.Array,i.createNewInstance=function(){var t=e.observable.shallowArray();return v(t,"toString",it),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 Z(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=Y(t.object);e.assertWritable();var n=e.getChildren();switch(t.type){case"update":if(t.newValue===t.object[t.index])return null;t.newValue=ot(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=ot(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=Y(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){et(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)?tt(t.map(function(t,r){return n.subType.validate(t,K(e,""+r,n.subType))})):X(e,t,"Value is not an array")},o.prototype.getDefaultSnapshot=function(){return[]},o.prototype.removeChild=function(t,e){t.storedValue.splice(parseInt(e,10),1)},r([e.action],o.prototype,"applySnapshot",null),o}(xt),Rt=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 Z(this,t,e,n,r,this.initializer)},e.prototype.isValidSnapshot=function(t,e){return f(t)&&this.checker(t)?Q():X(e,t,"Value is not a "+("Date"===this.name?"Date or a unix milliseconds timestamp":this.name))},e}(Nt),Et=new Rt("string",Vt.String,function(t){return"string"==typeof t}),zt=new Rt("number",Vt.Number,function(t){return"number"==typeof t}),kt=new Rt("boolean",Vt.Boolean,function(t){return"boolean"==typeof t}),Ft=new Rt("null",Vt.Null,function(t){return null===t}),Mt=new Rt("undefined",Vt.Undefined,function(t){return void 0===t}),$t=new Rt("Date",Vt.Date,function(t){return"number"==typeof t||t instanceof Date},function(t){return t instanceof Date?t:new Date(t)});$t.getSnapshot=function(t){return t.storedValue.getTime()};var Lt=function(t){function e(e){var n=t.call(this,"identifier("+e.name+")")||this;return n.identifierType=e,n.flags=Vt.Identifier,n}return n(e,t),e.prototype.instantiate=function(t,e,n,r){return t&&B(t.storedValue)?(t.identifierAttribute&&i("Cannot define property '"+e+"' as object identifier, property '"+t.identifierAttribute+"' is already defined as identifier property"),t.identifierAttribute=e,Z(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):X(e,t,"Value is not a valid identifier, which is a string or a number")},e}(Nt),Ut=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|Vt.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=B(i)?Y(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&&et(this,t),t},e.prototype.isValidSnapshot=function(t,e){return void 0===t?Q():this.type.validate(t,e)},e.prototype.isAssignableFrom=function(t){return this.type.isAssignableFrom(t)},e}(Nt),Ht={afterCreate:"afterCreate",afterAttach:"afterAttach",postProcessSnapshot:"postProcessSnapshot",beforeDetach:"beforeDetach",beforeDestroy:"beforeDestroy"},Jt={name:"AnonymousModel",properties:{},initializers:At},Wt=function(t){function o(n){var r=t.call(this,n.name||Jt.name)||this;r.flags=Vt.Object,r.createNewInstance=function(){var t=e.observable.shallowObject(St);return v(t,"toString",ut),t},r.finalizeNewInstance=function(t,n){var i=t.storedValue;r.forAllProps(function(r,o){e.extendShallowObservable(i,(a={},a[r]=e.observable.ref(o.instantiate(t,r,t._environment,n[r])),a)),e.extras.interceptReads(t.storedValue,r,t.unbox);var a}),r.initializers.reduce(function(t,e){return e(t)},i),e.intercept(i,function(t){return r.willChange(t)}),e.observe(i,r.didChange)},r.didChange=function(t){var e=Y(t.object);e.emitPatch({op:"replace",path:S(t.name),value:t.newValue.snapshot,oldValue:t.oldValue?t.oldValue.snapshot:void 0},e)};var o=n.name||Jt.name;return/^\w[\w\d_]*$/.test(o)||i("Typename should be a valid identifier: "+o),Object.assign(r,Jt,n),r.properties=pt(r.properties),r.propertiesNames=Object.keys(r.properties),Object.freeze(r.properties),r}return n(o,t),o.prototype.extend=function(t){return new o({name:t.name||this.name,properties:Object.assign({},this.properties,t.properties),initializers:this.initializers.concat(t.initializers||[]),preProcessor:t.preProcessor||this.preProcessor})},o.prototype.actions=function(t){return this.extend({initializers:[function(e){var n=t(e);return c(n)||i("actions initializer should return a plain object containing actions"),Object.keys(n).forEach(function(t){if("preProcessSnapshot"===t)return i("Cannot define action 'preProcessSnapshot', it should be defined using 'type.preProcessSnapshot(fn)' instead");var r=n[t],o=e[t];if(t in Ht&&o){var a=r;r=t===Ht.postProcessSnapshot?function(t){return a(o(t))}:function(){o.apply(null,arguments),a.apply(null,arguments)}}v(e,t,U(e,t,r))}),e}]})},o.prototype.named=function(t){return this.extend({name:t})},o.prototype.props=function(t){return this.extend({properties:t})},o.prototype.views=function(t){return this.extend({initializers:[function(n){var r=t(n);return c(r)||i("views initializer should return a plain object containing views"),Object.keys(r).forEach(function(t){var o=Object.getOwnPropertyDescriptor(r,t),a=o.value;if("get"in o)if(e.isComputed(n.$mobx.values[t]))n.$mobx.values[t]=e.computed(o.get,{name:t,setter:o.set,context:n});else{var s={};Object.defineProperty(s,t,{get:o.get,set:o.set,enumerable:!0}),e.extendShallowObservable(n,s)}else"function"==typeof a?v(n,t,a):i("A view member should either be a function or getter based property")}),n}]})},o.prototype.preProcessSnapshot=function(t){var e=this.preProcessor;return e?this.extend({preProcessor:function(n){return e(t(n))}}):this.extend({preProcessor:t})},o.prototype.instantiate=function(t,e,n,r){return Z(this,t,e,n,this.applySnapshotPreProcessor(r),this.createNewInstance,this.finalizeNewInstance)},o.prototype.willChange=function(t){var e=Y(t.object),n=this.properties[t.name];return e.assertWritable(),et(n,t.newValue),t.newValue=n.reconcile(e.getChildNode(t.name),t.newValue),t},o.prototype.getChildren=function(t){var e=this,n=[];return this.forAllProps(function(r,i){n.push(e.getChildNode(t,r))}),n},o.prototype.getChildNode=function(t,e){if(!(e in this.properties))return i("Not a value property: "+e);var n=t.storedValue.$mobx.values[e].value;return n||i("Node not available for property "+e)},o.prototype.getValue=function(t){return t.storedValue},o.prototype.getSnapshot=function(t){var n=this,r={};return this.forAllProps(function(i,o){e.extras.getAtom(t.storedValue,i).reportObserved(),r[i]=n.getChildNode(t,i).snapshot}),"function"==typeof t.storedValue.postProcessSnapshot?t.storedValue.postProcessSnapshot.call(null,r):r},o.prototype.applyPatchLocally=function(t,e,n){"replace"!==n.op&&"add"!==n.op&&i("object does not support operation "+n.op),t.storedValue[e]=n.value},o.prototype.applySnapshot=function(t,e){var n=this.applySnapshotPreProcessor(e);et(this,n),this.forAllProps(function(e,r){t.storedValue[e]=n[e]})},o.prototype.applySnapshotPreProcessor=function(t){return this.preProcessor?this.preProcessor.call(null,t):t},o.prototype.getChildType=function(t){return this.properties[t]},o.prototype.isValidSnapshot=function(t,e){var n=this,r=this.applySnapshotPreProcessor(t);return c(r)?tt(this.propertiesNames.map(function(t){return n.properties[t].validate(r[t],K(e,t,n.properties[t]))})):X(e,r,"Value is not a plain object")},o.prototype.forAllProps=function(t){var e=this;this.propertiesNames.forEach(function(n){return t(n,e.properties[n])})},o.prototype.describe=function(){var t=this;return"{ "+this.propertiesNames.map(function(e){return e+": "+t.properties[e].describe()}).join("; ")+" }"},o.prototype.getDefaultSnapshot=function(){return{}},o.prototype.removeChild=function(t,e){t.storedValue[e]=null},r([e.action],o.prototype,"applySnapshot",null),o}(xt),Bt=function(){return function(t,e){if(this.mode=t,this.value=e,"object"===t){if(!B(e))return i("Can only store references to tree nodes, got: '"+e+"'");if(!Y(e).identifierAttribute)return i("Can only store references with a defined identifier attribute.")}}}(),Yt=function(t){function e(e){var n=t.call(this,"reference("+e.name+")")||this;return n.targetType=e,n.flags=Vt.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 Y(e.value).identifier}},e.prototype.instantiate=function(t,e,n,r){var i=B(r);return Z(this,t,e,n,new Bt(i?"object":"identifier",r))},e.prototype.reconcile=function(t,e){var n=B(e)?"object":"identifier";if(O(t.type)){var r=t.storedValue;if(n===r.mode&&r.value===e)return t}var i=this.instantiate(t.parent,t.subpath,t._environment,e);return t.die(),i},e.prototype.isAssignableFrom=function(t){return this.targetType.isAssignableFrom(t)},e.prototype.isValidSnapshot=function(t,e){return"string"==typeof t||"number"==typeof t?Q():X(e,t,"Value is not a valid identifier, which is a string or a number")},e}(Nt),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=Vt.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?X(e,t,"Multiple types are applicable for the union (hint: provide a dispatch function)"):0===r.length?X(e,t,"No type is applicable for the union").concat(tt(n)):Q()},e}(Nt),Gt=function(t){function e(e){var n=t.call(this,JSON.stringify(e))||this;return n.flags=Vt.Literal,n.value=e,n}return n(e,t),e.prototype.instantiate=function(t,e,n,r){return Z(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?Q():X(e,t,"Value is not a literal "+JSON.stringify(this.value))},e}(Nt),Zt=new(function(t){function e(){var e=t.call(this,"frozen")||this;return e.flags=Vt.Frozen,e}return n(e,t),e.prototype.describe=function(){return"<any immutable value>"},e.prototype.instantiate=function(t,e,n,r){return Z(this,t,e,n,d(r))},e.prototype.isValidSnapshot=function(t,e){return y(t)?Q():X(e,t,"Value is not serializable and cannot be frozen")},e}(Nt)),Kt=st(Ft,null),Qt=function(t){function e(e,n,r,i){var o=t.call(this,e)||this;return o.type=n,o.predicate=r,o.message=i,o}return n(e,t),Object.defineProperty(e.prototype,"flags",{get:function(){return this.type.flags|Vt.Refinement},enumerable:!0,configurable:!0}),e.prototype.describe=function(){return this.name},e.prototype.instantiate=function(t,e,n,r){return this.type.instantiate(t,e,n,r)},e.prototype.isAssignableFrom=function(t){return this.type.isAssignableFrom(t)},e.prototype.isValidSnapshot=function(t,e){var n=this.type.validate(t,e);if(n.length>0)return n;var r=B(t)?Y(t).snapshot:t;return this.predicate(r)?Q():X(e,t,this.message(t))},e}(Nt),Xt=function(t){function e(e,n){var r=t.call(this,e)||this;return r._subType=null,r.definition=n,r}return n(e,t),Object.defineProperty(e.prototype,"flags",{get:function(){return this.subType.flags|Vt.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}(Nt),te={enumeration:function(t,e){var n="string"==typeof t?e:t,r=ct.apply(void 0,n.map(function(t){return lt(""+t)}));return"string"==typeof t&&(r.name=t),r},model:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n="string"==typeof t[0]?t.shift():"AnonymousModel",r=t.shift()||{};return new Wt({name:n,properties:r})},compose:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n="string"==typeof t[0]?t.shift():"AnonymousModel";return t.reduce(function(t,e){return t.extend({name:t.name+"_"+e.name,properties:e.properties,initializers:e.initializers})}).named(n)},reference:function(t){return new Yt(t)},union:ct,optional:st,literal:lt,maybe:function(t){return ct(Kt,t)},refinement:function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n="string"==typeof t[0]?t.shift():_(t[0])?t[0].name:null,r=t[0],i=t[1],o=t[2]?t[2]:function(t){return"Value does not respect the refinement predicate"};return new Qt(n,r,i,o)},string:Et,boolean:kt,number:zt,Date:$t,map:function(t){return new It("map<string, "+t.name+">",t)},array:function(t){return new Dt(t.name+"[]",t)},frozen:Zt,identifier:function(t){return void 0===t&&(t=Et),new Lt(t)},late:function(t,e){var n="string"==typeof t?t:"late("+t.toString()+")";return new Xt(n,"string"==typeof t?e:t)},undefined:Mt,null:Ft};t.types=te,t.escapeJsonPath=S,t.unescapeJsonPath=j,t.decorate=function(t,e){return e.$mst_middleware?e.$mst_middleware.push(t):e.$mst_middleware=[t],e},t.addMiddleware=H,t.process=function(t){return ft(t.name,t)},t.isStateTreeNode=B,t.asReduxStore=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];B(t)||i("Expected model object");var r={getState:function(){return E(t)},dispatch:function(e){wt(e,o.slice(),function(e){return vt(t,gt(e))})},subscribe:function(e){return I(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,R(e,i),r=!1)}),mt(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,E(e))}},!0)},t.applyAction=vt,t.onAction=mt,t.recordActions=function(t){var e={actions:[],stop:function(){return n()},replay:function(t){vt(t,e.actions)}},n=mt(t,e.actions.push.bind(e.actions));return e},t.getType=x,t.getChildType=function(t,e){return Y(t).getChildType(e)},t.onPatch=N,t.onSnapshot=I,t.applyPatch=D,t.recordPatches=function(t){function e(){n||(n=N(t,function(t,e){r.rawPatches.push([t,e])}))}var n=null,r={rawPatches:[],get patches(){return this.rawPatches.map(function(t){return t[0]})},get inversePatches(){return this.rawPatches.map(function(t){return t[0],t[1]})},stop:function(){n&&n(),n=null},resume:e,replay:function(e){D(e||t,r.patches)},undo:function(e){D(e||t,r.inversePatches.slice().reverse())}};return e(),r},t.protect=function(t){var e=Y(t);e.isRoot||i("`protect` can only be invoked on root nodes"),e.isProtectionEnabled=!0},t.unprotect=function(t){var e=Y(t);e.isRoot||i("`unprotect` can only be invoked on root nodes"),e.isProtectionEnabled=!1},t.isProtected=function(t){return Y(t).isProtected},t.applySnapshot=R,t.getSnapshot=E,t.hasParent=function(t,e){void 0===e&&(e=1);for(var n=Y(t).parent;n;){if(0==--e)return!0;n=n.parent}return!1},t.getParent=function(t,e){void 0===e&&(e=1);for(var n=e,r=Y(t).parent;r;){if(0==--n)return r.storedValue;r=r.parent}return i("Failed to find the parent of "+Y(t)+" at depth "+e)},t.getRoot=z,t.getPath=function(t){return Y(t).path},t.getPathParts=function(t){return C(Y(t).path)},t.isRoot=function(t){return Y(t).isRoot},t.resolvePath=function(t,e){var n=Y(t).resolve(e);return n?n.value:void 0},t.resolveIdentifier=function(t,e,n){var r=Y(e).root.identifierCache.resolve(t,""+n);return r?r.value:void 0},t.tryResolve=k,t.getRelativePath=function(t,e){return Y(t).getRelativePathTo(Y(e))},t.clone=function(t,e){void 0===e&&(e=!0);var n=Y(t);return n.type.create(n.snapshot,!0===e?n.root._environment:!1===e?void 0:e)},t.detach=function(t){return Y(t).detach(),t},t.destroy=function(t){var e=Y(t);e.isRoot?e.die():e.parent.removeChild(e.subpath)},t.isAlive=function(t){return Y(t).isAlive},t.addDisposer=function(t,e){Y(t).addDisposer(e)},t.getEnv=function(t){var e=Y(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=F,Object.defineProperty(t,"__esModule",{value:!0})}); |
@@ -35,3 +35,2 @@ import { IObservableArray, IArrayWillChange, IArrayWillSplice, IArrayChange, IArraySplice } from "mobx"; | ||
* @example | ||
* ```javascript | ||
* const Todo = types.model({ | ||
@@ -48,3 +47,3 @@ * task: types.string | ||
* console.log(s.todos[0]) // prints: "Grab coffee" | ||
* ``` | ||
* | ||
* @export | ||
@@ -51,0 +50,0 @@ * @alias types.array |
@@ -44,3 +44,2 @@ import { ObservableMap, IMapChange, IMapWillChange } from "mobx"; | ||
* @example | ||
* ```javascript | ||
* const Todo = types.model({ | ||
@@ -59,3 +58,3 @@ * id: types.identifier, | ||
* console.log(s.todos.get(17)) // prints: "Grab coffee" | ||
* ``` | ||
* | ||
* @export | ||
@@ -62,0 +61,0 @@ * @alias types.map |
@@ -34,3 +34,3 @@ import { IObjectChange, IObjectWillChange } from "mobx"; | ||
views<V extends Object>(fn: (self: T) => V): IModelType<S, T & V>; | ||
preProcessSnapshot<T>(preProcessor: (snapshot: T) => S): IModelType<S, T>; | ||
preProcessSnapshot(preProcessor: (snapshot: any) => S): IModelType<S, T>; | ||
instantiate(parent: Node | null, subpath: string, environment: any, snapshot: any): Node; | ||
@@ -66,3 +66,3 @@ createNewInstance: () => Object; | ||
}>(fn: (self: T & IStateTreeNode) => A): IModelType<S, T & A>; | ||
preProcessSnapshot<T>(fn: (snapshot: T) => S): IModelType<S, T>; | ||
preProcessSnapshot(fn: (snapshot: any) => S): IModelType<S, T>; | ||
} | ||
@@ -69,0 +69,0 @@ export declare type IModelProperties<T> = { |
@@ -0,0 +0,0 @@ import { IObservableArray } from "mobx"; |
@@ -21,3 +21,2 @@ import { ISimpleType, IType, Type } from "./type"; | ||
* @example | ||
* ```javascript | ||
* const Person = types.model({ | ||
@@ -27,3 +26,2 @@ * firstName: types.string, | ||
* }) | ||
* ``` | ||
*/ | ||
@@ -38,3 +36,2 @@ export declare const string: ISimpleType<string>; | ||
* @example | ||
* ```javascript | ||
* const Vector = types.model({ | ||
@@ -44,3 +41,2 @@ * x: types.number, | ||
* }) | ||
* ``` | ||
*/ | ||
@@ -55,3 +51,2 @@ export declare const number: ISimpleType<number>; | ||
* @example | ||
* ```javascript | ||
* const Thing = types.model({ | ||
@@ -61,3 +56,2 @@ * isCool: types.boolean, | ||
* }) | ||
* ``` | ||
*/ | ||
@@ -85,3 +79,2 @@ export declare const boolean: ISimpleType<boolean>; | ||
* @example | ||
* ```javascript | ||
* const LogLine = types.model({ | ||
@@ -92,5 +85,4 @@ * timestamp: types.Date, | ||
* LogLine.create({ timestamp: new Date() }) | ||
* ``` | ||
*/ | ||
export declare const DatePrimitive: IType<number, Date>; | ||
export declare function getPrimitiveFactoryFromValue(value: any): ISimpleType<any>; |
@@ -0,0 +0,0 @@ export interface IContextEntry { |
@@ -0,0 +0,0 @@ import { IType, IComplexType } from "./type"; |
@@ -0,0 +0,0 @@ import { TypeFlags } from "./type-flags"; |
@@ -0,0 +0,0 @@ import { ISimpleType } from "../type"; |
@@ -20,3 +20,2 @@ import { ISimpleType, Type } from "../type"; | ||
* @example | ||
* ```javascript | ||
* const GameCharacter = types.model({ | ||
@@ -34,7 +33,5 @@ * name: string, | ||
* hero.location.x = 7 // Not ok! | ||
* ``` | ||
* | ||
* | ||
* @alias types.frozen | ||
*/ | ||
export declare const frozen: ISimpleType<any>; |
@@ -0,0 +0,0 @@ import { Type, IType } from "../type"; |
@@ -0,0 +0,0 @@ import { Type, IType } from "../type"; |
@@ -0,0 +0,0 @@ import { ISimpleType, Type } from "../type"; |
@@ -0,0 +0,0 @@ import { IType } from "../type"; |
@@ -0,0 +0,0 @@ import { Type, IType } from "../type"; |
@@ -0,0 +0,0 @@ import { Node } from "../../core"; |
@@ -0,0 +0,0 @@ import { IType, Type } from "../type"; |
@@ -0,0 +0,0 @@ import { IType, Type } from "../type"; |
@@ -27,4 +27,5 @@ export declare const EMPTY_ARRAY: ReadonlyArray<any>; | ||
export declare function addReadOnlyProp(object: any, propName: string, value: any): void; | ||
export declare function remove<T>(collection: T[], item: T): void; | ||
export declare function registerEventHandler(handlers: Function[], handler: Function): IDisposer; | ||
export declare function hasOwnProperty(object: Object, propName: string): any; | ||
export declare function argsToArray(args: IArguments): any[]; |
{ | ||
"name": "mobx-state-tree", | ||
"version": "0.10.3", | ||
"version": "0.11.0", | ||
"description": "Opinionated, transactional, MobX powered state container", | ||
@@ -46,3 +46,3 @@ "main": "dist/mobx-state-tree.js", | ||
"cpr": "^2.1.0", | ||
"documentation": "^4.0.0-beta9", | ||
"documentation": "^5.2.2", | ||
"husky": "^0.13.4", | ||
@@ -90,2 +90,2 @@ "lint-staged": "^3.6.1", | ||
} | ||
} | ||
} |
@@ -760,2 +760,3 @@ <p align="center"> | ||
| [`connectReduxDevtools(removeDevModule, node)`](API.md#connectreduxdevtools) | Connects a node to the Redux development tools [example](https://github.com/mobxjs/mobx-state-tree/blob/b01fe97d427ca664f7ecc99349d10e58d08d2d98/examples/redux-todomvc/src/index.js) | | ||
| [`decorate(middleware, function)`](API.md#decorate) | Attaches middleware to a specific action (or process) | | ||
| [`destroy(node)`](API.md#destroy) | Kills `node`, making it unusable. Removes it from any parent in the process | | ||
@@ -780,3 +781,3 @@ | [`detach(node)`](API.md#detach) | Removes `node` from its current parent, and lets it live on as standalone tree | | ||
| [`onPatch(node, (patch) => void)`](API.md#onpatch) | Attach a JSONPatch listener, that is invoked for each change in the tree. Returns disposer | | ||
| [`onSnapshot(node, (snapshot) => void)`](API.md#onsnapshot) | Attach a snapshot listener, that is invoked for each change in the tree. Returns disposer | | ||
| [`onSnapshot(node, (snapshot, inverseSnapshot) => void)`](API.md#onsnapshot) | Attach a snapshot listener, that is invoked for each change in the tree. Returns disposer | | ||
| [`process(generator)`](API.md#process) | creates an asynchronous process based on a generator function | | ||
@@ -787,3 +788,2 @@ | [`protect(node)`](API.md#protect) | Protects an unprotected tree against modifications from outside actions | | ||
| [`resolve(node, path)`](API.md#resolve) | Resolves a `path` (json path) relatively to the given `node` | | ||
| [`revertPatch(node, jsonPatch)`](API.md#revertpatch) | Inverse applies a JSON patch or array of patches to `node` | | ||
| [`splitJsonPath(path)`](API.md#splitjsonpath) | Splits and unescapes the given JSON `path` into path parts | | ||
@@ -790,0 +790,0 @@ | [`tryResolve(node, path)`](API.md#tryresolve) | 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
Sorry, the diff of this file is not supported yet
82
481625
36
8585