mobx-state-tree
Advanced tools
Comparing version 0.6.2 to 0.6.3
@@ -0,1 +1,8 @@ | ||
# 0.6.3 | ||
Fixed issue with array/maps of union types @abruzzihraig | ||
Make types.extend support computed attributes @cpunion | ||
Fixed issue with map of primitive types and applySnapshot @pioh | ||
Better type declarations for union, up to 10 supported types | ||
# 0.6.2 | ||
@@ -2,0 +9,0 @@ |
@@ -0,0 +0,0 @@ export declare type ISerializedActionCall = { |
@@ -112,3 +112,4 @@ "use strict"; | ||
var node = mst_node_1.getMSTAdministration(resolvedTarget); | ||
utils_1.invariant(typeof resolvedTarget[action.name] === "function", "Action '" + action.name + "' does not exist in '" + node.path + "'"); | ||
if (!(typeof resolvedTarget[action.name] === "function")) | ||
utils_1.fail("Action '" + action.name + "' does not exist in '" + node.path + "'"); | ||
return resolvedTarget[action.name].apply(resolvedTarget, action.args ? action.args.map(function (v) { return deserializeArgument(node, v); }) : []); | ||
@@ -115,0 +116,0 @@ } |
@@ -0,0 +0,0 @@ export * from "./mst-node"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ export declare type IJsonPatch = { |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { IType } from "../types/type"; |
@@ -32,3 +32,4 @@ "use strict"; | ||
this.disposers = []; | ||
utils_1.invariant(type instanceof complex_type_1.ComplexType, "Uh oh"); | ||
if (!(type instanceof complex_type_1.ComplexType)) | ||
utils_1.fail("Uh oh"); | ||
utils_1.addHiddenFinalProp(initialState, "$treenode", this); | ||
@@ -342,3 +343,4 @@ this._parent = parent; | ||
MSTAdministration.prototype.detach = function () { | ||
utils_1.invariant(this._isAlive); | ||
if (!this._isAlive) | ||
utils_1.fail("Error while detaching, node is not alive."); | ||
if (this.isRoot) | ||
@@ -345,0 +347,0 @@ return; |
@@ -0,0 +0,0 @@ import { IType } from "../types/type"; |
@@ -58,3 +58,4 @@ "use strict"; | ||
// PRE condition target is (a child of) base! | ||
utils_1.invariant(base.root === target.root, "Cannot calculate relative path: objects '" + base + "' and '" + target + "' are not part of the same object tree"); | ||
if (base.root !== target.root) | ||
utils_1.fail("Cannot calculate relative path: objects '" + base + "' and '" + target + "' are not part of the same object tree"); | ||
var baseParts = json_patch_1.splitJsonPath(base.path); | ||
@@ -61,0 +62,0 @@ var targetParts = json_patch_1.splitJsonPath(target.path); |
@@ -29,3 +29,3 @@ import { IRawActionCall, ISerializedActionCall } from "./action"; | ||
* console.dir(action) | ||
* return next() | ||
* return next(action) | ||
* } | ||
@@ -32,0 +32,0 @@ * |
@@ -30,3 +30,3 @@ "use strict"; | ||
* console.dir(action) | ||
* return next() | ||
* return next(action) | ||
* } | ||
@@ -208,3 +208,4 @@ * | ||
if (depth === void 0) { depth = 1; } | ||
utils_1.invariant(depth >= 0, "Invalid depth: " + depth + ", should be >= 1"); | ||
if (depth < 0) | ||
utils_1.fail("Invalid depth: " + depth + ", should be >= 1"); | ||
var parent = mst_node_1.getMSTAdministration(target).parent; | ||
@@ -221,3 +222,4 @@ while (parent) { | ||
if (depth === void 0) { depth = 1; } | ||
utils_1.invariant(depth >= 0, "Invalid depth: " + depth + ", should be >= 1"); | ||
if (depth < 0) | ||
utils_1.fail("Invalid depth: " + depth + ", should be >= 1"); | ||
var d = depth; | ||
@@ -355,3 +357,4 @@ var parent = mst_node_1.getMSTAdministration(target).parent; | ||
var env = node.root._environment; | ||
utils_1.invariant(!!env, "Node '" + node + "' is not part of state tree that was initialized with an environment. Environment can be passed as second argumentt to .create()"); | ||
if (!(!!env)) | ||
utils_1.fail("Node '" + node + "' is not part of state tree that was initialized with an environment. Environment can be passed as second argumentt to .create()"); | ||
return env; | ||
@@ -358,0 +361,0 @@ } |
@@ -0,0 +0,0 @@ import { IMSTNode } from "./mst-node"; |
@@ -43,3 +43,4 @@ "use strict"; | ||
var child = targetCollection.get(identifier); | ||
utils_1.invariant(!child || child[targetIdAttribute] === identifier, "Inconsistent collection, the map entry under key '" + identifier + "' should have property '" + targetIdAttribute + "' set to value '" + identifier); | ||
if (!(!child || child[targetIdAttribute] === identifier)) | ||
utils_1.fail("Inconsistent collection, the map entry under key '" + identifier + "' should have property '" + targetIdAttribute + "' set to value '" + identifier); | ||
return child; | ||
@@ -65,3 +66,4 @@ } | ||
else { | ||
utils_1.invariant(base.root === target.root, "Failed to assign a value to a reference; the value should already be part of the same model tree"); | ||
if (base.root !== target.root) | ||
utils_1.fail("Failed to assign a value to a reference; the value should already be part of the same model tree"); | ||
this.identifier = mst_node_1.getRelativePathForNodes(base, target); | ||
@@ -71,7 +73,9 @@ } | ||
else if (this.targetIdAttribute) { | ||
utils_1.invariant(typeof value === "string", "Expected an identifier, got: " + value); | ||
if (typeof value !== "string") | ||
utils_1.fail("Expected an identifier, got: " + value); | ||
this.identifier = value; | ||
} | ||
else { | ||
utils_1.invariant(typeof value === "object" && typeof value.$ref === "string", "Expected a reference in the format `{ $ref: ... }`, got: " + value); | ||
if (!(typeof value === "object" && typeof value.$ref === "string")) | ||
utils_1.fail("Expected a reference in the format `{ $ref: ... }`, got: " + value); | ||
this.identifier = value.$ref; | ||
@@ -78,0 +82,0 @@ } |
@@ -0,0 +0,0 @@ import "./types/type"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { IRawActionCall } from "../core"; |
@@ -12,3 +12,4 @@ "use strict"; | ||
} | ||
utils_1.invariant(core_1.isMST(model), "Expected model object"); | ||
if (!core_1.isMST(model)) | ||
utils_1.fail("Expected model object"); | ||
var store = { | ||
@@ -15,0 +16,0 @@ getState: function () { return mst_operations_1.getSnapshot(model); }, |
import { IObservableArray, IArrayWillChange, IArrayWillSplice, IArrayChange, IArraySplice } from "mobx"; | ||
import { IJsonPatch, MSTAdministration } from "../../core"; | ||
import { IType, IComplexType } from "../type"; | ||
import { IType, IComplexType, TypeFlags } from "../type"; | ||
import { IContext, IValidationResult } from "../type-checker"; | ||
@@ -10,2 +10,3 @@ import { ComplexType } from "./complex-type"; | ||
subType: IType<any, any>; | ||
readonly flags: TypeFlags; | ||
constructor(name: string, subType: IType<any, any>); | ||
@@ -12,0 +13,0 @@ describe(): string; |
@@ -34,2 +34,3 @@ "use strict"; | ||
_this.isArrayFactory = true; | ||
_this.flags = type_1.TypeFlags.Array; | ||
_this.subType = subType; | ||
@@ -175,5 +176,5 @@ return _this; | ||
function isArrayFactory(type) { | ||
return type_1.isType(type) && type.isArrayFactory === true; | ||
return type_1.isType(type) && (type.flags & type_1.TypeFlags.Array) > 0; | ||
} | ||
exports.isArrayFactory = isArrayFactory; | ||
//# sourceMappingURL=array.js.map |
@@ -0,0 +0,0 @@ import { IType, Type } from "../type"; |
@@ -0,0 +0,0 @@ "use strict"; |
import { ObservableMap, IMapChange, IMapWillChange } from "mobx"; | ||
import { MSTAdministration, IJsonPatch } from "../../core"; | ||
import { IType, IComplexType } from "../type"; | ||
import { IType, IComplexType, TypeFlags } from "../type"; | ||
import { IContext, IValidationResult } from "../type-checker"; | ||
@@ -15,2 +15,3 @@ import { ComplexType } from "./complex-type"; | ||
subType: IType<any, any>; | ||
readonly flags: TypeFlags; | ||
constructor(name: string, subType: IType<any, any>); | ||
@@ -36,4 +37,4 @@ describe(): string; | ||
}, IExtendedObservableMap<T>>; | ||
export declare function isMapFactory<S, T>(factory: any): factory is IComplexType<{ | ||
export declare function isMapFactory<S, T>(type: any): type is IComplexType<{ | ||
[key: string]: S; | ||
}, IExtendedObservableMap<T>>; |
@@ -32,4 +32,6 @@ "use strict"; | ||
var identifierAttr = object_1.getIdentifierAttribute(core_1.getMSTAdministration(this).type.subType); | ||
utils_1.invariant(!!identifierAttr, "Map.put is only supported if the subtype has an idenfier attribute"); | ||
utils_1.invariant(!!value, "Map.put cannot be used to set empty values"); | ||
if (!(!!identifierAttr)) | ||
utils_1.fail("Map.put is only supported if the subtype has an idenfier attribute"); | ||
if (!(!!value)) | ||
utils_1.fail("Map.put cannot be used to set empty values"); | ||
this.set(value[identifierAttr], value); | ||
@@ -43,2 +45,3 @@ return this; | ||
_this.isMapFactory = true; | ||
_this.flags = type_1.TypeFlags.Map; | ||
_this.subType = subType; | ||
@@ -159,3 +162,2 @@ return _this; | ||
if (key in currentKeys && !utils_1.isPrimitive(item)) { | ||
currentKeys[key] = true; | ||
core_1.maybeMST(target.get(key), function (propertyNode) { | ||
@@ -171,2 +173,3 @@ // update existing instance | ||
} | ||
currentKeys[key] = true; | ||
}); | ||
@@ -212,6 +215,6 @@ Object.keys(currentKeys).forEach(function (key) { | ||
exports.map = map; | ||
function isMapFactory(factory) { | ||
return type_1.isType(factory) && factory.isMapFactory === true; | ||
function isMapFactory(type) { | ||
return type_1.isType(type) && (type.flags & type_1.TypeFlags.Map) > 0; | ||
} | ||
exports.isMapFactory = isMapFactory; | ||
//# sourceMappingURL=map.js.map |
import { IObjectChange, IObjectWillChange } from "mobx"; | ||
import { MSTAdministration, IMSTNode, IJsonPatch } from "../../core"; | ||
import { IType, IComplexType } from "../type"; | ||
import { IType, IComplexType, TypeFlags } from "../type"; | ||
import { IContext, IValidationResult } from "../type-checker"; | ||
@@ -8,2 +8,3 @@ import { ComplexType } from "./complex-type"; | ||
isObjectFactory: boolean; | ||
readonly flags: TypeFlags; | ||
/** | ||
@@ -10,0 +11,0 @@ * The original object definition |
@@ -29,3 +29,2 @@ "use strict"; | ||
var identifier_1 = require("../utility-types/identifier"); | ||
var late_1 = require("../utility-types/late"); | ||
var identifier_property_1 = require("../property-types/identifier-property"); | ||
@@ -45,2 +44,3 @@ var reference_property_1 = require("../property-types/reference-property"); | ||
_this.isObjectFactory = true; | ||
_this.flags = type_1.TypeFlags.Object; | ||
/** | ||
@@ -58,3 +58,4 @@ * Parsed description of all properties | ||
_this.baseActions = baseActions; | ||
utils_1.invariant(/^\w[\w\d_]*$/.test(name), "Typename should be a valid identifier: " + name); | ||
if (!(/^\w[\w\d_]*$/.test(name))) | ||
utils_1.fail("Typename should be a valid identifier: " + name); | ||
_this.modelConstructor = new Function("return function " + name + " (){}")(); // fancy trick to get a named function...., http://stackoverflow.com/questions/5905492/dynamic-function-name-in-javascript | ||
@@ -80,2 +81,3 @@ _this.modelConstructor.prototype.toString = objectTypeToString; | ||
node.assertWritable(); | ||
// TODO: assigning a new snapshot / MST to a property should result in a nice patch in itself | ||
return this.props[change.name].willChange(change); | ||
@@ -98,3 +100,4 @@ }; | ||
else if (identifier_1.isIdentifierFactory(value)) { | ||
utils_1.invariant(!this.identifierAttribute, "Cannot define property '" + key + "' as object identifier, property '" + this.identifierAttribute + "' is already defined as identifier property"); | ||
if (this.identifierAttribute) | ||
utils_1.fail("Cannot define property '" + key + "' as object identifier, property '" + this.identifierAttribute + "' is already defined as identifier property"); | ||
this.identifierAttribute = key; | ||
@@ -162,3 +165,4 @@ this.props[key] = new identifier_property_1.IdentifierProperty(key, value.primitiveType); | ||
ObjectType.prototype.applyPatchLocally = function (node, subpath, patch) { | ||
utils_1.invariant(patch.op === "replace" || patch.op === "add"); | ||
if (!(patch.op === "replace" || patch.op === "add")) | ||
utils_1.fail("object does not support operation " + patch.op); | ||
node.target[subpath] = patch.value; | ||
@@ -225,2 +229,6 @@ }; | ||
} | ||
function getObjectFactoryBaseActions(item) { | ||
var type = type_1.isType(item) ? item : core_1.getType(item); | ||
return isObjectFactory(type) ? type.baseActions : {}; | ||
} | ||
function extend() { | ||
@@ -234,16 +242,14 @@ var args = []; | ||
var factoryName = typeof args[0] === "string" ? args[0] : baseFactories.map(function (f) { return f.name; }).join("_"); | ||
return model(factoryName, utils_1.extend.apply(null, [{}].concat(baseFactories.map(getObjectFactoryBaseModel)))); | ||
var properties = utils_1.extendKeepGetter.apply(null, [{}].concat(baseFactories.map(getObjectFactoryBaseModel))); | ||
var actions = utils_1.extend.apply(null, [{}].concat(baseFactories.map(getObjectFactoryBaseActions))); | ||
return model(factoryName, properties, actions); | ||
} | ||
exports.extend = extend; | ||
function isObjectFactory(type) { | ||
return type_1.isType(type) && type.isObjectFactory === true; | ||
return type_1.isType(type) && (type.flags & type_1.TypeFlags.Object) > 0; | ||
} | ||
exports.isObjectFactory = isObjectFactory; | ||
function getIdentifierAttribute(type) { | ||
// TODO: this should be a general property of types | ||
if (type instanceof ObjectType) | ||
if (isObjectFactory(type)) | ||
return type.identifierAttribute; | ||
// TODO: make this a generic utility! | ||
if (type instanceof late_1.Late) | ||
return type.definition().identifierAttribute; | ||
return null; | ||
@@ -250,0 +256,0 @@ } |
@@ -52,2 +52,3 @@ import { IObservableArray } from "mobx"; | ||
<SA, SB, SC, SD, SE, SF, SG, SH, SI, SJ, TA, TB, TC, TD, TE, TF, TG, TH, TI, TJ>(A: IType<SA, TA>, B: IType<SB, TB>, C: IType<SC, TC>, D: IType<SD, TD>, E: IType<SE, TE>, F: IType<SF, TF>, G: IType<SG, TG>, H: IType<SH, TH>, I: IType<SI, TI>, J: IType<SJ, TJ>): IType<SA | SB | SC | SD | SE | SF | SG | SH | SI | SJ, TA | TB | TC | TD | TE | TF | TG | TH | TI | TJ>; | ||
(...types: IType<any, any>[]): IType<any, any>; | ||
(dispatchOrType: IType<any, any> | ((snapshot: any) => IType<any, any>), ...otherTypes: IType<any, any>[]): IType<any, any>; | ||
@@ -54,0 +55,0 @@ }; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -1,6 +0,7 @@ | ||
import { ISimpleType, Type } from "./type"; | ||
import { ISimpleType, TypeFlags, Type } from "./type"; | ||
import { IContext, IValidationResult } from "./type-checker"; | ||
export declare class CoreType<T> extends Type<T, T> { | ||
readonly checker: (value: any) => boolean; | ||
constructor(name: any, checker: any); | ||
readonly flags: TypeFlags; | ||
constructor(name: any, flags: TypeFlags, checker: any); | ||
describe(): string; | ||
@@ -7,0 +8,0 @@ create(value: any): any; |
@@ -18,4 +18,5 @@ "use strict"; | ||
__extends(CoreType, _super); | ||
function CoreType(name, checker) { | ||
function CoreType(name, flags, checker) { | ||
var _this = _super.call(this, name) || this; | ||
_this.flags = flags; | ||
_this.checker = checker; | ||
@@ -28,4 +29,6 @@ return _this; | ||
CoreType.prototype.create = function (value) { | ||
utils_1.invariant(utils_1.isPrimitive(value), "Not a primitive: '" + value + "'"); | ||
utils_1.invariant(this.checker(value), "Value is not assignable to '" + this.name + "'"); | ||
if (!utils_1.isPrimitive(value)) | ||
utils_1.fail("Not a primitive: '" + value + "'"); | ||
if (!this.checker(value)) | ||
utils_1.fail("Value is not assignable to '" + this.name + "'"); | ||
return value; | ||
@@ -50,9 +53,9 @@ }; | ||
// tslint:disable-next-line:variable-name | ||
exports.string = new CoreType("string", function (v) { return typeof v === "string"; }); | ||
exports.string = new CoreType("string", type_1.TypeFlags.String, function (v) { return typeof v === "string"; }); | ||
// tslint:disable-next-line:variable-name | ||
exports.number = new CoreType("number", function (v) { return typeof v === "number"; }); | ||
exports.number = new CoreType("number", type_1.TypeFlags.Number, function (v) { return typeof v === "number"; }); | ||
// tslint:disable-next-line:variable-name | ||
exports.boolean = new CoreType("boolean", function (v) { return typeof v === "boolean"; }); | ||
exports.boolean = new CoreType("boolean", type_1.TypeFlags.Boolean, function (v) { return typeof v === "boolean"; }); | ||
// tslint:disable-next-line:variable-name | ||
exports.DatePrimitive = new CoreType("Date", function (v) { return v instanceof Date; }); | ||
exports.DatePrimitive = new CoreType("Date", type_1.TypeFlags.Date, function (v) { return v instanceof Date; }); | ||
function getPrimitiveFactoryFromValue(value) { | ||
@@ -74,5 +77,5 @@ switch (typeof value) { | ||
function isPrimitiveType(type) { | ||
return type instanceof CoreType; | ||
return (type.flags & (type_1.TypeFlags.String | type_1.TypeFlags.Number | type_1.TypeFlags.Boolean | type_1.TypeFlags.Date)) > 0; | ||
} | ||
exports.isPrimitiveType = isPrimitiveType; | ||
//# sourceMappingURL=primitives.js.map |
@@ -0,0 +0,0 @@ import { Property } from "./property"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { Property } from "./property"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { IObjectWillChange } from "mobx"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { IMSTNode } from "../../core/"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { Property } from "./property"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { IObjectWillChange, IObjectChange } from "mobx"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { Property } from "./property"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { IType } from "./type"; |
@@ -0,0 +0,0 @@ "use strict"; |
export interface ISnapshottable<S> { | ||
} | ||
export declare enum TypeFlags { | ||
String = 1, | ||
Number = 2, | ||
Boolean = 4, | ||
Date = 8, | ||
Literal = 16, | ||
Array = 32, | ||
Map = 64, | ||
Object = 128, | ||
Frozen = 256, | ||
Optional = 512, | ||
} | ||
export interface IType<S, T> { | ||
name: string; | ||
flags: TypeFlags; | ||
is(thing: any): thing is S | T; | ||
@@ -23,2 +36,3 @@ validate(thing: any, context: IContext): IValidationResult; | ||
constructor(name: string); | ||
abstract flags: TypeFlags; | ||
abstract create(snapshot: any): any; | ||
@@ -25,0 +39,0 @@ abstract validate(thing: any, context: IContext): IValidationResult; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var TypeFlags; | ||
(function (TypeFlags) { | ||
TypeFlags[TypeFlags["String"] = 1] = "String"; | ||
TypeFlags[TypeFlags["Number"] = 2] = "Number"; | ||
TypeFlags[TypeFlags["Boolean"] = 4] = "Boolean"; | ||
TypeFlags[TypeFlags["Date"] = 8] = "Date"; | ||
TypeFlags[TypeFlags["Literal"] = 16] = "Literal"; | ||
TypeFlags[TypeFlags["Array"] = 32] = "Array"; | ||
TypeFlags[TypeFlags["Map"] = 64] = "Map"; | ||
TypeFlags[TypeFlags["Object"] = 128] = "Object"; | ||
TypeFlags[TypeFlags["Frozen"] = 256] = "Frozen"; | ||
TypeFlags[TypeFlags["Optional"] = 512] = "Optional"; | ||
})(TypeFlags = exports.TypeFlags || (exports.TypeFlags = {})); | ||
function isType(value) { | ||
@@ -4,0 +17,0 @@ return typeof value === "object" && value && value.isType === true; |
@@ -1,4 +0,5 @@ | ||
import { ISimpleType, Type } from "../type"; | ||
import { ISimpleType, TypeFlags, Type } from "../type"; | ||
import { IContext, IValidationResult } from "../type-checker"; | ||
export declare class Frozen<T> extends Type<T, T> { | ||
flags: TypeFlags; | ||
constructor(); | ||
@@ -5,0 +6,0 @@ describe(): string; |
@@ -30,3 +30,5 @@ "use strict"; | ||
function Frozen() { | ||
return _super.call(this, "frozen") || this; | ||
var _this = _super.call(this, "frozen") || this; | ||
_this.flags = type_1.TypeFlags.Frozen; | ||
return _this; | ||
} | ||
@@ -37,3 +39,4 @@ Frozen.prototype.describe = function () { | ||
Frozen.prototype.create = function (value) { | ||
utils_1.invariant(utils_1.isSerializable(value), "Given value should be serializable"); | ||
if (!utils_1.isSerializable(value)) | ||
utils_1.fail("Given value should be serializable"); | ||
// deep freeze the object/array | ||
@@ -40,0 +43,0 @@ return utils_1.isMutable(value) ? freeze(value) : value; |
@@ -0,0 +0,0 @@ import { IType } from "../type"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -1,2 +0,2 @@ | ||
import { Type, IType } from "../type"; | ||
import { Type, IType, TypeFlags } from "../type"; | ||
import { IContext, IValidationResult } from "../type-checker"; | ||
@@ -6,2 +6,3 @@ export declare class Late<S, T> extends Type<S, T> { | ||
private _subType; | ||
readonly flags: TypeFlags; | ||
readonly subType: IType<S, T>; | ||
@@ -8,0 +9,0 @@ constructor(name: string, definition: () => IType<S, T>); |
@@ -15,3 +15,2 @@ "use strict"; | ||
var type_1 = require("../type"); | ||
var type_checker_1 = require("../type-checker"); | ||
var Late = (function (_super) { | ||
@@ -22,6 +21,14 @@ __extends(Late, _super); | ||
_this._subType = null; | ||
utils_1.invariant(typeof definition === "function" && definition.length === 0, "Invalid late type, expected a function with zero arguments that returns a type, got: " + definition); | ||
if (!(typeof definition === "function" && definition.length === 0)) | ||
utils_1.fail("Invalid late type, expected a function with zero arguments that returns a type, got: " + definition); | ||
_this.definition = definition; | ||
return _this; | ||
} | ||
Object.defineProperty(Late.prototype, "flags", { | ||
get: function () { | ||
return this.subType.flags; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Late.prototype, "subType", { | ||
@@ -44,6 +51,3 @@ get: function () { | ||
Late.prototype.validate = function (value, context) { | ||
if (!this.subType.is(value)) { | ||
return type_checker_1.typeCheckFailure(context, value); | ||
} | ||
return type_checker_1.typeCheckSuccess(); | ||
return this.subType.validate(value, context); | ||
}; | ||
@@ -50,0 +54,0 @@ Object.defineProperty(Late.prototype, "identifierAttribute", { |
@@ -1,5 +0,6 @@ | ||
import { ISimpleType, Type } from "../type"; | ||
import { ISimpleType, TypeFlags, Type } from "../type"; | ||
import { IContext, IValidationResult } from "../type-checker"; | ||
export declare class Literal<T> extends Type<T, T> { | ||
readonly value: any; | ||
readonly flags: TypeFlags; | ||
constructor(value: any); | ||
@@ -6,0 +7,0 @@ create(snapshot: any): any; |
@@ -20,2 +20,3 @@ "use strict"; | ||
var _this = _super.call(this, "" + value) || this; | ||
_this.flags = type_1.TypeFlags.Literal; | ||
_this.value = value; | ||
@@ -48,3 +49,4 @@ return _this; | ||
function literal(value) { | ||
utils_1.invariant(utils_1.isPrimitive(value), "Literal types can be built only on top of primitives"); | ||
if (!utils_1.isPrimitive(value)) | ||
utils_1.fail("Literal types can be built only on top of primitives"); | ||
return new Literal(value); | ||
@@ -51,0 +53,0 @@ } |
import { IType } from "../type"; | ||
export declare function maybe<S, T>(type: IType<S, T>): IType<S | null | undefined, T | null>; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -8,2 +8,3 @@ import { Type, IType } from "../type"; | ||
readonly defaultValue: IOptionalValue<S, T>; | ||
readonly flags: number; | ||
constructor(type: IType<S, T>, defaultValue: IOptionalValue<S, T>); | ||
@@ -10,0 +11,0 @@ describe(): string; |
@@ -23,2 +23,9 @@ "use strict"; | ||
} | ||
Object.defineProperty(OptionalValue.prototype, "flags", { | ||
get: function () { | ||
return this.type.flags | type_1.TypeFlags.Optional; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
OptionalValue.prototype.describe = function () { | ||
@@ -25,0 +32,0 @@ // return "(" + this.type.type.describe() + " = " + JSON.stringify(this.defaultValue) + ")" |
@@ -0,0 +0,0 @@ import { IType } from "../type"; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -1,2 +0,2 @@ | ||
import { IType, Type } from "../type"; | ||
import { IType, TypeFlags, Type } from "../type"; | ||
import { IContext, IValidationResult } from "../type-checker"; | ||
@@ -6,2 +6,3 @@ export declare class Refinement extends Type<any, any> { | ||
readonly predicate: (v: any) => boolean; | ||
readonly flags: TypeFlags; | ||
constructor(name: string, type: IType<any, any>, predicate: (v: any) => boolean); | ||
@@ -8,0 +9,0 @@ describe(): string; |
@@ -25,2 +25,9 @@ "use strict"; | ||
} | ||
Object.defineProperty(Refinement.prototype, "flags", { | ||
get: function () { | ||
return this.type.flags; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Refinement.prototype.describe = function () { | ||
@@ -34,3 +41,4 @@ return this.name; | ||
// check if pass the predicate | ||
utils_1.invariant(this.is(snapshot), "Value " + JSON.stringify(snapshot) + " is not assignable to type " + this.name); | ||
if (!this.is(snapshot)) | ||
utils_1.fail("Value " + JSON.stringify(snapshot) + " is not assignable to type " + this.name); | ||
return inst; | ||
@@ -57,3 +65,4 @@ }; | ||
var inst = type.create(); | ||
utils_1.invariant(predicate(core_1.isMST(inst) ? core_1.getMSTAdministration(inst).snapshot : inst), "Default value for refinement type " + name + " does not pass the predicate."); | ||
if (!predicate(core_1.isMST(inst) ? core_1.getMSTAdministration(inst).snapshot : inst)) | ||
utils_1.fail("Default value for refinement type " + name + " does not pass the predicate."); | ||
return new Refinement(name, type, predicate); | ||
@@ -60,0 +69,0 @@ } |
@@ -1,3 +0,4 @@ | ||
import { IType, Type } from "../type"; | ||
import { IType, TypeFlags, Type } from "../type"; | ||
import { IContext, IValidationResult } from "../type-checker"; | ||
import { MSTAdministration } from "../../core/mst-node-administration"; | ||
export declare type ITypeDispatcher = (snapshot: any) => IType<any, any>; | ||
@@ -7,5 +8,6 @@ export declare class Union extends Type<any, any> { | ||
readonly types: IType<any, any>[]; | ||
readonly flags: TypeFlags; | ||
constructor(name: string, types: IType<any, any>[], dispatcher: ITypeDispatcher | null); | ||
describe(): string; | ||
create(value: any): any; | ||
create(value: any, environment?: any, parent?: MSTAdministration | null, subpath?: string): any; | ||
validate(value: any, context: IContext): IValidationResult; | ||
@@ -32,2 +34,3 @@ readonly identifierAttribute: string | null; | ||
export declare function union<SA, SB, SC, SD, SE, SF, SG, SH, SI, SJ, TA, TB, TC, TD, TE, TF, TG, TH, TI, TJ>(A: IType<SA, TA>, B: IType<SB, TB>, C: IType<SC, TC>, D: IType<SD, TD>, E: IType<SE, TE>, F: IType<SF, TF>, G: IType<SG, TG>, H: IType<SH, TH>, I: IType<SI, TI>, J: IType<SJ, TJ>): IType<SA | SB | SC | SD | SE | SF | SG | SH | SI | SJ, TA | TB | TC | TD | TE | TF | TG | TH | TI | TJ>; | ||
export declare function union(...types: IType<any, any>[]): IType<any, any>; | ||
export declare function union(dispatchOrType: ITypeDispatcher | IType<any, any>, ...otherTypes: IType<any, any>[]): IType<any, any>; |
@@ -25,10 +25,24 @@ "use strict"; | ||
} | ||
Object.defineProperty(Union.prototype, "flags", { | ||
get: function () { | ||
var result = 0; | ||
this.types.forEach(function (type) { | ||
result |= type.flags; | ||
}); | ||
return result; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Union.prototype.describe = function () { | ||
return "(" + this.types.map(function (factory) { return factory.describe(); }).join(" | ") + ")"; | ||
}; | ||
Union.prototype.create = function (value) { | ||
Union.prototype.create = function (value, environment, parent, subpath) { | ||
if (environment === void 0) { environment = undefined; } | ||
if (parent === void 0) { parent = null; } | ||
if (subpath === void 0) { subpath = ""; } | ||
type_checker_1.typecheck(this, value); | ||
// try the dispatcher, if defined | ||
if (this.dispatcher !== null) { | ||
return this.dispatcher(value).create(value); | ||
return this.dispatcher(value).create(value, environment, parent, subpath); | ||
} | ||
@@ -39,3 +53,3 @@ // find the most accomodating type | ||
return utils_1.fail("Ambiguos snapshot " + JSON.stringify(value) + " for union " + this.name + ". Please provide a dispatch in the union declaration."); | ||
return applicableTypes[0].create(value); | ||
return applicableTypes[0].create(value, environment, parent, subpath); | ||
}; | ||
@@ -42,0 +56,0 @@ Union.prototype.validate = function (value, context) { |
export declare const EMPTY_ARRAY: ReadonlyArray<never>; | ||
export declare type IDisposer = () => void; | ||
export declare function fail(message?: string): never; | ||
export declare function invariant(cond: boolean, message?: string): void; | ||
export declare function identity<T>(_: T): T; | ||
@@ -11,2 +10,6 @@ export declare function nothing(): null; | ||
export declare function extend(a: any, ...b: any[]): any; | ||
export declare function extendKeepGetter<A, B>(a: A, b: B): A & B; | ||
export declare function extendKeepGetter<A, B, C>(a: A, b: B, c: C): A & B & C; | ||
export declare function extendKeepGetter<A, B, C, D>(a: A, b: B, c: C, d: D): A & B & C & D; | ||
export declare function extendKeepGetter(a: any, ...b: any[]): any; | ||
export declare function isPlainObject(value: any): boolean; | ||
@@ -13,0 +16,0 @@ export declare function isMutable(value: any): boolean; |
@@ -6,13 +6,5 @@ "use strict"; | ||
if (message === void 0) { message = "Illegal state"; } | ||
invariant(false, message); | ||
throw "!"; | ||
throw new Error("[mobx-state-tree] " + message); | ||
} | ||
exports.fail = fail; | ||
// Optimize: accept () => string as message, so string doesn't have to be prepared at runtime | ||
function invariant(cond, message) { | ||
if (message === void 0) { message = "Illegal state"; } | ||
if (!cond) | ||
throw new Error("[mobx-state-tree] " + message); | ||
} | ||
exports.invariant = invariant; | ||
function identity(_) { | ||
@@ -39,2 +31,21 @@ return _; | ||
exports.extend = extend; | ||
function extendKeepGetter(a) { | ||
var b = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
b[_i - 1] = arguments[_i]; | ||
} | ||
for (var i = 0; i < b.length; i++) { | ||
var current = b[i]; | ||
for (var key in current) { | ||
var descriptor = Object.getOwnPropertyDescriptor(current, key); | ||
if ("get" in descriptor) { | ||
Object.defineProperty(a, key, descriptor); | ||
continue; | ||
} | ||
a[key] = current[key]; | ||
} | ||
} | ||
return a; | ||
} | ||
exports.extendKeepGetter = extendKeepGetter; | ||
function isPlainObject(value) { | ||
@@ -41,0 +52,0 @@ if (value === null || typeof value !== "object") |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("mobx")):"function"==typeof define&&define.amd?define(["mobx"],e):"object"==typeof exports?exports.mobxStateTree=e(require("mobx")):t.mobxStateTree=e(t.mobx)}(this,function(t){return function(t){function e(r){if(n[r])return n[r].exports;var i=n[r]={exports:{},id:r,loaded:!1};return t[r].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){"use strict";function r(t){for(var n in t)e.hasOwnProperty(n)||(e[n]=t[n])}Object.defineProperty(e,"__esModule",{value:!0}),n(3),n(10);var i=n(25);e.types=i.types,r(n(7)),r(n(9));var o=n(5);e.isMST=o.isMST,e.getType=o.getType,e.getChildType=o.getChildType,e.onAction=o.onAction,e.applyAction=o.applyAction;var a=n(22);e.asReduxStore=a.asReduxStore,e.connectReduxDevtools=a.connectReduxDevtools},function(t,e){"use strict";function n(t){throw void 0===t&&(t="Illegal state"),r(!1,t),"!"}function r(t,e){if(void 0===e&&(e="Illegal state"),!t)throw new Error("[mobx-state-tree] "+e)}function i(t){return t}function o(){return null}function a(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 s(t){if(null===t||"object"!=typeof t)return!1;var e=Object.getPrototypeOf(t);return e===Object.prototype||null===e}function u(t){return!(null===t||"object"!=typeof t||t instanceof Date||t instanceof RegExp)}function c(t){return null===t||void 0===t||"string"==typeof t||"number"==typeof t||"boolean"==typeof t||t instanceof Date}function p(t){return"function"!=typeof t}function f(t,e,n){Object.defineProperty(t,e,{enumerable:!1,writable:!1,configurable:!0,value:n})}function l(t,e,n){Object.defineProperty(t,e,{enumerable:!1,writable:!0,configurable:!0,value:n})}function h(t,e,n){Object.defineProperty(t,e,{enumerable:!0,writable:!1,configurable:!0,value:n})}function d(t,e){return t.push(e),function(){var n=t.indexOf(e);n!==-1&&t.splice(n,1)}}function y(t,e){return m.call(t,e)}function v(t){for(var e=new Array(t.length),n=0;n<t.length;n++)e[n]=t[n];return e}function b(t,e){return new Function("f","return function "+t+"() { return f.apply(this, arguments)}")(e)}function g(t){return"string"==typeof t&&/^[a-z0-9_-]+$/i.test(t)}Object.defineProperty(e,"__esModule",{value:!0}),e.EMPTY_ARRAY=Object.freeze([]),e.fail=n,e.invariant=r,e.identity=i,e.nothing=o,e.extend=a,e.isPlainObject=s,e.isMutable=u,e.isPrimitive=c,e.isSerializable=p,e.addHiddenFinalProp=f,e.addHiddenWritableProp=l,e.addReadOnlyProp=h,e.registerEventHandler=d;var m=Object.prototype.hasOwnProperty;e.hasOwnProperty=y,e.argsToArray=v,e.createNamedFunction=b,e.isValidIdentifier=g},function(t,e,n){"use strict";function r(t){var e=t.value,n=t.context[t.context.length-1].type,r=t.context.map(function(t){var e=t.path;return e}).filter(function(t){return t.length>0}).join("/"),i=r.length>0?'at path "/'+r+'" ':"",o=f.maybeMST(e,function(t){return"value of type "+t.type.name+":"},function(){return p.isPrimitive(e)?"value":"snapshot"}),a=n&&f.isMST(e)&&n.is(f.getMSTAdministration(e).snapshot);return""+i+o+" "+d(e)+" is not assignable "+(n?"to type: `"+n.name+"`":"")+(t.message?" ("+t.message+")":"")+(n?l.isPrimitiveType(n)||n instanceof h.OptionalValue&&l.isPrimitiveType(n.type)?".":", expected an instance of `"+n.name+"` or a snapshot like `"+n.describe()+"` instead."+(a?" (Note that a snapshot of the provided value is compatible with the targeted type)":""):".")}function i(t){return[{type:t,path:""}]}function o(t,e,n){return t.concat([{path:e,type:n}])}function a(){return p.EMPTY_ARRAY}function s(t,e,n){return[{context:t,value:e,message:n}]}function u(t){return t.reduce(function(t,e){return t.concat(e)},[])}function c(t,e){var n=t.validate(e,[{path:"",type:t}]);n.length>0&&p.fail("Error while converting "+d(e)+" to `"+t.name+"`:\n"+n.map(r).join("\n"))}Object.defineProperty(e,"__esModule",{value:!0});var p=n(1),f=n(6),l=n(12),h=n(13),d=function(t){return f.isMST(t)?"<"+t+">":"`"+JSON.stringify(t)+"`"};e.getDefaultContext=i,e.getContextForPath=o,e.typeCheckSuccess=a,e.typeCheckFailure=s,e.flattenTypeErrors=u,e.typecheck=c},function(t,e,n){"use strict";function r(t){return"object"==typeof t&&t&&t.isType===!0}Object.defineProperty(e,"__esModule",{value:!0}),e.isType=r;var i=function(){function t(t){this.isType=!0,this.name=t}return t.prototype.is=function(t){return 0===this.validate(t,[{path:"",type:this}]).length},Object.defineProperty(t.prototype,"Type",{get:function(){return o.fail("Factory.Type should not be actually called. It is just a Type signature that can be used at compile time with Typescript, by using `typeof type.Type`")},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"SnapshotType",{get:function(){return o.fail("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}),t}();e.Type=i;var o=n(1)},function(e,n){e.exports=t},function(t,e,n){"use strict";function r(t){for(var n in t)e.hasOwnProperty(n)||(e[n]=t[n])}Object.defineProperty(e,"__esModule",{value:!0}),r(n(6)),r(n(15)),r(n(14)),r(n(9)),r(n(7))},function(t,e,n){"use strict";function r(t){return a(t).type}function i(t,e){return a(t).getChildType(e)}function o(t){return t&&t.$treenode}function a(t){return o(t)?t.$treenode:f.fail("element has no Node")}function s(t,e,n){if(f.isMutable(t)&&o(t)){var r=a(t);return e(r,r.target)}return n?n(t):t}function u(t){return t instanceof Date?{$treetype:"Date",time:t.toJSON()}:o(t)?a(t).snapshot:f.isSerializable(t)?t:void f.fail("Unable to convert value to snapshot.")}function c(t,e){f.invariant(t.root===e.root,"Cannot calculate relative path: objects '"+t+"' and '"+e+"' are not part of the same object tree");for(var n=p.splitJsonPath(t.path),r=p.splitJsonPath(e.path),i=0;i<n.length&&n[i]===r[i];i++);return n.slice(i).map(function(t){return".."}).join("/")+p.joinJsonPath(r.slice(i))}Object.defineProperty(e,"__esModule",{value:!0});var p=n(9);e.getType=r,e.getChildType=i,e.isMST=o,e.getMSTAdministration=a,e.maybeMST=s,e.valueToSnapshot=u,e.getRelativePathForNodes=c;var f=n(1)},function(t,e,n){"use strict";function r(t,e){var n=z.getMSTAdministration(t);return n.isProtectionEnabled||console.warn("It is recommended to protect the state tree before attaching action middleware, as otherwise it cannot be guaranteed that all changes are passed through middleware. See `protect`"),n.addMiddleWare(e)}function i(t,e){return z.getMSTAdministration(t).onPatch(e)}function o(t,e){return z.getMSTAdministration(t).onSnapshot(e)}function a(t,e){return z.getMSTAdministration(t).applyPatch(e)}function s(t,e){var n=z.getMSTAdministration(t);I.runInAction(function(){e.forEach(function(t){return n.applyPatch(t)})})}function u(t){var e={patches:[],stop:function(){return n()},replay:function(t){s(t,e.patches)}},n=i(t,function(t){e.patches.push(t)});return e}function c(t,e){I.runInAction(function(){e.forEach(function(e){return R.applyAction(t,e)})})}function p(t){var e={actions:[],stop:function(){return n()},replay:function(t){c(t,e.actions)}},n=R.onAction(t,e.actions.push.bind(e.actions));return e}function f(t){z.getMSTAdministration(t).isProtectionEnabled=!0}function l(t){z.getMSTAdministration(t).isProtectionEnabled=!1}function h(t){return z.getMSTAdministration(t).isProtectionEnabled}function d(t,e){return z.getMSTAdministration(t).applySnapshot(e)}function y(t){return z.getMSTAdministration(t).snapshot}function v(t,e){void 0===e&&(e=1),E.invariant(e>=0,"Invalid depth: "+e+", should be >= 1");for(var n=z.getMSTAdministration(t).parent;n;){if(0===--e)return!0;n=n.parent}return!1}function b(t,e){void 0===e&&(e=1),E.invariant(e>=0,"Invalid depth: "+e+", should be >= 1");for(var n=e,r=z.getMSTAdministration(t).parent;r;){if(0===--n)return r.target;r=r.parent}return E.fail("Failed to find the parent of "+z.getMSTAdministration(t)+" at depth "+e)}function g(t){return z.getMSTAdministration(t).root.target}function m(t){return z.getMSTAdministration(t).path}function _(t){return V.splitJsonPath(z.getMSTAdministration(t).path)}function P(t){return z.getMSTAdministration(t).isRoot}function T(t,e){var n=z.getMSTAdministration(t).resolve(e);return n?n.target:void 0}function A(t,e){var n=z.getMSTAdministration(t).resolve(e,!1);if(void 0!==n)return n?n.target:void 0}function j(t,e){return z.getRelativePathForNodes(z.getMSTAdministration(t),z.getMSTAdministration(e))}function S(t,e){void 0===e&&(e=!0);var n=z.getMSTAdministration(t);return n.type.create(n.snapshot,e===!0?n.root._environment:e===!1?void 0:e)}function O(t){return z.getMSTAdministration(t).detach(),t}function w(t){var e=z.getMSTAdministration(t);e.isRoot?e.die():e.parent.removeChild(e.subpath)}function M(t){return z.getMSTAdministration(t).isAlive}function C(t,e){z.getMSTAdministration(t).addDisposer(e)}function x(t){var e=z.getMSTAdministration(t),n=e.root._environment;return E.invariant(!!n,"Node '"+e+"' is not part of state tree that was initialized with an environment. Environment can be passed as second argumentt to .create()"),n}function k(t,e){var n=z.getMSTAdministration(t);n.getChildMSTs().forEach(function(t){var n=(t[0],t[1]);k(n.target,e)}),e(n.target)}function F(t,e){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];var i=t.create(e);return c(i,n),y(i)}Object.defineProperty(e,"__esModule",{value:!0});var R=n(14),I=n(4),z=n(6),V=n(9),E=n(1);e.addMiddleware=r,e.onPatch=i,e.onSnapshot=o,e.applyPatch=a,e.applyPatches=s,e.recordPatches=u,e.applyActions=c,e.recordActions=p,e.protect=f,e.unprotect=l,e.isProtected=h,e.applySnapshot=d,e.getSnapshot=y,e.hasParent=v,e.getParent=b,e.getRoot=g,e.getPath=m,e.getPathParts=_,e.isRoot=P,e.resolve=T,e.tryResolve=A,e.getRelativePath=j,e.clone=S,e.detach=O,e.destroy=w,e.isAlive=M,e.addDisposer=C,e.getEnv=x,e.walk=k,e.testActions=F},function(t,e){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function t(t){this.name=t}return t.prototype.initializePrototype=function(t){},t.prototype.initialize=function(t,e){},t.prototype.willChange=function(t){return null},t.prototype.didChange=function(t){},t.prototype.serialize=function(t,e){},t.prototype.deserialize=function(t,e){},t}();e.Property=n},function(t,e){"use strict";function n(t){return t.replace(/~/g,"~1").replace(/\//g,"~0")}function r(t){return t.replace(/~0/g,"\\").replace(/~1/g,"~")}function i(t){return 0===t.length?"":"/"+t.map(n).join("/")}function o(t){var e=t.split("/").map(r);return""===e[0]?e.slice(1):e}Object.defineProperty(e,"__esModule",{value:!0}),e.escapeJsonPath=n,e.unescapeJsonPath=r,e.joinJsonPath=i,e.splitJsonPath=o},function(t,e,n){"use strict";function r(){return p.getMSTAdministration(this).snapshot}var i=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.defineProperty(e,"__esModule",{value:!0});var o=n(4),a=n(3),s=n(1),u=n(2),c=function(t){function e(e){var n=t.call(this,e)||this;return n.create=o.action(n.name,n.create),n}return i(e,t),e.prototype.create=function(t,e,n,i){var o=this;void 0===t&&(t=this.getDefaultSnapshot()),void 0===e&&(e=void 0),void 0===n&&(n=null),void 0===i&&(i=""),u.typecheck(this,t);var a=this.createNewInstance(),c=new f.MSTAdministration(n,i,a,this,e),p=!0;try{return c.pseudoAction(function(){o.finalizeNewInstance(a,t)}),s.addReadOnlyProp(a,"toJSON",r),c.fireHook("afterCreate"),n&&c.fireHook("afterAttach"),p=!1,a}finally{p&&(c._isAlive=!1)}},e.prototype.validate=function(t,e){return t&&"object"==typeof t?p.isMST(t)?p.getType(t)===this?u.typeCheckSuccess():u.typeCheckFailure(e,t):this.isValidSnapshot(t,e):u.typeCheckFailure(e,t)},e}(a.Type);e.ComplexType=c;var p=n(6),f=n(15)},function(t,e,n){"use strict";function r(){return h.getMSTAdministration(this).toString()}function i(t,e,n){var r="string"==typeof t?t:"AnonymousModel",i="string"==typeof t?e:t,o="string"==typeof t?n:e;return new M(r,i,o||{})}function o(t){var e=d.isType(t)?t:h.getType(t);return s(e)?e.baseModel:{}}function a(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];console.warn("[mobx-state-tree] `extend` is an experimental feature and it's behavior will probably change in the future");var n="string"==typeof t[0]?t.slice(1):t,r="string"==typeof t[0]?t[0]:n.map(function(t){return t.name}).join("_");return i(r,l.extend.apply(null,[{}].concat(n.map(o))))}function s(t){return d.isType(t)&&t.isObjectFactory===!0}function u(t){return t instanceof M?t.identifierAttribute:t instanceof P.Late?t.definition().identifierAttribute:null}var c=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),p=this&&this.__decorate||function(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};Object.defineProperty(e,"__esModule",{value:!0});var f=n(4),l=n(1),h=n(5),d=n(3),y=n(2),v=n(10),b=n(12),g=n(13),m=n(19),_=n(16),P=n(17),T=n(28),A=n(29),j=n(27),S=n(30),O=n(26),w=n(31),M=function(t){function e(e,n,i){var o=t.call(this,e)||this;return o.isObjectFactory=!0,o.props={},o.identifierAttribute=null,o.didChange=function(t){o.props[t.name].didChange(t)},Object.freeze(n),Object.freeze(i),o.baseModel=n,o.baseActions=i,l.invariant(/^\w[\w\d_]*$/.test(e),"Typename should be a valid identifier: "+e),o.modelConstructor=new Function("return function "+e+" (){}")(),o.modelConstructor.prototype.toString=r,o.parseModelProps(),o.forAllProps(function(t){return t.initializePrototype(o.modelConstructor.prototype)}),o}return c(e,t),e.prototype.createNewInstance=function(){var t=new this.modelConstructor;return f.extendShallowObservable(t,{}),t},e.prototype.finalizeNewInstance=function(t,e){var n=this;f.intercept(t,function(t){return n.willChange(t)}),f.observe(t,this.didChange),this.forAllProps(function(n){return n.initialize(t,e)})},e.prototype.willChange=function(t){var e=h.getMSTAdministration(t.object);return e.assertWritable(),this.props[t.name].willChange(t)},e.prototype.parseModelProps=function(){var t=this,e=t.baseModel,n=t.baseActions;for(var r in e)if(l.hasOwnProperty(e,r)){var i=Object.getOwnPropertyDescriptor(e,r);if("get"in i){this.props[r]=new j.ComputedProperty(r,i.get,i.set);continue}var o=i.value;if(null===o)l.fail("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(_.isIdentifierFactory(o))l.invariant(!this.identifierAttribute,"Cannot define property '"+r+"' as object identifier, property '"+this.identifierAttribute+"' is already defined as identifier property"),this.identifierAttribute=r,this.props[r]=new T.IdentifierProperty(r,o.primitiveType);else if(l.isPrimitive(o)){var a=b.getPrimitiveFactoryFromValue(o);this.props[r]=new S.ValueProperty(r,g.optional(a,o))}else d.isType(o)?this.props[r]=new S.ValueProperty(r,o):m.isReferenceFactory(o)?this.props[r]=new A.ReferenceProperty(r,o.targetType,o.basePath):"function"==typeof o?this.props[r]=new w.ViewProperty(r,o):"object"==typeof o?l.fail("In property '"+r+"': base model's should not contain complex values: '"+o+"'"):l.fail("Unexpected value for property '"+r+"'")}for(var r in n)if(l.hasOwnProperty(n,r)){var o=n[r];r in this.baseModel&&l.fail("Property '"+r+"' was also defined as action. Actions and properties should not collide"),"function"==typeof o?this.props[r]=new O.ActionProperty(r,o):l.fail("Unexpected value for action '"+r+"'. Expected function, got "+typeof o)}},e.prototype.getChildMSTs=function(t){var e=[];return this.forAllProps(function(n){n instanceof S.ValueProperty&&h.maybeMST(t.target[n.name],function(t){return e.push([n.name,t])})}),e},e.prototype.getChildMST=function(t,e){return h.maybeMST(t.target[e],l.identity,l.nothing)},e.prototype.serialize=function(t){var e={};return this.forAllProps(function(n){return n.serialize(t.target,e)}),e},e.prototype.applyPatchLocally=function(t,e,n){l.invariant("replace"===n.op||"add"===n.op),t.target[e]=n.value},e.prototype.applySnapshot=function(t,e){var n=this;t.pseudoAction(function(){for(var r in n.props)n.props[r].deserialize(t.target,e)})},e.prototype.getChildType=function(t){return this.props[t].type},e.prototype.isValidSnapshot=function(t,e){var n=this;return l.isPlainObject(t)?y.flattenTypeErrors(Object.keys(this.props).map(function(r){return n.props[r].validate(t,e)})):y.typeCheckFailure(e,t)},e.prototype.forAllProps=function(t){var e=this;Object.keys(this.props).forEach(function(n){return t(e.props[n])})},e.prototype.describe=function(){var t=this;return"{ "+Object.keys(this.props).map(function(e){var n=t.props[e];return n instanceof S.ValueProperty?e+": "+n.type.describe():n instanceof T.IdentifierProperty?e+": identifier":""}).filter(Boolean).join("; ")+" }"},e.prototype.getDefaultSnapshot=function(){return{}},e.prototype.removeChild=function(t,e){t.target[e]=null},e}(v.ComplexType);p([f.action],M.prototype,"applySnapshot",null),e.ObjectType=M,e.model=i,e.extend=a,e.isObjectFactory=s,e.getIdentifierAttribute=u},function(t,e,n){"use strict";function r(t){switch(typeof t){case"string":return e.string;case"number":return e.number;case"boolean":return e.boolean;case"object":if(t instanceof Date)return e.DatePrimitive}return u.fail("Cannot determine primtive type from value "+t)}function i(t){return t instanceof c}var o=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.defineProperty(e,"__esModule",{value:!0});var a=n(3),s=n(2),u=n(1),c=function(t){function e(e,n){var r=t.call(this,e)||this;return r.checker=n,r}return o(e,t),e.prototype.describe=function(){return this.name},e.prototype.create=function(t){return u.invariant(u.isPrimitive(t),"Not a primitive: '"+t+"'"),u.invariant(this.checker(t),"Value is not assignable to '"+this.name+"'"),t},e.prototype.validate=function(t,e){return u.isPrimitive(t)&&this.checker(t)?s.typeCheckSuccess():s.typeCheckFailure(e,t)},Object.defineProperty(e.prototype,"identifierAttribute",{get:function(){return null},enumerable:!0,configurable:!0}),e}(a.Type);e.CoreType=c,e.string=new c("string",function(t){return"string"==typeof t}),e.number=new c("number",function(t){return"number"==typeof t}),e.boolean=new c("boolean",function(t){return"boolean"==typeof t}),e.DatePrimitive=new c("Date",function(t){return t instanceof Date}),e.getPrimitiveFactoryFromValue=r,e.isPrimitiveType=i},function(t,e,n){"use strict";function r(t,e){var n="function"==typeof e?e():e,r=u.isMST(n)?u.getMSTAdministration(n).snapshot:n;return a.typecheck(t,r),new s(t,e)}var i=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.defineProperty(e,"__esModule",{value:!0});var o=n(3),a=n(2),s=function(t){function e(e,n){var r=t.call(this,e.name)||this;return r.type=e,r.defaultValue=n,r}return i(e,t),e.prototype.describe=function(){return this.type.describe()+"?"},e.prototype.create=function(t){if("undefined"==typeof t){var e="function"==typeof this.defaultValue?this.defaultValue():this.defaultValue,n=u.isMST(e)?u.getMSTAdministration(e).snapshot:e;return this.type.create(n)}return this.type.create(t)},e.prototype.validate=function(t,e){return void 0===t||this.type.is(t)?a.typeCheckSuccess():a.typeCheckFailure(e,t)},Object.defineProperty(e.prototype,"identifierAttribute",{get:function(){return this.type.identifierAttribute},enumerable:!0,configurable:!0}),e}(o.Type);e.OptionalValue=s,e.optional=r;var u=n(6)},function(t,e,n){"use strict";function r(t){return t.object[t.name].apply(t.object,t.args)}function i(t){for(var e=t.middlewares.slice(),n=t;n.parent;)n=n.parent,e=e.concat(n.middlewares);return e}function o(t,e){function n(t){var e=o.shift();return e?e(t,n):r(t)}var o=i(t);return o.length?n(e):r(e)}function a(t,e){var n=f.action(t,e),r=function(){var e=l.getMSTAdministration(this);if(e.assertAlive(),e.isRunningAction())return n.apply(this,arguments);var r={name:t,object:e.target,args:d.argsToArray(arguments)},i=e.root;i._isRunningAction=!0;try{return o(e,r)}finally{i._isRunningAction=!1}};return d.createNamedFunction(t,r)}function s(t,e,n,r){if(d.isPrimitive(r))return r;if(l.isMST(r)){var i=l.getMSTAdministration(r);if(t.root!==i.root)throw new Error("Argument "+n+" that was passed to action '"+e+"' is a model that is not part of the same state tree. Consider passing a snapshot or some representative ID instead");return{$ref:l.getRelativePathForNodes(t,l.getMSTAdministration(r))}}if("function"==typeof r)throw new Error("Argument "+n+" that was passed to action '"+e+"' should be a primitive, model object or plain object, received a function");if("object"==typeof r&&!d.isPlainObject(r)&&!Array.isArray(r))throw new Error("Argument "+n+" that was passed to action '"+e+"' should be a primitive, model object or plain object, received a "+(r&&r.constructor?r.constructor.name:"Complex Object"));if(f.isObservable(r))throw new Error("Argument "+n+" that was passed to action '"+e+"' should be a primitive, model object or plain object, received an mobx observable.");try{return JSON.stringify(r),r}catch(t){throw new Error("Argument "+n+" that was passed to action '"+e+"' is not serializable.")}}function u(t,e){if("object"==typeof e){var n=Object.keys(e);if(1===n.length&&"$ref"===n[0])return h.resolve(t.target,e.$ref)}return e}function c(t,e){var n=h.tryResolve(t,e.path||"");if(!n)return d.fail("Invalid action path: "+(e.path||""));var r=l.getMSTAdministration(n);return d.invariant("function"==typeof n[e.name],"Action '"+e.name+"' does not exist in '"+r.path+"'"),n[e.name].apply(n,e.args?e.args.map(function(t){return u(r,t)}):[])}function p(t,e){return h.addMiddleware(t,function(n,r){var i=l.getMSTAdministration(n.object);return e({name:n.name,path:l.getRelativePathForNodes(l.getMSTAdministration(t),i),args:n.args.map(function(t,e){return s(i,n.name,e,t)})}),r(n)})}Object.defineProperty(e,"__esModule",{value:!0});var f=n(4);e.createActionInvoker=a,e.applyAction=c,e.onAction=p;var l=n(6),h=n(7),d=n(1)},function(t,e,n){"use strict";var r=this&&this.__decorate||function(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};Object.defineProperty(e,"__esModule",{value:!0});var i=n(4),o=n(2),a=n(6),s=n(1),u=n(9),c=n(11),p=n(10),f=1,l=function(){function t(t,e,n,r,o){var a=this;this.nodeId=++f,this._parent=null,this.subpath="",this.isProtectionEnabled=!0,this._environment=void 0,this._isRunningAction=!1,this._isAlive=!0,this._isDetaching=!1,this.middlewares=[],this.snapshotSubscribers=[],this.patchSubscribers=[],this.disposers=[],s.invariant(r instanceof p.ComplexType,"Uh oh"),s.addHiddenFinalProp(n,"$treenode",this),this._parent=t,this.subpath=e,this.type=r,this.target=n,this._environment=o;var u=i.reaction(function(){return a.snapshot},function(t){a.snapshotSubscribers.forEach(function(e){return e(t)})});u.onError(function(t){throw t}),this.addDisposer(u)}return Object.defineProperty(t.prototype,"path",{get:function(){return this.parent?this.parent.path+"/"+u.escapeJsonPath(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}),Object.defineProperty(t.prototype,"isAlive",{get:function(){return this._isAlive},enumerable:!0,configurable:!0}),t.prototype.die=function(){this._isDetaching||(h.walk(this.target,function(t){return a.getMSTAdministration(t).aboutToDie()}),h.walk(this.target,function(t){return a.getMSTAdministration(t).finalizeDeath()}))},t.prototype.aboutToDie=function(){this.disposers.splice(0).forEach(function(t){return t()}),this.fireHook("beforeDestroy")},t.prototype.finalizeDeath=function(){var t=this,e=this.path;s.addReadOnlyProp(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.target,"$mobx",{get:function(){s.fail("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||s.fail(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 Object.freeze(this.type.serialize(this))},enumerable:!0,configurable:!0}),t.prototype.onSnapshot=function(t){return s.registerEventHandler(this.snapshotSubscribers,t)},t.prototype.applySnapshot=function(t){return o.typecheck(this.type,t),this.type.applySnapshot(this,t)},t.prototype.applyPatch=function(t){var e=u.splitJsonPath(t.path),n=this.resolvePath(e.slice(0,-1));n.pseudoAction(function(){n.applyPatchLocally(e[e.length-1],t)})},t.prototype.applyPatchLocally=function(t,e){this.assertWritable(),this.type.applyPatchLocally(this,t,e)},t.prototype.onPatch=function(t){return s.registerEventHandler(this.patchSubscribers,t)},t.prototype.emitPatch=function(t,e){if(this.patchSubscribers.length){var n=s.extend({},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&&s.fail("A node cannot exists twice in the state tree. Failed to add "+this+" to path '"+t.path+"/"+e+"'."),!this._parent&&t&&t.root===this&&s.fail("A state tree is not allowed to contain itself. Cannot assign "+this+" to path '"+t.path+"/"+e+"'"),!this._parent&&this._environment&&s.fail("A state tree that has been initialized with an environment cannot be made part of another state tree."),this.parent&&!t?this.die():(this._parent=t,this.subpath=e||"",this.fireHook("afterAttach")))},t.prototype.addDisposer=function(t){this.disposers.unshift(t)},t.prototype.reconcileChildren=function(t,e,n,r){var i=this,u=new Array(n.length),p={},f={},l=c.getIdentifierAttribute(t);e.forEach(function(t){if(t){if(l){var e=t[l];e&&(f[e]=t)}a.isMST(t)&&(p[a.getMSTAdministration(t).nodeId]=t)}}),n.forEach(function(e,n){var c=""+r[n];if(a.isMST(e)){var h=a.getMSTAdministration(e);if(h.assertAlive(),h.parent&&(h.parent!==i||!p[h.nodeId]))return s.fail("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 '"+i.path+"/"+c+"', but it lives already at '"+h.path+"'");p[h.nodeId]=void 0,h.setParent(i,c),u[n]=e}else if(l&&s.isMutable(e)){o.typecheck(t,e);var d=e[l],y=f[d],h=y&&a.getMSTAdministration(y);y&&h.type.is(e)?(p[h.nodeId]=void 0,h.setParent(i,c),h.applySnapshot(e),u[n]=y):u[n]=t.create(e,void 0,i,c)}else o.typecheck(t,e),u[n]=t.create(e,void 0,i,c)});for(var h in p)p[h]&&a.getMSTAdministration(p[h]).die();return u},t.prototype.resolve=function(t,e){return void 0===e&&(e=!0),this.resolvePath(u.splitJsonPath(t),e)},t.prototype.resolvePath=function(t,e){void 0===e&&(e=!0),this.assertAlive();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;n=n.getChildMST(t[r])}if(null===n)return e?s.fail("Could not resolve '"+t[r]+"' in '"+u.joinJsonPath(t.slice(0,r-1))+"', path of the patch does not resolve"):void 0}return n},t.prototype.isRunningAction=function(){return!!this._isRunningAction||!this.isRoot&&this.parent.isRunningAction()},t.prototype.addMiddleWare=function(t){return s.registerEventHandler(this.middlewares,t)},t.prototype.getChildMST=function(t){return this.assertAlive(),this.type.getChildMST(this,t)},t.prototype.getChildMSTs=function(){return this.type.getChildMSTs(this)},t.prototype.getChildType=function(t){return this.type.getChildType(t)},Object.defineProperty(t.prototype,"isProtected",{get:function(){for(var t=this;t;){if(t.isProtectionEnabled===!1)return!1;t=t.parent}return!0},enumerable:!0,configurable:!0}),t.prototype.pseudoAction=function(t){var e=this._isRunningAction;this._isRunningAction=!0,t(),this._isRunningAction=e},t.prototype.assertWritable=function(){this.assertAlive(),!this.isRunningAction()&&this.isProtected&&s.fail("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(){s.invariant(this._isAlive),this.isRoot||(this.fireHook("beforeDetach"),this._environment=this.root._environment,this._isDetaching=!0,this.parent.removeChild(this.subpath),this._parent=null,this.subpath="",this._isDetaching=!1)},t.prototype.fireHook=function(t){var e=this.target[t];"function"==typeof e&&e.apply(this.target)},t.prototype.toString=function(){var t=c.getIdentifierAttribute(this.type),e=t?"("+t+": "+this.target[t]+")":"";return this.type.name+"@"+(this.path||"<root>")+e+(this.isAlive?"":"[dead]")},t}();r([i.observable],l.prototype,"_parent",void 0),r([i.observable],l.prototype,"subpath",void 0),r([i.computed],l.prototype,"path",null),r([i.computed],l.prototype,"snapshot",null),r([i.action],l.prototype,"applyPatch",null),e.MSTAdministration=l;var h=n(7)},function(t,e,n){"use strict";function r(t){return void 0===t&&(t=o.string),t!==o.string&&t!==o.number&&a.fail("Only 'types.number' and 'types.string' are acceptable as type specification for identifiers"),{isIdentifier:!0,primitiveType:t}}function i(t){return"object"==typeof t&&t&&t.isIdentifier===!0}Object.defineProperty(e,"__esModule",{value:!0});var o=n(12),a=n(1);e.identifier=r,e.isIdentifierFactory=i},function(t,e,n){"use strict";function r(t,e){var n="string"==typeof t?t:"<late>",r="string"==typeof t?e:t;return new u(n,r)}var i=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.defineProperty(e,"__esModule",{value:!0});var o=n(1),a=n(3),s=n(2),u=function(t){ | ||
function e(e,n){var r=t.call(this,e)||this;return r._subType=null,o.invariant("function"==typeof n&&0===n.length,"Invalid late type, expected a function with zero arguments that returns a type, got: "+n),r.definition=n,r}return i(e,t),Object.defineProperty(e.prototype,"subType",{get:function(){return null===this._subType&&(this._subType=this.definition()),this._subType},enumerable:!0,configurable:!0}),e.prototype.create=function(t,e){return this.subType.create(t,e)},e.prototype.describe=function(){return this.subType.name},e.prototype.validate=function(t,e){return this.subType.is(t)?s.typeCheckSuccess():s.typeCheckFailure(e,t)},Object.defineProperty(e.prototype,"identifierAttribute",{get:function(){return this.subType.identifierAttribute},enumerable:!0,configurable:!0}),e}(a.Type);e.Late=u,e.late=r},function(t,e,n){"use strict";function r(t){return a.invariant(a.isPrimitive(t),"Literal types can be built only on top of primitives"),new u(t)}var i=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.defineProperty(e,"__esModule",{value:!0});var o=n(3),a=n(1),s=n(2),u=function(t){function e(e){var n=t.call(this,""+e)||this;return n.value=e,n}return i(e,t),e.prototype.create=function(t){return s.typecheck(this,t),this.value},e.prototype.describe=function(){return JSON.stringify(this.value)},e.prototype.validate=function(t,e){return a.isPrimitive(t)&&t===this.value?s.typeCheckSuccess():s.typeCheckFailure(e,t)},Object.defineProperty(e.prototype,"identifierAttribute",{get:function(){return null},enumerable:!0,configurable:!0}),e}(o.Type);e.Literal=u,e.literal=r},function(t,e){"use strict";function n(t,e){return void 0===e&&(e=""),{targetType:t,basePath:e,isReference:!0}}function r(t){return t.isReference===!0}Object.defineProperty(e,"__esModule",{value:!0}),e.reference=n,e.isReferenceFactory=r},function(t,e,n){"use strict";function r(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var r=o.isType(t)?null:t,i=o.isType(t)?e.concat(t):e,a=i.map(function(t){return t.name}).join(" | ");return new u(a,i,r)}var i=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.defineProperty(e,"__esModule",{value:!0});var o=n(3),a=n(2),s=n(1),u=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 i(e,t),e.prototype.describe=function(){return"("+this.types.map(function(t){return t.describe()}).join(" | ")+")"},e.prototype.create=function(t){if(a.typecheck(this,t),null!==this.dispatcher)return this.dispatcher(t).create(t);var e=this.types.filter(function(e){return e.is(t)});return e.length>1?s.fail("Ambiguos snapshot "+JSON.stringify(t)+" for union "+this.name+". Please provide a dispatch in the union declaration."):e[0].create(t)},e.prototype.validate=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?a.typeCheckFailure(e,t,"Multiple types are applicable and no dispatch method is defined for the union"):r.length<1?a.typeCheckFailure(e,t,"No type is applicable and no dispatch method is defined for the union").concat(a.flattenTypeErrors(n)):a.typeCheckSuccess()},Object.defineProperty(e.prototype,"identifierAttribute",{get:function(){var t=this.types[0].identifierAttribute;return t&&this.types.every(function(e){return e.identifierAttribute===t})?t:null},enumerable:!0,configurable:!0}),e}(o.Type);e.Union=u,e.union=r},function(t,e,n){"use strict";var r=this&&this.__decorate||function(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};Object.defineProperty(e,"__esModule",{value:!0});var i=n(4),o=n(6),a=n(1),s=n(11),u=n(2),c=n(7),p=function(){function t(t,e,n,r){return this.owner=t,this.type=e,this.basePath=n,this.identifier=null,n&&(this.targetIdAttribute=s.getIdentifierAttribute(e)||"",!this.targetIdAttribute)?a.fail("Cannot create reference to path '"+n+"'; the targeted type, "+e.describe()+", does not specify an identifier property"):void this.setNewValue(r)}return Object.defineProperty(t.prototype,"get",{get:function(){var t=this,e=t.targetIdAttribute,n=t.identifier;if(null===n)return null;if(this.basePath){var r=c.resolve(this.owner,this.basePath);if(i.isObservableArray(r))return r.find(function(t){return t&&t[e]===n});if(i.isObservableMap(r)){var o=r.get(n);return a.invariant(!o||o[e]===n,"Inconsistent collection, the map entry under key '"+n+"' should have property '"+e+"' set to value '"+n),o}return a.fail("References with base paths should point to either an `array` or `map` collection")}return c.resolve(this.owner,n)},enumerable:!0,configurable:!0}),t.prototype.setNewValue=function(t){if(t)if(o.isMST(t)){u.typecheck(this.type,t);var e=o.getMSTAdministration(this.owner),n=o.getMSTAdministration(t);this.targetIdAttribute?this.identifier=t[this.targetIdAttribute]:(a.invariant(e.root===n.root,"Failed to assign a value to a reference; the value should already be part of the same model tree"),this.identifier=o.getRelativePathForNodes(e,n))}else this.targetIdAttribute?(a.invariant("string"==typeof t,"Expected an identifier, got: "+t),this.identifier=t):(a.invariant("object"==typeof t&&"string"==typeof t.$ref,"Expected a reference in the format `{ $ref: ... }`, got: "+t),this.identifier=t.$ref);else this.identifier=null},t.prototype.serialize=function(){return this.basePath?this.identifier:this.identifier?{$ref:this.identifier}:null},t}();r([i.observable],p.prototype,"identifier",void 0),r([i.computed],p.prototype,"get",null),e.Reference=p},function(t,e,n){"use strict";function r(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];p.invariant(s.isMST(t),"Expected model object");var r={getState:function(){return u.getSnapshot(t)},dispatch:function(e){o(e,a.slice(),function(e){return c.applyAction(t,i(e))})},subscribe:function(e){return u.onSnapshot(t,e)}},a=e.map(function(t){return t(r)});return r}function i(t){var e=p.extend({},t);return delete e.type,{name:t.type,args:[e]}}function o(t,e,n){function r(t){var i=e.shift();i?i(r)(t):n(t)}r(t)}function a(t,e){var n=t.connectViaExtension(),r=!1;n.subscribe(function(n){var i=t.extractState(n);i&&(r=!0,u.applySnapshot(e,i),r=!1)}),c.onAction(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,u.getSnapshot(e))}})}Object.defineProperty(e,"__esModule",{value:!0});var s=n(5),u=n(7),c=n(14),p=n(1);e.asReduxStore=r,e.connectReduxDevtools=a},function(t,e,n){"use strict";function r(){return c.getMSTAdministration(this)+"("+this.length+" items)"}function i(t){return new d(t.name+"[]",t)}function o(t){return f.isType(t)&&t.isArrayFactory===!0}var a=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),s=this&&this.__decorate||function(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};Object.defineProperty(e,"__esModule",{value:!0});var u=n(4),c=n(5),p=n(1),f=n(3),l=n(2),h=n(10);e.arrayToString=r;var d=function(t){function e(e,n){var r=t.call(this,e)||this;return r.isArrayFactory=!0,r.subType=n,r}return a(e,t),e.prototype.describe=function(){return this.subType.describe()+"[]"},e.prototype.createNewInstance=function(){var t=u.observable.shallowArray();return p.addHiddenFinalProp(t,"toString",r),t},e.prototype.finalizeNewInstance=function(t,e){var n=this;u.intercept(t,function(t){return n.willChange(t)}),u.observe(t,this.didChange),c.getMSTAdministration(t).applySnapshot(e)},e.prototype.getChildMSTs=function(t){var e=t.target,n=[];return e.forEach(function(t,e){c.maybeMST(t,function(t){n.push([""+e,t])})}),n},e.prototype.getChildMST=function(t,e){var n=t.target,r=parseInt(e,10);return r<n.length?c.maybeMST(n[r],p.identity,p.nothing):null},e.prototype.willChange=function(t){var e=c.getMSTAdministration(t.object);switch(e.assertWritable(),t.type){case"update":if(t.newValue===t.object[t.index])return null;t.newValue=e.reconcileChildren(this.subType,[t.object[t.index]],[t.newValue],[t.index])[0];break;case"splice":var n=t.index,r=t.removedCount,i=t.added,o=t.object;t.added=e.reconcileChildren(this.subType,o.slice(n,n+r),i,i.map(function(t,e){return n+e}));for(var a=function(t){c.maybeMST(o[t],function(n){n.setParent(e,""+(t+i.length-r))})},s=n+r;s<o.length;s++)a(s)}return t},e.prototype.serialize=function(t){var e=t.target;return e.map(c.valueToSnapshot)},e.prototype.didChange=function(t){var e=c.getMSTAdministration(t.object);switch(t.type){case"update":return void e.emitPatch({op:"replace",path:""+t.index,value:c.valueToSnapshot(t.newValue)},e);case"splice":for(var n=t.index+t.removedCount-1;n>=t.index;n--)e.emitPatch({op:"remove",path:""+n},e);for(var n=0;n<t.addedCount;n++)e.emitPatch({op:"add",path:""+(t.index+n),value:c.valueToSnapshot(t.added[n])},e);return}},e.prototype.applyPatchLocally=function(t,e,n){var r=t.target,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)}},e.prototype.applySnapshot=function(t,e){t.pseudoAction(function(){var n=t.target;n.replace(e)})},e.prototype.getChildType=function(t){return this.subType},e.prototype.isValidSnapshot=function(t,e){var n=this;return Array.isArray(t)?l.flattenTypeErrors(t.map(function(t,r){return n.subType.validate(t,l.getContextForPath(e,""+r,n.subType))})):l.typeCheckFailure(e,t)},e.prototype.getDefaultSnapshot=function(){return[]},e.prototype.removeChild=function(t,e){t.target.splice(parseInt(e,10),1)},Object.defineProperty(e.prototype,"identifierAttribute",{get:function(){return null},enumerable:!0,configurable:!0}),e}(h.ComplexType);s([u.action],d.prototype,"applySnapshot",null),e.ArrayType=d,e.array=i,e.isArrayFactory=o},function(t,e,n){"use strict";function r(){return f.getMSTAdministration(this)+"("+this.size+" items)"}function i(t){var e=c.getIdentifierAttribute(f.getMSTAdministration(this).type.subType);return l.invariant(!!e,"Map.put is only supported if the subtype has an idenfier attribute"),l.invariant(!!t,"Map.put cannot be used to set empty values"),this.set(t[e],t),this}function o(t){return new v("map<string, "+t.name+">",t)}function a(t){return h.isType(t)&&t.isMapFactory===!0}var s=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),u=this&&this.__decorate||function(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};Object.defineProperty(e,"__esModule",{value:!0});var c=n(11),p=n(4),f=n(5),l=n(1),h=n(3),d=n(2),y=n(10);e.mapToString=r;var v=function(t){function e(e,n){var r=t.call(this,e)||this;return r.isMapFactory=!0,r.subType=n,r}return s(e,t),e.prototype.describe=function(){return"Map<string, "+this.subType.describe()+">"},e.prototype.createNewInstance=function(){var t=p.observable.shallowMap();return l.addHiddenFinalProp(t,"put",i),l.addHiddenFinalProp(t,"toString",r),t},e.prototype.finalizeNewInstance=function(t,e){var n=this;p.intercept(t,function(t){return n.willChange(t)}),p.observe(t,this.didChange),f.getMSTAdministration(t).applySnapshot(e)},e.prototype.getChildMSTs=function(t){var e=[];return t.target.forEach(function(t,n){f.maybeMST(t,function(t){e.push([n,t])})}),e},e.prototype.getChildMST=function(t,e){var n=t.target;return n.has(e)?f.maybeMST(n.get(e),l.identity,l.nothing):null},e.prototype.willChange=function(t){var e=f.getMSTAdministration(t.object);e.assertWritable();var n=c.getIdentifierAttribute(e.type);switch(n&&t.newValue&&"object"==typeof t.newValue&&t.newValue[n]!==t.name&&l.fail("A map of objects containing an identifier should always store the object under their own identifier. Trying to store key '"+t.name+"', but expected: '"+t.newValue[n]+"'"),t.type){case"update":var r=t.newValue,i=t.object.get(t.name);if(r===i)return null;t.newValue=e.reconcileChildren(this.subType,[i],[r],[t.name])[0];break;case"add":var r=t.newValue;t.newValue=e.reconcileChildren(this.subType,[],[r],[t.name])[0];break;case"delete":var i=t.object.get(t.name);e.reconcileChildren(this.subType,[i],[],[])}return t},e.prototype.serialize=function(t){var e=t.target,n={};return e.forEach(function(t,e){n[e]=f.valueToSnapshot(t)}),n},e.prototype.didChange=function(t){var e=f.getMSTAdministration(t.object);switch(t.type){case"update":case"add":return void e.emitPatch({op:"add"===t.type?"add":"replace",path:f.escapeJsonPath(t.name),value:f.valueToSnapshot(t.newValue)},e);case"delete":return void e.emitPatch({op:"remove",path:f.escapeJsonPath(t.name)},e)}},e.prototype.applyPatchLocally=function(t,e,n){var r=t.target;switch(n.op){case"add":case"replace":r.set(e,n.value);break;case"remove":r.delete(e)}},e.prototype.applySnapshot=function(t,e){var n=this;t.pseudoAction(function(){var r=t.target,i=c.getIdentifierAttribute(n.subType),o={};r.keys().forEach(function(t){o[t]=!1}),Object.keys(e).forEach(function(t){var n=e[t];i&&n&&"object"==typeof n&&t!==n[i]&&l.fail("A map of objects containing an identifier should always store the object under their own identifier. Trying to store key '"+t+"', but expected: '"+n[i]+"'"),t in o&&!l.isPrimitive(n)?(o[t]=!0,f.maybeMST(r.get(t),function(t){t.applySnapshot(n)},function(){r.set(t,n)})):r.set(t,n)}),Object.keys(o).forEach(function(t){o[t]===!1&&r.delete(t)})})},e.prototype.getChildType=function(t){return this.subType},e.prototype.isValidSnapshot=function(t,e){var n=this;return l.isPlainObject(t)?d.flattenTypeErrors(Object.keys(t).map(function(r){return n.subType.validate(t[r],d.getContextForPath(e,r,n.subType))})):d.typeCheckFailure(e,t)},e.prototype.getDefaultSnapshot=function(){return{}},e.prototype.removeChild=function(t,e){t.target.delete(e)},Object.defineProperty(e.prototype,"identifierAttribute",{get:function(){return null},enumerable:!0,configurable:!0}),e}(y.ComplexType);u([p.action],v.prototype,"applySnapshot",null),e.MapType=v,e.map=o,e.isMapFactory=a},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=n(24),i=n(23),o=n(16),a=n(11),s=n(19),u=n(20),c=n(13),p=n(18),f=n(33),l=n(34),h=n(32),d=n(12),y=n(17);e.types={model:a.model,extend:a.extend,reference:s.reference,union:u.union,optional:c.optional,literal:p.literal,maybe:f.maybe,refinement:l.refinement,string:d.string,boolean:d.boolean,number:d.number,Date:d.DatePrimitive,map:r.map,array:i.array,frozen:h.frozen,identifier:o.identifier,late:y.late}},function(t,e,n){"use strict";var r=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.defineProperty(e,"__esModule",{value:!0});var i=n(1),o=n(5),a=n(8),s=n(2),u=function(t){function e(e,n){var r=t.call(this,e)||this;return r.invokeAction=o.createActionInvoker(e,n),r}return r(e,t),e.prototype.initialize=function(t){i.addHiddenFinalProp(t,this.name,this.invokeAction.bind(t))},e.prototype.validate=function(t,e){return this.name in t?s.typeCheckFailure(s.getContextForPath(e,this.name),t[this.name],"Action properties should not be provided in the snapshot"):s.typeCheckSuccess()},e}(a.Property);e.ActionProperty=u},function(t,e,n){"use strict";var r=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.defineProperty(e,"__esModule",{value:!0});var i=n(4),o=n(8),a=n(2),s=function(t){function e(e,n,r){var i=t.call(this,e)||this;return i.getter=n,i.setter=r,i}return r(e,t),e.prototype.initializePrototype=function(t){Object.defineProperty(t,this.name,i.computed(t,this.name,{get:this.getter,set:this.setter,configurable:!0,enumerable:!1}))},e.prototype.validate=function(t,e){return this.name in t?a.typeCheckFailure(a.getContextForPath(e,this.name),t[this.name],"Computed properties should not be provided in the snapshot"):a.typeCheckSuccess()},e}(o.Property);e.ComputedProperty=s},function(t,e,n){"use strict";var r=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.defineProperty(e,"__esModule",{value:!0});var i=n(5),o=n(4),a=n(8),s=n(1),u=n(2),c=function(t){function e(e,n){var r=t.call(this,e)||this;return r.subtype=n,r}return r(e,t),e.prototype.initialize=function(t,e){o.extendObservable(t,(n={},n[this.name]=o.observable.ref(e[this.name]),n));var n},e.prototype.willChange=function(t){var e=t.newValue;"number"==typeof e||s.isValidIdentifier(e)||s.fail("Not a valid identifier: '"+e),u.typecheck(this.subtype,e);var n=i.getMSTAdministration(t.object);n.assertWritable();var r=t.object[this.name];return void 0!==r&&r!==e&&s.fail("It is not allowed to change the identifier of an object, got: '"+e+"' but expected: '"+r+"'"),t},e.prototype.serialize=function(t,e){var n=t[this.name];this.isValidIdentifier(n)||s.fail("Object does not have a valid identifier yet: '"+n+"'"),e[this.name]=n},e.prototype.deserialize=function(t,e){t[this.name]=e[this.name]},e.prototype.validate=function(t,e){return this.isValidIdentifier(t[this.name])?u.typeCheckSuccess():u.typeCheckFailure(u.getContextForPath(e,this.name,this.subtype),t[this.name],"The provided identifier is not valid")},e.prototype.isValidIdentifier=function(t){return!("number"!=typeof t&&!s.isValidIdentifier(t))&&this.subtype.is(t)},e}(a.Property);e.IdentifierProperty=c},function(t,e,n){"use strict";var r=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.defineProperty(e,"__esModule",{value:!0});var i=n(8),o=n(1),a=n(5),s=n(21),u=n(2),c=function(t){function e(e,n,r){var i=t.call(this,e)||this;return i.type=n,i.basePath=r,i}return r(e,t),e.prototype.initialize=function(t,e){var n=new s.Reference(t,this.type,this.basePath,e[this.name]);o.addHiddenFinalProp(t,this.name+"$value",n);var r=this;Object.defineProperty(t,this.name,{get:function(){return a.getMSTAdministration(this).assertAlive(),n.get},set:function(t){var e=a.getMSTAdministration(this);e.assertWritable();var i=n.identifier;n.setNewValue(t),n.identifier!==i&&e.emitPatch({op:"replace",path:a.escapeJsonPath(r.name),value:n.serialize},e)}}),t[this.name]=e[this.name]},e.prototype.serialize=function(t,e){e[this.name]=t[this.name+"$value"].serialize()},e.prototype.deserialize=function(t,e){t[this.name+"$value"].setNewValue(e[this.name])},e.prototype.validate=function(t,e){return this.name in t?u.typeCheckSuccess():u.typeCheckFailure(u.getContextForPath(e,this.name,this.type),void 0,"Reference is required.")},e}(i.Property);e.ReferenceProperty=c},function(t,e,n){"use strict";var r=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.defineProperty(e,"__esModule",{value:!0});var i=n(4),o=n(8),a=n(5),s=n(2),u=function(t){function e(e,n){var r=t.call(this,e)||this;return r.type=n,r}return r(e,t),e.prototype.initializePrototype=function(t){i.observable.ref(t,this.name,{value:void 0})},e.prototype.initialize=function(t,e){t[this.name]=this.type.create(e[this.name])},e.prototype.willChange=function(t){var e=a.getMSTAdministration(t.object);return t.newValue=e.reconcileChildren(this.type,[t.object[t.name]],[t.newValue],[t.name])[0],t},e.prototype.didChange=function(t){var e=a.getMSTAdministration(t.object);e.emitPatch({op:"replace",path:a.escapeJsonPath(this.name),value:a.valueToSnapshot(t.newValue)},e)},e.prototype.serialize=function(t,e){e[this.name]=a.valueToSnapshot(t[this.name])},e.prototype.deserialize=function(t,e){var n=this;a.maybeMST(t[this.name],function(t){t.applySnapshot(e[n.name])},function(){t[n.name]=e[n.name]})},e.prototype.validate=function(t,e){return this.type.validate(t[this.name],s.getContextForPath(e,this.name,this.type))},e}(o.Property);e.ValueProperty=u},function(t,e,n){"use strict";function r(t,e){var n=function(){var t=this,n=arguments,r=s.getMSTAdministration(this);return r.assertAlive(),o.extras.allowStateChanges(!1,function(){return e.apply(t,n)})};return a.createNamedFunction(t,n)}var i=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.defineProperty(e,"__esModule",{value:!0});var o=n(4),a=n(1),s=n(5),u=n(8),c=n(2),p=function(t){function e(e,n){var i=t.call(this,e)||this;return i.invokeView=r(e,n),i}return i(e,t),e.prototype.initialize=function(t){a.addHiddenFinalProp(t,this.name,this.invokeView.bind(t))},e.prototype.validate=function(t,e){return this.name in t?c.typeCheckFailure(c.getContextForPath(e,this.name),t[this.name],"View properties should not be provided in the snapshot"):c.typeCheckSuccess()},e}(u.Property);e.ViewProperty=p,e.createViewInvoker=r},function(t,e,n){"use strict";function r(t){return Object.freeze(t),s.isPlainObject(t)&&Object.keys(t).forEach(function(e){Object.isFrozen(t[e])||r(t[e])}),t}var i=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.defineProperty(e,"__esModule",{value:!0});var o=n(3),a=n(2),s=n(1),u=function(t){function e(){return t.call(this,"frozen")||this}return i(e,t),e.prototype.describe=function(){return"<any immutable value>"},e.prototype.create=function(t){return s.invariant(s.isSerializable(t),"Given value should be serializable"),s.isMutable(t)?r(t):t},e.prototype.validate=function(t,e){return s.isSerializable(t)?a.typeCheckSuccess():a.typeCheckFailure(e,t)},Object.defineProperty(e.prototype,"identifierAttribute",{get:function(){return null},enumerable:!0,configurable:!0}),e}(o.Type);e.Frozen=u,e.frozen=new u},function(t,e,n){"use strict";function r(t){return i.union(s,t)}Object.defineProperty(e,"__esModule",{value:!0});var i=n(20),o=n(18),a=n(13),s=a.optional(o.literal(null),null);e.maybe=r},function(t,e,n){"use strict";function r(t,e,n){var r=e.create();return a.invariant(n(s.isMST(r)?s.getMSTAdministration(r).snapshot:r),"Default value for refinement type "+t+" does not pass the predicate."),new c(t,e,n)}var i=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.defineProperty(e,"__esModule",{value:!0});var o=n(3),a=n(1),s=n(5),u=n(2),c=function(t){function e(e,n,r){var i=t.call(this,e)||this;return i.type=n,i.predicate=r,i}return i(e,t),e.prototype.describe=function(){return this.name},e.prototype.create=function(t){var e=this.type.create(t),n=s.isMST(e)?s.getMSTAdministration(e).snapshot:e;return a.invariant(this.is(n),"Value "+JSON.stringify(n)+" is not assignable to type "+this.name),e},e.prototype.validate=function(t,e){return this.type.is(t)&&this.predicate(t)?u.typeCheckSuccess():u.typeCheckFailure(e,t)},Object.defineProperty(e.prototype,"identifierAttribute",{get:function(){return this.type.identifierAttribute},enumerable:!0,configurable:!0}),e}(o.Type);e.Refinement=c,e.refinement=r}])}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("mobx")):"function"==typeof define&&define.amd?define(["mobx"],e):"object"==typeof exports?exports.mobxStateTree=e(require("mobx")):t.mobxStateTree=e(t.mobx)}(this,function(t){return function(t){function e(r){if(n[r])return n[r].exports;var i=n[r]={exports:{},id:r,loaded:!1};return t[r].call(i.exports,i,i.exports,e),i.loaded=!0,i.exports}var n={};return e.m=t,e.c=n,e.p="",e(0)}([function(t,e,n){"use strict";function r(t){for(var n in t)e.hasOwnProperty(n)||(e[n]=t[n])}Object.defineProperty(e,"__esModule",{value:!0}),n(3),n(10);var i=n(24);e.types=i.types,r(n(7)),r(n(9));var o=n(5);e.isMST=o.isMST,e.getType=o.getType,e.getChildType=o.getChildType,e.onAction=o.onAction,e.applyAction=o.applyAction;var a=n(21);e.asReduxStore=a.asReduxStore,e.connectReduxDevtools=a.connectReduxDevtools},function(t,e){"use strict";function n(t){throw void 0===t&&(t="Illegal state"),new Error("[mobx-state-tree] "+t)}function r(t){return t}function i(){return null}function o(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 a(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];for(var r=0;r<e.length;r++){var i=e[r];for(var o in i){var a=Object.getOwnPropertyDescriptor(i,o);"get"in a?Object.defineProperty(t,o,a):t[o]=i[o]}}return t}function s(t){if(null===t||"object"!=typeof t)return!1;var e=Object.getPrototypeOf(t);return e===Object.prototype||null===e}function u(t){return!(null===t||"object"!=typeof t||t instanceof Date||t instanceof RegExp)}function c(t){return null===t||void 0===t||"string"==typeof t||"number"==typeof t||"boolean"==typeof t||t instanceof Date}function p(t){return"function"!=typeof t}function f(t,e,n){Object.defineProperty(t,e,{enumerable:!1,writable:!1,configurable:!0,value:n})}function l(t,e,n){Object.defineProperty(t,e,{enumerable:!1,writable:!0,configurable:!0,value:n})}function h(t,e,n){Object.defineProperty(t,e,{enumerable:!0,writable:!1,configurable:!0,value:n})}function d(t,e){return t.push(e),function(){var n=t.indexOf(e);n!==-1&&t.splice(n,1)}}function y(t,e){return m.call(t,e)}function v(t){for(var e=new Array(t.length),n=0;n<t.length;n++)e[n]=t[n];return e}function b(t,e){return new Function("f","return function "+t+"() { return f.apply(this, arguments)}")(e)}function g(t){return"string"==typeof t&&/^[a-z0-9_-]+$/i.test(t)}Object.defineProperty(e,"__esModule",{value:!0}),e.EMPTY_ARRAY=Object.freeze([]),e.fail=n,e.identity=r,e.nothing=i,e.extend=o,e.extendKeepGetter=a,e.isPlainObject=s,e.isMutable=u,e.isPrimitive=c,e.isSerializable=p,e.addHiddenFinalProp=f,e.addHiddenWritableProp=l,e.addReadOnlyProp=h,e.registerEventHandler=d;var m=Object.prototype.hasOwnProperty;e.hasOwnProperty=y,e.argsToArray=v,e.createNamedFunction=b,e.isValidIdentifier=g},function(t,e,n){"use strict";function r(t){var e=t.value,n=t.context[t.context.length-1].type,r=t.context.map(function(t){var e=t.path;return e}).filter(function(t){return t.length>0}).join("/"),i=r.length>0?'at path "/'+r+'" ':"",o=f.maybeMST(e,function(t){return"value of type "+t.type.name+":"},function(){return p.isPrimitive(e)?"value":"snapshot"}),a=n&&f.isMST(e)&&n.is(f.getMSTAdministration(e).snapshot);return""+i+o+" "+d(e)+" is not assignable "+(n?"to type: `"+n.name+"`":"")+(t.message?" ("+t.message+")":"")+(n?l.isPrimitiveType(n)||n instanceof h.OptionalValue&&l.isPrimitiveType(n.type)?".":", expected an instance of `"+n.name+"` or a snapshot like `"+n.describe()+"` instead."+(a?" (Note that a snapshot of the provided value is compatible with the targeted type)":""):".")}function i(t){return[{type:t,path:""}]}function o(t,e,n){return t.concat([{path:e,type:n}])}function a(){return p.EMPTY_ARRAY}function s(t,e,n){return[{context:t,value:e,message:n}]}function u(t){return t.reduce(function(t,e){return t.concat(e)},[])}function c(t,e){var n=t.validate(e,[{path:"",type:t}]);n.length>0&&p.fail("Error while converting "+d(e)+" to `"+t.name+"`:\n"+n.map(r).join("\n"))}Object.defineProperty(e,"__esModule",{value:!0});var p=n(1),f=n(6),l=n(12),h=n(13),d=function(t){return f.isMST(t)?"<"+t+">":"`"+JSON.stringify(t)+"`"};e.getDefaultContext=i,e.getContextForPath=o,e.typeCheckSuccess=a,e.typeCheckFailure=s,e.flattenTypeErrors=u,e.typecheck=c},function(t,e,n){"use strict";function r(t){return"object"==typeof t&&t&&t.isType===!0}Object.defineProperty(e,"__esModule",{value:!0});var i;!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"}(i=e.TypeFlags||(e.TypeFlags={})),e.isType=r;var o=function(){function t(t){this.isType=!0,this.name=t}return t.prototype.is=function(t){return 0===this.validate(t,[{path:"",type:this}]).length},Object.defineProperty(t.prototype,"Type",{get:function(){return a.fail("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 a.fail("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}),t}();e.Type=o;var a=n(1)},function(e,n){e.exports=t},function(t,e,n){"use strict";function r(t){for(var n in t)e.hasOwnProperty(n)||(e[n]=t[n])}Object.defineProperty(e,"__esModule",{value:!0}),r(n(6)),r(n(15)),r(n(14)),r(n(9)),r(n(7))},function(t,e,n){"use strict";function r(t){return a(t).type}function i(t,e){return a(t).getChildType(e)}function o(t){return t&&t.$treenode}function a(t){return o(t)?t.$treenode:f.fail("element has no Node")}function s(t,e,n){if(f.isMutable(t)&&o(t)){var r=a(t);return e(r,r.target)}return n?n(t):t}function u(t){return t instanceof Date?{$treetype:"Date",time:t.toJSON()}:o(t)?a(t).snapshot:f.isSerializable(t)?t:void f.fail("Unable to convert value to snapshot.")}function c(t,e){t.root!==e.root&&f.fail("Cannot calculate relative path: objects '"+t+"' and '"+e+"' are not part of the same object tree");for(var n=p.splitJsonPath(t.path),r=p.splitJsonPath(e.path),i=0;i<n.length&&n[i]===r[i];i++);return n.slice(i).map(function(t){return".."}).join("/")+p.joinJsonPath(r.slice(i))}Object.defineProperty(e,"__esModule",{value:!0});var p=n(9);e.getType=r,e.getChildType=i,e.isMST=o,e.getMSTAdministration=a,e.maybeMST=s,e.valueToSnapshot=u,e.getRelativePathForNodes=c;var f=n(1)},function(t,e,n){"use strict";function r(t,e){var n=z.getMSTAdministration(t);return n.isProtectionEnabled||console.warn("It is recommended to protect the state tree before attaching action middleware, as otherwise it cannot be guaranteed that all changes are passed through middleware. See `protect`"),n.addMiddleWare(e)}function i(t,e){return z.getMSTAdministration(t).onPatch(e)}function o(t,e){return z.getMSTAdministration(t).onSnapshot(e)}function a(t,e){return z.getMSTAdministration(t).applyPatch(e)}function s(t,e){var n=z.getMSTAdministration(t);I.runInAction(function(){e.forEach(function(t){return n.applyPatch(t)})})}function u(t){var e={patches:[],stop:function(){return n()},replay:function(t){s(t,e.patches)}},n=i(t,function(t){e.patches.push(t)});return e}function c(t,e){I.runInAction(function(){e.forEach(function(e){return R.applyAction(t,e)})})}function p(t){var e={actions:[],stop:function(){return n()},replay:function(t){c(t,e.actions)}},n=R.onAction(t,e.actions.push.bind(e.actions));return e}function f(t){z.getMSTAdministration(t).isProtectionEnabled=!0}function l(t){z.getMSTAdministration(t).isProtectionEnabled=!1}function h(t){return z.getMSTAdministration(t).isProtectionEnabled}function d(t,e){return z.getMSTAdministration(t).applySnapshot(e)}function y(t){return z.getMSTAdministration(t).snapshot}function v(t,e){void 0===e&&(e=1),e<0&&E.fail("Invalid depth: "+e+", should be >= 1");for(var n=z.getMSTAdministration(t).parent;n;){if(0===--e)return!0;n=n.parent}return!1}function b(t,e){void 0===e&&(e=1),e<0&&E.fail("Invalid depth: "+e+", should be >= 1");for(var n=e,r=z.getMSTAdministration(t).parent;r;){if(0===--n)return r.target;r=r.parent}return E.fail("Failed to find the parent of "+z.getMSTAdministration(t)+" at depth "+e)}function g(t){return z.getMSTAdministration(t).root.target}function m(t){return z.getMSTAdministration(t).path}function _(t){return V.splitJsonPath(z.getMSTAdministration(t).path)}function P(t){return z.getMSTAdministration(t).isRoot}function T(t,e){var n=z.getMSTAdministration(t).resolve(e);return n?n.target:void 0}function A(t,e){var n=z.getMSTAdministration(t).resolve(e,!1);if(void 0!==n)return n?n.target:void 0}function j(t,e){return z.getRelativePathForNodes(z.getMSTAdministration(t),z.getMSTAdministration(e))}function O(t,e){void 0===e&&(e=!0);var n=z.getMSTAdministration(t);return n.type.create(n.snapshot,e===!0?n.root._environment:e===!1?void 0:e)}function S(t){return z.getMSTAdministration(t).detach(),t}function w(t){var e=z.getMSTAdministration(t);e.isRoot?e.die():e.parent.removeChild(e.subpath)}function M(t){return z.getMSTAdministration(t).isAlive}function C(t,e){z.getMSTAdministration(t).addDisposer(e)}function x(t){var e=z.getMSTAdministration(t),n=e.root._environment;return n||E.fail("Node '"+e+"' is not part of state tree that was initialized with an environment. Environment can be passed as second argumentt to .create()"),n}function F(t,e){var n=z.getMSTAdministration(t);n.getChildMSTs().forEach(function(t){var n=(t[0],t[1]);F(n.target,e)}),e(n.target)}function k(t,e){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];var i=t.create(e);return c(i,n),y(i)}Object.defineProperty(e,"__esModule",{value:!0});var R=n(14),I=n(4),z=n(6),V=n(9),E=n(1);e.addMiddleware=r,e.onPatch=i,e.onSnapshot=o,e.applyPatch=a,e.applyPatches=s,e.recordPatches=u,e.applyActions=c,e.recordActions=p,e.protect=f,e.unprotect=l,e.isProtected=h,e.applySnapshot=d,e.getSnapshot=y,e.hasParent=v,e.getParent=b,e.getRoot=g,e.getPath=m,e.getPathParts=_,e.isRoot=P,e.resolve=T,e.tryResolve=A,e.getRelativePath=j,e.clone=O,e.detach=S,e.destroy=w,e.isAlive=M,e.addDisposer=C,e.getEnv=x,e.walk=F,e.testActions=k},function(t,e){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=function(){function t(t){this.name=t}return t.prototype.initializePrototype=function(t){},t.prototype.initialize=function(t,e){},t.prototype.willChange=function(t){return null},t.prototype.didChange=function(t){},t.prototype.serialize=function(t,e){},t.prototype.deserialize=function(t,e){},t}();e.Property=n},function(t,e){"use strict";function n(t){return t.replace(/~/g,"~1").replace(/\//g,"~0")}function r(t){return t.replace(/~0/g,"\\").replace(/~1/g,"~")}function i(t){return 0===t.length?"":"/"+t.map(n).join("/")}function o(t){var e=t.split("/").map(r);return""===e[0]?e.slice(1):e}Object.defineProperty(e,"__esModule",{value:!0}),e.escapeJsonPath=n,e.unescapeJsonPath=r,e.joinJsonPath=i,e.splitJsonPath=o},function(t,e,n){"use strict";function r(){return p.getMSTAdministration(this).snapshot}var i=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.defineProperty(e,"__esModule",{value:!0});var o=n(4),a=n(3),s=n(1),u=n(2),c=function(t){function e(e){var n=t.call(this,e)||this;return n.create=o.action(n.name,n.create),n}return i(e,t),e.prototype.create=function(t,e,n,i){var o=this;void 0===t&&(t=this.getDefaultSnapshot()),void 0===e&&(e=void 0),void 0===n&&(n=null),void 0===i&&(i=""),u.typecheck(this,t);var a=this.createNewInstance(),c=new f.MSTAdministration(n,i,a,this,e),p=!0;try{return c.pseudoAction(function(){o.finalizeNewInstance(a,t)}),s.addReadOnlyProp(a,"toJSON",r),c.fireHook("afterCreate"),n&&c.fireHook("afterAttach"),p=!1,a}finally{p&&(c._isAlive=!1)}},e.prototype.validate=function(t,e){return t&&"object"==typeof t?p.isMST(t)?p.getType(t)===this?u.typeCheckSuccess():u.typeCheckFailure(e,t):this.isValidSnapshot(t,e):u.typeCheckFailure(e,t)},e}(a.Type);e.ComplexType=c;var p=n(6),f=n(15)},function(t,e,n){"use strict";function r(){return d.getMSTAdministration(this).toString()}function i(t,e,n){var r="string"==typeof t?t:"AnonymousModel",i="string"==typeof t?e:t,o="string"==typeof t?n:e;return new M(r,i,o||{})}function o(t){var e=y.isType(t)?t:d.getType(t);return u(e)?e.baseModel:{}}function a(t){var e=y.isType(t)?t:d.getType(t);return u(e)?e.baseActions:{}}function s(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];console.warn("[mobx-state-tree] `extend` is an experimental feature and it's behavior will probably change in the future");var n="string"==typeof t[0]?t.slice(1):t,r="string"==typeof t[0]?t[0]:n.map(function(t){return t.name}).join("_"),s=h.extendKeepGetter.apply(null,[{}].concat(n.map(o))),u=h.extend.apply(null,[{}].concat(n.map(a)));return i(r,s,u)}function u(t){return y.isType(t)&&(t.flags&y.TypeFlags.Object)>0}function c(t){return u(t)?t.identifierAttribute:null}var p=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),f=this&&this.__decorate||function(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};Object.defineProperty(e,"__esModule",{value:!0});var l=n(4),h=n(1),d=n(5),y=n(3),v=n(2),b=n(10),g=n(12),m=n(13),_=n(18),P=n(16),T=n(27),A=n(28),j=n(26),O=n(29),S=n(25),w=n(30),M=function(t){function e(e,n,i){var o=t.call(this,e)||this;return o.isObjectFactory=!0,o.flags=y.TypeFlags.Object,o.props={},o.identifierAttribute=null,o.didChange=function(t){o.props[t.name].didChange(t)},Object.freeze(n),Object.freeze(i),o.baseModel=n,o.baseActions=i,/^\w[\w\d_]*$/.test(e)||h.fail("Typename should be a valid identifier: "+e),o.modelConstructor=new Function("return function "+e+" (){}")(),o.modelConstructor.prototype.toString=r,o.parseModelProps(),o.forAllProps(function(t){return t.initializePrototype(o.modelConstructor.prototype)}),o}return p(e,t),e.prototype.createNewInstance=function(){var t=new this.modelConstructor;return l.extendShallowObservable(t,{}),t},e.prototype.finalizeNewInstance=function(t,e){var n=this;l.intercept(t,function(t){return n.willChange(t)}),l.observe(t,this.didChange),this.forAllProps(function(n){return n.initialize(t,e)})},e.prototype.willChange=function(t){var e=d.getMSTAdministration(t.object);return e.assertWritable(),this.props[t.name].willChange(t)},e.prototype.parseModelProps=function(){var t=this,e=t.baseModel,n=t.baseActions;for(var r in e)if(h.hasOwnProperty(e,r)){var i=Object.getOwnPropertyDescriptor(e,r);if("get"in i){this.props[r]=new j.ComputedProperty(r,i.get,i.set);continue}var o=i.value;if(null===o)h.fail("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(P.isIdentifierFactory(o))this.identifierAttribute&&h.fail("Cannot define property '"+r+"' as object identifier, property '"+this.identifierAttribute+"' is already defined as identifier property"),this.identifierAttribute=r,this.props[r]=new T.IdentifierProperty(r,o.primitiveType);else if(h.isPrimitive(o)){var a=g.getPrimitiveFactoryFromValue(o);this.props[r]=new O.ValueProperty(r,m.optional(a,o))}else y.isType(o)?this.props[r]=new O.ValueProperty(r,o):_.isReferenceFactory(o)?this.props[r]=new A.ReferenceProperty(r,o.targetType,o.basePath):"function"==typeof o?this.props[r]=new w.ViewProperty(r,o):"object"==typeof o?h.fail("In property '"+r+"': base model's should not contain complex values: '"+o+"'"):h.fail("Unexpected value for property '"+r+"'")}for(var r in n)if(h.hasOwnProperty(n,r)){var o=n[r];r in this.baseModel&&h.fail("Property '"+r+"' was also defined as action. Actions and properties should not collide"),"function"==typeof o?this.props[r]=new S.ActionProperty(r,o):h.fail("Unexpected value for action '"+r+"'. Expected function, got "+typeof o)}},e.prototype.getChildMSTs=function(t){var e=[];return this.forAllProps(function(n){n instanceof O.ValueProperty&&d.maybeMST(t.target[n.name],function(t){return e.push([n.name,t])})}),e},e.prototype.getChildMST=function(t,e){return d.maybeMST(t.target[e],h.identity,h.nothing)},e.prototype.serialize=function(t){var e={};return this.forAllProps(function(n){return n.serialize(t.target,e)}),e},e.prototype.applyPatchLocally=function(t,e,n){"replace"!==n.op&&"add"!==n.op&&h.fail("object does not support operation "+n.op),t.target[e]=n.value},e.prototype.applySnapshot=function(t,e){var n=this;t.pseudoAction(function(){for(var r in n.props)n.props[r].deserialize(t.target,e)})},e.prototype.getChildType=function(t){return this.props[t].type},e.prototype.isValidSnapshot=function(t,e){var n=this;return h.isPlainObject(t)?v.flattenTypeErrors(Object.keys(this.props).map(function(r){return n.props[r].validate(t,e)})):v.typeCheckFailure(e,t)},e.prototype.forAllProps=function(t){var e=this;Object.keys(this.props).forEach(function(n){return t(e.props[n])})},e.prototype.describe=function(){var t=this;return"{ "+Object.keys(this.props).map(function(e){var n=t.props[e];return n instanceof O.ValueProperty?e+": "+n.type.describe():n instanceof T.IdentifierProperty?e+": identifier":""}).filter(Boolean).join("; ")+" }"},e.prototype.getDefaultSnapshot=function(){return{}},e.prototype.removeChild=function(t,e){t.target[e]=null},e}(b.ComplexType);f([l.action],M.prototype,"applySnapshot",null),e.ObjectType=M,e.model=i,e.extend=s,e.isObjectFactory=u,e.getIdentifierAttribute=c},function(t,e,n){"use strict";function r(t){switch(typeof t){case"string":return e.string;case"number":return e.number;case"boolean":return e.boolean;case"object":if(t instanceof Date)return e.DatePrimitive}return u.fail("Cannot determine primtive type from value "+t)}function i(t){return(t.flags&(a.TypeFlags.String|a.TypeFlags.Number|a.TypeFlags.Boolean|a.TypeFlags.Date))>0}var o=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.defineProperty(e,"__esModule",{value:!0});var a=n(3),s=n(2),u=n(1),c=function(t){function e(e,n,r){var i=t.call(this,e)||this;return i.flags=n,i.checker=r,i}return o(e,t),e.prototype.describe=function(){return this.name},e.prototype.create=function(t){return u.isPrimitive(t)||u.fail("Not a primitive: '"+t+"'"),this.checker(t)||u.fail("Value is not assignable to '"+this.name+"'"),t},e.prototype.validate=function(t,e){return u.isPrimitive(t)&&this.checker(t)?s.typeCheckSuccess():s.typeCheckFailure(e,t)},Object.defineProperty(e.prototype,"identifierAttribute",{get:function(){return null},enumerable:!0,configurable:!0}),e}(a.Type);e.CoreType=c,e.string=new c("string",a.TypeFlags.String,function(t){return"string"==typeof t}),e.number=new c("number",a.TypeFlags.Number,function(t){return"number"==typeof t}),e.boolean=new c("boolean",a.TypeFlags.Boolean,function(t){return"boolean"==typeof t}),e.DatePrimitive=new c("Date",a.TypeFlags.Date,function(t){return t instanceof Date}),e.getPrimitiveFactoryFromValue=r,e.isPrimitiveType=i},function(t,e,n){"use strict";function r(t,e){var n="function"==typeof e?e():e,r=u.isMST(n)?u.getMSTAdministration(n).snapshot:n;return a.typecheck(t,r),new s(t,e)}var i=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.defineProperty(e,"__esModule",{value:!0});var o=n(3),a=n(2),s=function(t){function e(e,n){var r=t.call(this,e.name)||this;return r.type=e,r.defaultValue=n,r}return i(e,t),Object.defineProperty(e.prototype,"flags",{get:function(){return this.type.flags|o.TypeFlags.Optional},enumerable:!0,configurable:!0}),e.prototype.describe=function(){return this.type.describe()+"?"},e.prototype.create=function(t){if("undefined"==typeof t){var e="function"==typeof this.defaultValue?this.defaultValue():this.defaultValue,n=u.isMST(e)?u.getMSTAdministration(e).snapshot:e;return this.type.create(n)}return this.type.create(t)},e.prototype.validate=function(t,e){return void 0===t||this.type.is(t)?a.typeCheckSuccess():a.typeCheckFailure(e,t)},Object.defineProperty(e.prototype,"identifierAttribute",{get:function(){return this.type.identifierAttribute},enumerable:!0,configurable:!0}),e}(o.Type);e.OptionalValue=s,e.optional=r;var u=n(6)},function(t,e,n){"use strict";function r(t){return t.object[t.name].apply(t.object,t.args)}function i(t){for(var e=t.middlewares.slice(),n=t;n.parent;)n=n.parent,e=e.concat(n.middlewares);return e}function o(t,e){function n(t){var e=o.shift();return e?e(t,n):r(t)}var o=i(t);return o.length?n(e):r(e)}function a(t,e){var n=f.action(t,e),r=function(){var e=l.getMSTAdministration(this);if(e.assertAlive(),e.isRunningAction())return n.apply(this,arguments);var r={name:t,object:e.target,args:d.argsToArray(arguments)},i=e.root;i._isRunningAction=!0;try{return o(e,r)}finally{i._isRunningAction=!1}};return d.createNamedFunction(t,r)}function s(t,e,n,r){if(d.isPrimitive(r))return r;if(l.isMST(r)){var i=l.getMSTAdministration(r);if(t.root!==i.root)throw new Error("Argument "+n+" that was passed to action '"+e+"' is a model that is not part of the same state tree. Consider passing a snapshot or some representative ID instead");return{$ref:l.getRelativePathForNodes(t,l.getMSTAdministration(r))}}if("function"==typeof r)throw new Error("Argument "+n+" that was passed to action '"+e+"' should be a primitive, model object or plain object, received a function");if("object"==typeof r&&!d.isPlainObject(r)&&!Array.isArray(r))throw new Error("Argument "+n+" that was passed to action '"+e+"' should be a primitive, model object or plain object, received a "+(r&&r.constructor?r.constructor.name:"Complex Object"));if(f.isObservable(r))throw new Error("Argument "+n+" that was passed to action '"+e+"' should be a primitive, model object or plain object, received an mobx observable.");try{return JSON.stringify(r),r}catch(t){throw new Error("Argument "+n+" that was passed to action '"+e+"' is not serializable.")}}function u(t,e){if("object"==typeof e){var n=Object.keys(e);if(1===n.length&&"$ref"===n[0])return h.resolve(t.target,e.$ref)}return e}function c(t,e){var n=h.tryResolve(t,e.path||"");if(!n)return d.fail("Invalid action path: "+(e.path||""));var r=l.getMSTAdministration(n);return"function"!=typeof n[e.name]&&d.fail("Action '"+e.name+"' does not exist in '"+r.path+"'"),n[e.name].apply(n,e.args?e.args.map(function(t){return u(r,t)}):[])}function p(t,e){return h.addMiddleware(t,function(n,r){var i=l.getMSTAdministration(n.object);return e({name:n.name,path:l.getRelativePathForNodes(l.getMSTAdministration(t),i),args:n.args.map(function(t,e){return s(i,n.name,e,t)})}),r(n)})}Object.defineProperty(e,"__esModule",{value:!0});var f=n(4);e.createActionInvoker=a,e.applyAction=c,e.onAction=p;var l=n(6),h=n(7),d=n(1)},function(t,e,n){"use strict";var r=this&&this.__decorate||function(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};Object.defineProperty(e,"__esModule",{value:!0});var i=n(4),o=n(2),a=n(6),s=n(1),u=n(9),c=n(11),p=n(10),f=1,l=function(){function t(t,e,n,r,o){var a=this;this.nodeId=++f,this._parent=null,this.subpath="",this.isProtectionEnabled=!0,this._environment=void 0,this._isRunningAction=!1,this._isAlive=!0,this._isDetaching=!1,this.middlewares=[],this.snapshotSubscribers=[],this.patchSubscribers=[],this.disposers=[],r instanceof p.ComplexType||s.fail("Uh oh"),s.addHiddenFinalProp(n,"$treenode",this),this._parent=t,this.subpath=e,this.type=r,this.target=n,this._environment=o;var u=i.reaction(function(){return a.snapshot},function(t){a.snapshotSubscribers.forEach(function(e){return e(t)})});u.onError(function(t){throw t}),this.addDisposer(u)}return Object.defineProperty(t.prototype,"path",{get:function(){return this.parent?this.parent.path+"/"+u.escapeJsonPath(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}),Object.defineProperty(t.prototype,"isAlive",{get:function(){return this._isAlive},enumerable:!0,configurable:!0}),t.prototype.die=function(){this._isDetaching||(h.walk(this.target,function(t){return a.getMSTAdministration(t).aboutToDie()}),h.walk(this.target,function(t){return a.getMSTAdministration(t).finalizeDeath()}))},t.prototype.aboutToDie=function(){this.disposers.splice(0).forEach(function(t){return t()}),this.fireHook("beforeDestroy")},t.prototype.finalizeDeath=function(){var t=this,e=this.path;s.addReadOnlyProp(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.target,"$mobx",{get:function(){s.fail("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||s.fail(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 Object.freeze(this.type.serialize(this))},enumerable:!0,configurable:!0}),t.prototype.onSnapshot=function(t){return s.registerEventHandler(this.snapshotSubscribers,t)},t.prototype.applySnapshot=function(t){return o.typecheck(this.type,t),this.type.applySnapshot(this,t)},t.prototype.applyPatch=function(t){var e=u.splitJsonPath(t.path),n=this.resolvePath(e.slice(0,-1));n.pseudoAction(function(){n.applyPatchLocally(e[e.length-1],t)})},t.prototype.applyPatchLocally=function(t,e){this.assertWritable(),this.type.applyPatchLocally(this,t,e)},t.prototype.onPatch=function(t){return s.registerEventHandler(this.patchSubscribers,t)},t.prototype.emitPatch=function(t,e){if(this.patchSubscribers.length){var n=s.extend({},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&&s.fail("A node cannot exists twice in the state tree. Failed to add "+this+" to path '"+t.path+"/"+e+"'."),!this._parent&&t&&t.root===this&&s.fail("A state tree is not allowed to contain itself. Cannot assign "+this+" to path '"+t.path+"/"+e+"'"),!this._parent&&this._environment&&s.fail("A state tree that has been initialized with an environment cannot be made part of another state tree."),this.parent&&!t?this.die():(this._parent=t,this.subpath=e||"",this.fireHook("afterAttach")))},t.prototype.addDisposer=function(t){this.disposers.unshift(t)},t.prototype.reconcileChildren=function(t,e,n,r){var i=this,u=new Array(n.length),p={},f={},l=c.getIdentifierAttribute(t);e.forEach(function(t){if(t){if(l){var e=t[l];e&&(f[e]=t)}a.isMST(t)&&(p[a.getMSTAdministration(t).nodeId]=t)}}),n.forEach(function(e,n){var c=""+r[n];if(a.isMST(e)){var h=a.getMSTAdministration(e);if(h.assertAlive(),h.parent&&(h.parent!==i||!p[h.nodeId]))return s.fail("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 '"+i.path+"/"+c+"', but it lives already at '"+h.path+"'");p[h.nodeId]=void 0,h.setParent(i,c),u[n]=e}else if(l&&s.isMutable(e)){o.typecheck(t,e);var d=e[l],y=f[d],h=y&&a.getMSTAdministration(y);y&&h.type.is(e)?(p[h.nodeId]=void 0,h.setParent(i,c),h.applySnapshot(e),u[n]=y):u[n]=t.create(e,void 0,i,c)}else o.typecheck(t,e),u[n]=t.create(e,void 0,i,c)});for(var h in p)p[h]&&a.getMSTAdministration(p[h]).die();return u},t.prototype.resolve=function(t,e){return void 0===e&&(e=!0),this.resolvePath(u.splitJsonPath(t),e)},t.prototype.resolvePath=function(t,e){void 0===e&&(e=!0),this.assertAlive();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;n=n.getChildMST(t[r])}if(null===n)return e?s.fail("Could not resolve '"+t[r]+"' in '"+u.joinJsonPath(t.slice(0,r-1))+"', path of the patch does not resolve"):void 0}return n},t.prototype.isRunningAction=function(){return!!this._isRunningAction||!this.isRoot&&this.parent.isRunningAction()},t.prototype.addMiddleWare=function(t){return s.registerEventHandler(this.middlewares,t)},t.prototype.getChildMST=function(t){return this.assertAlive(),this.type.getChildMST(this,t)},t.prototype.getChildMSTs=function(){return this.type.getChildMSTs(this)},t.prototype.getChildType=function(t){return this.type.getChildType(t)},Object.defineProperty(t.prototype,"isProtected",{get:function(){for(var t=this;t;){if(t.isProtectionEnabled===!1)return!1;t=t.parent}return!0},enumerable:!0,configurable:!0}),t.prototype.pseudoAction=function(t){var e=this._isRunningAction;this._isRunningAction=!0,t(),this._isRunningAction=e},t.prototype.assertWritable=function(){this.assertAlive(),!this.isRunningAction()&&this.isProtected&&s.fail("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||s.fail("Error while detaching, node is not alive."),this.isRoot||(this.fireHook("beforeDetach"),this._environment=this.root._environment,this._isDetaching=!0,this.parent.removeChild(this.subpath),this._parent=null,this.subpath="",this._isDetaching=!1)},t.prototype.fireHook=function(t){var e=this.target[t];"function"==typeof e&&e.apply(this.target)},t.prototype.toString=function(){var t=c.getIdentifierAttribute(this.type),e=t?"("+t+": "+this.target[t]+")":"";return this.type.name+"@"+(this.path||"<root>")+e+(this.isAlive?"":"[dead]")},t}();r([i.observable],l.prototype,"_parent",void 0),r([i.observable],l.prototype,"subpath",void 0),r([i.computed],l.prototype,"path",null),r([i.computed],l.prototype,"snapshot",null),r([i.action],l.prototype,"applyPatch",null),e.MSTAdministration=l;var h=n(7)},function(t,e,n){"use strict";function r(t){return void 0===t&&(t=o.string), | ||
t!==o.string&&t!==o.number&&a.fail("Only 'types.number' and 'types.string' are acceptable as type specification for identifiers"),{isIdentifier:!0,primitiveType:t}}function i(t){return"object"==typeof t&&t&&t.isIdentifier===!0}Object.defineProperty(e,"__esModule",{value:!0});var o=n(12),a=n(1);e.identifier=r,e.isIdentifierFactory=i},function(t,e,n){"use strict";function r(t){return a.isPrimitive(t)||a.fail("Literal types can be built only on top of primitives"),new u(t)}var i=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.defineProperty(e,"__esModule",{value:!0});var o=n(3),a=n(1),s=n(2),u=function(t){function e(e){var n=t.call(this,""+e)||this;return n.flags=o.TypeFlags.Literal,n.value=e,n}return i(e,t),e.prototype.create=function(t){return s.typecheck(this,t),this.value},e.prototype.describe=function(){return JSON.stringify(this.value)},e.prototype.validate=function(t,e){return a.isPrimitive(t)&&t===this.value?s.typeCheckSuccess():s.typeCheckFailure(e,t)},Object.defineProperty(e.prototype,"identifierAttribute",{get:function(){return null},enumerable:!0,configurable:!0}),e}(o.Type);e.Literal=u,e.literal=r},function(t,e){"use strict";function n(t,e){return void 0===e&&(e=""),{targetType:t,basePath:e,isReference:!0}}function r(t){return t.isReference===!0}Object.defineProperty(e,"__esModule",{value:!0}),e.reference=n,e.isReferenceFactory=r},function(t,e,n){"use strict";function r(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var r=o.isType(t)?null:t,i=o.isType(t)?e.concat(t):e,a=i.map(function(t){return t.name}).join(" | ");return new u(a,i,r)}var i=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.defineProperty(e,"__esModule",{value:!0});var o=n(3),a=n(2),s=n(1),u=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 i(e,t),Object.defineProperty(e.prototype,"flags",{get:function(){var t=0;return this.types.forEach(function(e){t|=e.flags}),t},enumerable:!0,configurable:!0}),e.prototype.describe=function(){return"("+this.types.map(function(t){return t.describe()}).join(" | ")+")"},e.prototype.create=function(t,e,n,r){if(void 0===e&&(e=void 0),void 0===n&&(n=null),void 0===r&&(r=""),a.typecheck(this,t),null!==this.dispatcher)return this.dispatcher(t).create(t,e,n,r);var i=this.types.filter(function(e){return e.is(t)});return i.length>1?s.fail("Ambiguos snapshot "+JSON.stringify(t)+" for union "+this.name+". Please provide a dispatch in the union declaration."):i[0].create(t,e,n,r)},e.prototype.validate=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?a.typeCheckFailure(e,t,"Multiple types are applicable and no dispatch method is defined for the union"):r.length<1?a.typeCheckFailure(e,t,"No type is applicable and no dispatch method is defined for the union").concat(a.flattenTypeErrors(n)):a.typeCheckSuccess()},Object.defineProperty(e.prototype,"identifierAttribute",{get:function(){var t=this.types[0].identifierAttribute;return t&&this.types.every(function(e){return e.identifierAttribute===t})?t:null},enumerable:!0,configurable:!0}),e}(o.Type);e.Union=u,e.union=r},function(t,e,n){"use strict";var r=this&&this.__decorate||function(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};Object.defineProperty(e,"__esModule",{value:!0});var i=n(4),o=n(6),a=n(1),s=n(11),u=n(2),c=n(7),p=function(){function t(t,e,n,r){return this.owner=t,this.type=e,this.basePath=n,this.identifier=null,n&&(this.targetIdAttribute=s.getIdentifierAttribute(e)||"",!this.targetIdAttribute)?a.fail("Cannot create reference to path '"+n+"'; the targeted type, "+e.describe()+", does not specify an identifier property"):void this.setNewValue(r)}return Object.defineProperty(t.prototype,"get",{get:function(){var t=this,e=t.targetIdAttribute,n=t.identifier;if(null===n)return null;if(this.basePath){var r=c.resolve(this.owner,this.basePath);if(i.isObservableArray(r))return r.find(function(t){return t&&t[e]===n});if(i.isObservableMap(r)){var o=r.get(n);return o&&o[e]!==n&&a.fail("Inconsistent collection, the map entry under key '"+n+"' should have property '"+e+"' set to value '"+n),o}return a.fail("References with base paths should point to either an `array` or `map` collection")}return c.resolve(this.owner,n)},enumerable:!0,configurable:!0}),t.prototype.setNewValue=function(t){if(t)if(o.isMST(t)){u.typecheck(this.type,t);var e=o.getMSTAdministration(this.owner),n=o.getMSTAdministration(t);this.targetIdAttribute?this.identifier=t[this.targetIdAttribute]:(e.root!==n.root&&a.fail("Failed to assign a value to a reference; the value should already be part of the same model tree"),this.identifier=o.getRelativePathForNodes(e,n))}else this.targetIdAttribute?("string"!=typeof t&&a.fail("Expected an identifier, got: "+t),this.identifier=t):("object"==typeof t&&"string"==typeof t.$ref||a.fail("Expected a reference in the format `{ $ref: ... }`, got: "+t),this.identifier=t.$ref);else this.identifier=null},t.prototype.serialize=function(){return this.basePath?this.identifier:this.identifier?{$ref:this.identifier}:null},t}();r([i.observable],p.prototype,"identifier",void 0),r([i.computed],p.prototype,"get",null),e.Reference=p},function(t,e,n){"use strict";function r(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];s.isMST(t)||p.fail("Expected model object");var r={getState:function(){return u.getSnapshot(t)},dispatch:function(e){o(e,a.slice(),function(e){return c.applyAction(t,i(e))})},subscribe:function(e){return u.onSnapshot(t,e)}},a=e.map(function(t){return t(r)});return r}function i(t){var e=p.extend({},t);return delete e.type,{name:t.type,args:[e]}}function o(t,e,n){function r(t){var i=e.shift();i?i(r)(t):n(t)}r(t)}function a(t,e){var n=t.connectViaExtension(),r=!1;n.subscribe(function(n){var i=t.extractState(n);i&&(r=!0,u.applySnapshot(e,i),r=!1)}),c.onAction(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,u.getSnapshot(e))}})}Object.defineProperty(e,"__esModule",{value:!0});var s=n(5),u=n(7),c=n(14),p=n(1);e.asReduxStore=r,e.connectReduxDevtools=a},function(t,e,n){"use strict";function r(){return c.getMSTAdministration(this)+"("+this.length+" items)"}function i(t){return new d(t.name+"[]",t)}function o(t){return f.isType(t)&&(t.flags&f.TypeFlags.Array)>0}var a=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),s=this&&this.__decorate||function(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};Object.defineProperty(e,"__esModule",{value:!0});var u=n(4),c=n(5),p=n(1),f=n(3),l=n(2),h=n(10);e.arrayToString=r;var d=function(t){function e(e,n){var r=t.call(this,e)||this;return r.isArrayFactory=!0,r.flags=f.TypeFlags.Array,r.subType=n,r}return a(e,t),e.prototype.describe=function(){return this.subType.describe()+"[]"},e.prototype.createNewInstance=function(){var t=u.observable.shallowArray();return p.addHiddenFinalProp(t,"toString",r),t},e.prototype.finalizeNewInstance=function(t,e){var n=this;u.intercept(t,function(t){return n.willChange(t)}),u.observe(t,this.didChange),c.getMSTAdministration(t).applySnapshot(e)},e.prototype.getChildMSTs=function(t){var e=t.target,n=[];return e.forEach(function(t,e){c.maybeMST(t,function(t){n.push([""+e,t])})}),n},e.prototype.getChildMST=function(t,e){var n=t.target,r=parseInt(e,10);return r<n.length?c.maybeMST(n[r],p.identity,p.nothing):null},e.prototype.willChange=function(t){var e=c.getMSTAdministration(t.object);switch(e.assertWritable(),t.type){case"update":if(t.newValue===t.object[t.index])return null;t.newValue=e.reconcileChildren(this.subType,[t.object[t.index]],[t.newValue],[t.index])[0];break;case"splice":var n=t.index,r=t.removedCount,i=t.added,o=t.object;t.added=e.reconcileChildren(this.subType,o.slice(n,n+r),i,i.map(function(t,e){return n+e}));for(var a=function(t){c.maybeMST(o[t],function(n){n.setParent(e,""+(t+i.length-r))})},s=n+r;s<o.length;s++)a(s)}return t},e.prototype.serialize=function(t){var e=t.target;return e.map(c.valueToSnapshot)},e.prototype.didChange=function(t){var e=c.getMSTAdministration(t.object);switch(t.type){case"update":return void e.emitPatch({op:"replace",path:""+t.index,value:c.valueToSnapshot(t.newValue)},e);case"splice":for(var n=t.index+t.removedCount-1;n>=t.index;n--)e.emitPatch({op:"remove",path:""+n},e);for(var n=0;n<t.addedCount;n++)e.emitPatch({op:"add",path:""+(t.index+n),value:c.valueToSnapshot(t.added[n])},e);return}},e.prototype.applyPatchLocally=function(t,e,n){var r=t.target,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)}},e.prototype.applySnapshot=function(t,e){t.pseudoAction(function(){var n=t.target;n.replace(e)})},e.prototype.getChildType=function(t){return this.subType},e.prototype.isValidSnapshot=function(t,e){var n=this;return Array.isArray(t)?l.flattenTypeErrors(t.map(function(t,r){return n.subType.validate(t,l.getContextForPath(e,""+r,n.subType))})):l.typeCheckFailure(e,t)},e.prototype.getDefaultSnapshot=function(){return[]},e.prototype.removeChild=function(t,e){t.target.splice(parseInt(e,10),1)},Object.defineProperty(e.prototype,"identifierAttribute",{get:function(){return null},enumerable:!0,configurable:!0}),e}(h.ComplexType);s([u.action],d.prototype,"applySnapshot",null),e.ArrayType=d,e.array=i,e.isArrayFactory=o},function(t,e,n){"use strict";function r(){return f.getMSTAdministration(this)+"("+this.size+" items)"}function i(t){var e=c.getIdentifierAttribute(f.getMSTAdministration(this).type.subType);return e||l.fail("Map.put is only supported if the subtype has an idenfier attribute"),t||l.fail("Map.put cannot be used to set empty values"),this.set(t[e],t),this}function o(t){return new v("map<string, "+t.name+">",t)}function a(t){return h.isType(t)&&(t.flags&h.TypeFlags.Map)>0}var s=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),u=this&&this.__decorate||function(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};Object.defineProperty(e,"__esModule",{value:!0});var c=n(11),p=n(4),f=n(5),l=n(1),h=n(3),d=n(2),y=n(10);e.mapToString=r;var v=function(t){function e(e,n){var r=t.call(this,e)||this;return r.isMapFactory=!0,r.flags=h.TypeFlags.Map,r.subType=n,r}return s(e,t),e.prototype.describe=function(){return"Map<string, "+this.subType.describe()+">"},e.prototype.createNewInstance=function(){var t=p.observable.shallowMap();return l.addHiddenFinalProp(t,"put",i),l.addHiddenFinalProp(t,"toString",r),t},e.prototype.finalizeNewInstance=function(t,e){var n=this;p.intercept(t,function(t){return n.willChange(t)}),p.observe(t,this.didChange),f.getMSTAdministration(t).applySnapshot(e)},e.prototype.getChildMSTs=function(t){var e=[];return t.target.forEach(function(t,n){f.maybeMST(t,function(t){e.push([n,t])})}),e},e.prototype.getChildMST=function(t,e){var n=t.target;return n.has(e)?f.maybeMST(n.get(e),l.identity,l.nothing):null},e.prototype.willChange=function(t){var e=f.getMSTAdministration(t.object);e.assertWritable();var n=c.getIdentifierAttribute(e.type);switch(n&&t.newValue&&"object"==typeof t.newValue&&t.newValue[n]!==t.name&&l.fail("A map of objects containing an identifier should always store the object under their own identifier. Trying to store key '"+t.name+"', but expected: '"+t.newValue[n]+"'"),t.type){case"update":var r=t.newValue,i=t.object.get(t.name);if(r===i)return null;t.newValue=e.reconcileChildren(this.subType,[i],[r],[t.name])[0];break;case"add":var r=t.newValue;t.newValue=e.reconcileChildren(this.subType,[],[r],[t.name])[0];break;case"delete":var i=t.object.get(t.name);e.reconcileChildren(this.subType,[i],[],[])}return t},e.prototype.serialize=function(t){var e=t.target,n={};return e.forEach(function(t,e){n[e]=f.valueToSnapshot(t)}),n},e.prototype.didChange=function(t){var e=f.getMSTAdministration(t.object);switch(t.type){case"update":case"add":return void e.emitPatch({op:"add"===t.type?"add":"replace",path:f.escapeJsonPath(t.name),value:f.valueToSnapshot(t.newValue)},e);case"delete":return void e.emitPatch({op:"remove",path:f.escapeJsonPath(t.name)},e)}},e.prototype.applyPatchLocally=function(t,e,n){var r=t.target;switch(n.op){case"add":case"replace":r.set(e,n.value);break;case"remove":r.delete(e)}},e.prototype.applySnapshot=function(t,e){var n=this;t.pseudoAction(function(){var r=t.target,i=c.getIdentifierAttribute(n.subType),o={};r.keys().forEach(function(t){o[t]=!1}),Object.keys(e).forEach(function(t){var n=e[t];i&&n&&"object"==typeof n&&t!==n[i]&&l.fail("A map of objects containing an identifier should always store the object under their own identifier. Trying to store key '"+t+"', but expected: '"+n[i]+"'"),t in o&&!l.isPrimitive(n)?f.maybeMST(r.get(t),function(t){t.applySnapshot(n)},function(){r.set(t,n)}):r.set(t,n),o[t]=!0}),Object.keys(o).forEach(function(t){o[t]===!1&&r.delete(t)})})},e.prototype.getChildType=function(t){return this.subType},e.prototype.isValidSnapshot=function(t,e){var n=this;return l.isPlainObject(t)?d.flattenTypeErrors(Object.keys(t).map(function(r){return n.subType.validate(t[r],d.getContextForPath(e,r,n.subType))})):d.typeCheckFailure(e,t)},e.prototype.getDefaultSnapshot=function(){return{}},e.prototype.removeChild=function(t,e){t.target.delete(e)},Object.defineProperty(e.prototype,"identifierAttribute",{get:function(){return null},enumerable:!0,configurable:!0}),e}(y.ComplexType);u([p.action],v.prototype,"applySnapshot",null),e.MapType=v,e.map=o,e.isMapFactory=a},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=n(23),i=n(22),o=n(16),a=n(11),s=n(18),u=n(19),c=n(13),p=n(17),f=n(33),l=n(34),h=n(31),d=n(12),y=n(32);e.types={model:a.model,extend:a.extend,reference:s.reference,union:u.union,optional:c.optional,literal:p.literal,maybe:f.maybe,refinement:l.refinement,string:d.string,boolean:d.boolean,number:d.number,Date:d.DatePrimitive,map:r.map,array:i.array,frozen:h.frozen,identifier:o.identifier,late:y.late}},function(t,e,n){"use strict";var r=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.defineProperty(e,"__esModule",{value:!0});var i=n(1),o=n(5),a=n(8),s=n(2),u=function(t){function e(e,n){var r=t.call(this,e)||this;return r.invokeAction=o.createActionInvoker(e,n),r}return r(e,t),e.prototype.initialize=function(t){i.addHiddenFinalProp(t,this.name,this.invokeAction.bind(t))},e.prototype.validate=function(t,e){return this.name in t?s.typeCheckFailure(s.getContextForPath(e,this.name),t[this.name],"Action properties should not be provided in the snapshot"):s.typeCheckSuccess()},e}(a.Property);e.ActionProperty=u},function(t,e,n){"use strict";var r=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.defineProperty(e,"__esModule",{value:!0});var i=n(4),o=n(8),a=n(2),s=function(t){function e(e,n,r){var i=t.call(this,e)||this;return i.getter=n,i.setter=r,i}return r(e,t),e.prototype.initializePrototype=function(t){Object.defineProperty(t,this.name,i.computed(t,this.name,{get:this.getter,set:this.setter,configurable:!0,enumerable:!1}))},e.prototype.validate=function(t,e){return this.name in t?a.typeCheckFailure(a.getContextForPath(e,this.name),t[this.name],"Computed properties should not be provided in the snapshot"):a.typeCheckSuccess()},e}(o.Property);e.ComputedProperty=s},function(t,e,n){"use strict";var r=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.defineProperty(e,"__esModule",{value:!0});var i=n(5),o=n(4),a=n(8),s=n(1),u=n(2),c=function(t){function e(e,n){var r=t.call(this,e)||this;return r.subtype=n,r}return r(e,t),e.prototype.initialize=function(t,e){o.extendObservable(t,(n={},n[this.name]=o.observable.ref(e[this.name]),n));var n},e.prototype.willChange=function(t){var e=t.newValue;"number"==typeof e||s.isValidIdentifier(e)||s.fail("Not a valid identifier: '"+e),u.typecheck(this.subtype,e);var n=i.getMSTAdministration(t.object);n.assertWritable();var r=t.object[this.name];return void 0!==r&&r!==e&&s.fail("It is not allowed to change the identifier of an object, got: '"+e+"' but expected: '"+r+"'"),t},e.prototype.serialize=function(t,e){var n=t[this.name];this.isValidIdentifier(n)||s.fail("Object does not have a valid identifier yet: '"+n+"'"),e[this.name]=n},e.prototype.deserialize=function(t,e){t[this.name]=e[this.name]},e.prototype.validate=function(t,e){return this.isValidIdentifier(t[this.name])?u.typeCheckSuccess():u.typeCheckFailure(u.getContextForPath(e,this.name,this.subtype),t[this.name],"The provided identifier is not valid")},e.prototype.isValidIdentifier=function(t){return!("number"!=typeof t&&!s.isValidIdentifier(t))&&this.subtype.is(t)},e}(a.Property);e.IdentifierProperty=c},function(t,e,n){"use strict";var r=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.defineProperty(e,"__esModule",{value:!0});var i=n(8),o=n(1),a=n(5),s=n(20),u=n(2),c=function(t){function e(e,n,r){var i=t.call(this,e)||this;return i.type=n,i.basePath=r,i}return r(e,t),e.prototype.initialize=function(t,e){var n=new s.Reference(t,this.type,this.basePath,e[this.name]);o.addHiddenFinalProp(t,this.name+"$value",n);var r=this;Object.defineProperty(t,this.name,{get:function(){return a.getMSTAdministration(this).assertAlive(),n.get},set:function(t){var e=a.getMSTAdministration(this);e.assertWritable();var i=n.identifier;n.setNewValue(t),n.identifier!==i&&e.emitPatch({op:"replace",path:a.escapeJsonPath(r.name),value:n.serialize},e)}}),t[this.name]=e[this.name]},e.prototype.serialize=function(t,e){e[this.name]=t[this.name+"$value"].serialize()},e.prototype.deserialize=function(t,e){t[this.name+"$value"].setNewValue(e[this.name])},e.prototype.validate=function(t,e){return this.name in t?u.typeCheckSuccess():u.typeCheckFailure(u.getContextForPath(e,this.name,this.type),void 0,"Reference is required.")},e}(i.Property);e.ReferenceProperty=c},function(t,e,n){"use strict";var r=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.defineProperty(e,"__esModule",{value:!0});var i=n(4),o=n(8),a=n(5),s=n(2),u=function(t){function e(e,n){var r=t.call(this,e)||this;return r.type=n,r}return r(e,t),e.prototype.initializePrototype=function(t){i.observable.ref(t,this.name,{value:void 0})},e.prototype.initialize=function(t,e){t[this.name]=this.type.create(e[this.name])},e.prototype.willChange=function(t){var e=a.getMSTAdministration(t.object);return t.newValue=e.reconcileChildren(this.type,[t.object[t.name]],[t.newValue],[t.name])[0],t},e.prototype.didChange=function(t){var e=a.getMSTAdministration(t.object);e.emitPatch({op:"replace",path:a.escapeJsonPath(this.name),value:a.valueToSnapshot(t.newValue)},e)},e.prototype.serialize=function(t,e){e[this.name]=a.valueToSnapshot(t[this.name])},e.prototype.deserialize=function(t,e){var n=this;a.maybeMST(t[this.name],function(t){t.applySnapshot(e[n.name])},function(){t[n.name]=e[n.name]})},e.prototype.validate=function(t,e){return this.type.validate(t[this.name],s.getContextForPath(e,this.name,this.type))},e}(o.Property);e.ValueProperty=u},function(t,e,n){"use strict";function r(t,e){var n=function(){var t=this,n=arguments,r=s.getMSTAdministration(this);return r.assertAlive(),o.extras.allowStateChanges(!1,function(){return e.apply(t,n)})};return a.createNamedFunction(t,n)}var i=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.defineProperty(e,"__esModule",{value:!0});var o=n(4),a=n(1),s=n(5),u=n(8),c=n(2),p=function(t){function e(e,n){var i=t.call(this,e)||this;return i.invokeView=r(e,n),i}return i(e,t),e.prototype.initialize=function(t){a.addHiddenFinalProp(t,this.name,this.invokeView.bind(t))},e.prototype.validate=function(t,e){return this.name in t?c.typeCheckFailure(c.getContextForPath(e,this.name),t[this.name],"View properties should not be provided in the snapshot"):c.typeCheckSuccess()},e}(u.Property);e.ViewProperty=p,e.createViewInvoker=r},function(t,e,n){"use strict";function r(t){return Object.freeze(t),s.isPlainObject(t)&&Object.keys(t).forEach(function(e){Object.isFrozen(t[e])||r(t[e])}),t}var i=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.defineProperty(e,"__esModule",{value:!0});var o=n(3),a=n(2),s=n(1),u=function(t){function e(){var e=t.call(this,"frozen")||this;return e.flags=o.TypeFlags.Frozen,e}return i(e,t),e.prototype.describe=function(){return"<any immutable value>"},e.prototype.create=function(t){return s.isSerializable(t)||s.fail("Given value should be serializable"),s.isMutable(t)?r(t):t},e.prototype.validate=function(t,e){return s.isSerializable(t)?a.typeCheckSuccess():a.typeCheckFailure(e,t)},Object.defineProperty(e.prototype,"identifierAttribute",{get:function(){return null},enumerable:!0,configurable:!0}),e}(o.Type);e.Frozen=u,e.frozen=new u},function(t,e,n){"use strict";function r(t,e){var n="string"==typeof t?t:"<late>",r="string"==typeof t?e:t;return new s(n,r)}var i=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.defineProperty(e,"__esModule",{value:!0});var o=n(1),a=n(3),s=function(t){function e(e,n){var r=t.call(this,e)||this;return r._subType=null,"function"==typeof n&&0===n.length||o.fail("Invalid late type, expected a function with zero arguments that returns a type, got: "+n),r.definition=n,r}return i(e,t),Object.defineProperty(e.prototype,"flags",{get:function(){return this.subType.flags},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.create=function(t,e){return this.subType.create(t,e)},e.prototype.describe=function(){return this.subType.name},e.prototype.validate=function(t,e){return this.subType.validate(t,e)},Object.defineProperty(e.prototype,"identifierAttribute",{get:function(){return this.subType.identifierAttribute},enumerable:!0,configurable:!0}),e}(a.Type);e.Late=s,e.late=r},function(t,e,n){"use strict";function r(t){return i.union(s,t)}Object.defineProperty(e,"__esModule",{value:!0});var i=n(19),o=n(17),a=n(13),s=a.optional(o.literal(null),null);e.maybe=r},function(t,e,n){"use strict";function r(t,e,n){var r=e.create();return n(s.isMST(r)?s.getMSTAdministration(r).snapshot:r)||a.fail("Default value for refinement type "+t+" does not pass the predicate."),new c(t,e,n)}var i=this&&this.__extends||function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])};return function(e,n){function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();Object.defineProperty(e,"__esModule",{value:!0});var o=n(3),a=n(1),s=n(5),u=n(2),c=function(t){function e(e,n,r){var i=t.call(this,e)||this;return i.type=n,i.predicate=r,i}return i(e,t),Object.defineProperty(e.prototype,"flags",{get:function(){return this.type.flags},enumerable:!0,configurable:!0}),e.prototype.describe=function(){return this.name},e.prototype.create=function(t){var e=this.type.create(t),n=s.isMST(e)?s.getMSTAdministration(e).snapshot:e;return this.is(n)||a.fail("Value "+JSON.stringify(n)+" is not assignable to type "+this.name),e},e.prototype.validate=function(t,e){return this.type.is(t)&&this.predicate(t)?u.typeCheckSuccess():u.typeCheckFailure(e,t)},Object.defineProperty(e.prototype,"identifierAttribute",{get:function(){return this.type.identifierAttribute},enumerable:!0,configurable:!0}),e}(o.Type);e.Refinement=c,e.refinement=r}])}); |
{ | ||
"name": "mobx-state-tree", | ||
"version": "0.6.2", | ||
"version": "0.6.3", | ||
"description": "Opinionated, transactional, MobX powered state container", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
568
README.md
@@ -1,5 +0,7 @@ | ||
# mobx-state-tree | ||
<p align="center"> | ||
<img src="docs/logo.png" height="100"> | ||
<h3 align="center">mobx-state-tree</h3> | ||
<p align="center">_Opinionated, transactional, MobX powered state container combining the best features of the immutable and mutable world for an optimal DX_<p> | ||
</p> | ||
_Opinionated, transactional, MobX powered state container combining the best features of the immutable and mutable world for an optimal DX_ | ||
[![Build Status](https://travis-ci.org/mobxjs/mobx-state-tree.svg?branch=master)](https://travis-ci.org/mobxjs/mobx-state-tree) | ||
@@ -9,2 +11,4 @@ [![Coverage Status](https://coveralls.io/repos/github/mobxjs/mobx-state-tree/badge.svg?branch=master)](https://coveralls.io/github/mobxjs/mobx-state-tree?branch=master) | ||
**DISCLAIMER: Docs are still being worked on, so if you are confused at any point; we hope to see you back soon, or feel free to open issue or join the gitter channel** | ||
# Contents | ||
@@ -14,5 +18,16 @@ | ||
* [Philosophy & Overview](#philosophy--overview) | ||
* [MST overview for the impatient](#quick-overview-for-the-impatient) | ||
* [Concepts](#concepts) | ||
* [Short types overview](#types-overview) | ||
* [Short api overview](#api-overview) | ||
* [Trees, types and state](#trees-types-and-state) | ||
* [Creating models](#construction-models) | ||
* [Tree semantics in detail](#tree-semantis-in-detail) | ||
* [Composing trees](#composing-trees) | ||
* [Actions](#actions) | ||
* [Snapshots](#snapshots) | ||
* [Patches](#patches) | ||
* [References and identifiers](#references-and-identifiers) | ||
* [Listening to observables, snapshots, patches or actions](#listening-to-observables-snapshots-patches-or-actions) | ||
* [Types overview](#types-overview) | ||
* [Api overview](#api-overview) | ||
* [Tips](#tips) | ||
* [FAQ](#FAQ) | ||
@@ -29,2 +44,4 @@ * [Full Api Docs](API.md) | ||
Typescript typings are included in the packages. Use `module: "commonjs"` or `moduleResolution: "node"` to make sure they are picked up automatically in any consuming project. | ||
# Philosophy & Overview | ||
@@ -89,5 +106,5 @@ | ||
Although mutable sounds scare to some, fear not; actions have many interesting properties. | ||
By default trees cannot only be modified by using an action that belongs to the same subtree. | ||
Furthermore actions are replayable and can be used as means to distribute changes ([example](https://github.com/mobxjs/mobx-state-tree/blob/master/examples/boxes/src/stores/socket.js)). | ||
Although mutable sounds scary to some, fear not; actions have many interesting properties. | ||
By default trees can only be modified by using an action that belongs to the same subtree. | ||
Furthermore, actions are replayable and can be used as means to distribute changes ([example](https://github.com/mobxjs/mobx-state-tree/blob/master/examples/boxes/src/stores/socket.js)). | ||
@@ -111,6 +128,6 @@ Moreover; since changes can be detected on a fine grained level. JSON patches are supported out of the box. | ||
```javascript | ||
const oldTodo = store.todos[0] | ||
store.removeTodo(0) | ||
```javascript | ||
function logTodo(todo) { | ||
@@ -138,235 +155,187 @@ setTimeout( | ||
TODO: react europe talk | ||
mobx-state-tree "immutable trees" and "graph model" features talk, ["Next Generation State Management"](https://www.youtube.com/watch?v=rwqwwn_46kA) at React Europe 2017. [Slides](http://tree.surge.sh/#1). | ||
# Examples | ||
TODO: move https://github.com/mweststrate/react-mobx-shop/tree/mobx-state-tree to this repo | ||
* [Bookshop](https://github.com/mobxjs/mobx-state-tree/tree/master/examples/bookshop) Example webshop application with references, identifiers, routing, testing etc. | ||
* [Boxes](https://github.com/mobxjs/mobx-state-tree/tree/master/examples/boxes) Example app where on can draw, drag and drop boxes. With time travelling and multi client synchronization over websockets. | ||
* [Redux TodoMVC](https://github.com/mobxjs/mobx-state-tree/tree/master/examples/redux-todomvc) Redux TodoMVC application, except that the reducers are replaced with a MST. Tip: open the Redux devtools; they will work! | ||
# Concepts | ||
1. The state is represented as a _tree_ of _models_. | ||
2. _models_ are created using _factories_. | ||
3. A _factory_ basically takes a _snapshot_ and a clone of a base _model_ and copies the two into a fresh _model_ instance. | ||
4. A _snapshot_ is the immutable representation of the _state_ of a _model_. In other words, a one-time copy of the internal state of a model at a certain point in time. | ||
5. _snapshots_ use structural sharing. So a snapshot of a node in the tree is composed of the snapshots of it's children, where unmodified snapshots are always shared | ||
6. `mobx-state-tree` supports JSON patches, replayable actions, listeners for patches, actions and snapshots. References, maps, arrays. Just read on :) | ||
With MobX state tree, you build, as the name suggests, trees of models. | ||
## Models | ||
### Trees, types and state | ||
Models are at the heart of `mobx-state-tree`. They simply store your data. | ||
Each **node** in the tree is described by two things: Its **type** (the shape of the thing) and its **data** (the state it is currently in). | ||
- Models are self-contained. | ||
- Models have fields. Either primitive or complex objects like maps, arrays or other models. In short, these are MobX observables. Fields can only be modified by actions. | ||
- Models have derived fields. Based on the `mobx` concept of `computed` values. | ||
- Models have actions. Only actions are allowed to change fields. Fields cannot be changed directly. This ensures replayability of the application state. | ||
- Models can contain other models. However, models are not allowed to form a graph (using direct references) but must always have a tree shape. This enables many feature like standardized serialization and cloning. | ||
- Models can be snapshotted at any time | ||
- Models can be created using factories, that take copy a base model and combine it with a (partial) snapshot | ||
The simplest tree possible: | ||
TODO: properties & operations | ||
Example: | ||
```javascript | ||
import { types } from "mobx-state-tree" | ||
import uuid from "uuid" | ||
import {types} from "mobx-state-tree" | ||
const Box = types.model("Box",{ | ||
// props | ||
id: types.identifier(), | ||
name: "", | ||
x: 0, | ||
y: 0, | ||
// computed prop / views | ||
get width() { | ||
return this.name.length * 15 | ||
} | ||
}, { | ||
// actions | ||
move(dx, dy) { | ||
this.x += dx | ||
this.y += dy | ||
} | ||
// declaring the shape of a node with the type `Todo` | ||
const Todo = types.model({ | ||
title: types.string | ||
}) | ||
const BoxStore = types.model("BoxStore",{ | ||
boxes: types.map(Box), | ||
selection: types.reference("boxes/name") | ||
}, { | ||
addBox(name, x, y) { | ||
const box = Box.create({ id: uuid(), name, x, y }) | ||
this.boxes.put(box) | ||
return box | ||
} | ||
// creating a tree based on the "Todo" type, with initial data: | ||
const coffeeTodo = Todo.create({ | ||
title: "Get coffee" | ||
}) | ||
const boxStore = BoxStore.create({ | ||
"boxes": {}, | ||
"selection": "" | ||
}); | ||
const box = boxStore.addBox("test",100,100) | ||
box.move(7, 3) | ||
``` | ||
Useful methods: | ||
The `types.model` type declaration is used to describe the shape of an object. | ||
Other built-in types include arrays, maps, primitives etc. See the [types overview](#types-overview). | ||
The type information will be used for both | ||
- `types.model(exampleModel)`: creates a new factory | ||
- `clone(model)`: constructs a deep clone of the given model instance | ||
## Snapshots | ||
### Creating models | ||
A snapshot is a representation of a model. Snapshots are immutable and use structural sharing (sinces model can contain models, snapshots can contain other snapshots). | ||
This means that any mutation of a model results in a new snapshot (using structural sharing) of the entire state tree. | ||
This enables compatibility with any library that is based on immutable state trees. | ||
The most important type in MST is `types.model`, which can be used to describe the shape of an object. | ||
An example: | ||
- Snapshots are immutable | ||
- Snapshots can be transported | ||
- Snapshots can be used to update / restore models to a certain state | ||
- Snapshots use structural sharing | ||
- It is posible to subscribe to models and be notified of each new snapshot | ||
- Snapshots are automatically converted to models when needed. So assignments like `boxStore.boxes.set("test", Box({ name: "test" }))` and `boxStore.boxes.set("test", { name: "test" })` are both valid. | ||
Useful methods: | ||
- `getSnapshot(model)`: returns a snapshot representing the current state of the model | ||
- `onSnapshot(model, callback)`: creates a listener that fires whenever a new snapshot is available (but only one per MobX transaction). | ||
- `applySnapshot(model, snapshot)`: updates the state of the model and all its descendants to the state represented by the snapshot | ||
## Actions | ||
Actions modify models. Actions are replayable and are therefore constrained in several ways: | ||
- Actions can be invoked directly as method on a model | ||
- All action arguments must be serializable. Some arguments can be serialized automatically, such as relative paths to other nodes | ||
- Actions are serializable and replayable | ||
- It is possible to subscribe to the stream of actions that is invoked on a model | ||
- Actions can only modify models that belong to the tree on which they are invoked | ||
- Actions are automatically bound the their instance, so it is save to pass actions around first class without binding or wrapping in arrow functions. | ||
A serialized action call looks like: | ||
{ | ||
name: "setAge" | ||
path: "/user", | ||
args: [17] | ||
```javascript | ||
const TodoStore = types.model("TodoStore", { // 1 | ||
loaded: types.boolean // 2 | ||
endpoint: "http://localhost", // 3 | ||
todos: types.array(Todo), // 4 | ||
selectedTodo: types.reference(Todo, "todos"), // 5 | ||
get completedTodos() { // 6 | ||
return this.todos.filter(t => t.done) | ||
}, | ||
findTodosByUser(user) { // 7 | ||
return this.todos.filter(t => t.assignee = user) | ||
} | ||
}, { | ||
addTodo(title) { | ||
this.todos.push({ | ||
id: Math.random(), | ||
title | ||
}) | ||
} | ||
}) | ||
``` | ||
Useful methods: | ||
When defining a model, it is advised to give the model a name for debugging purposes (see `// 1`). | ||
A model takes two objects arguments, first all the properties, then the actions. | ||
- Use `name: function(/* args */) { /* body */ }` (ES5) or `name (/* args */) { /* body */ }` (ES6) to construct actions | ||
- `onAction(model, middleware)` listens to any action that is invoked on the model or any of it's descendants. See `onAction` for more details. | ||
- `applyAction(model, action)` invokes an action on the model according to the given action description | ||
The _properties_ argument is a key-value set where each key indicates the introduction of a property, and the value it's type. The following types are acceptable as type: | ||
It is not necessary to express all logic around models as actions. For example it is not possible to define constructors on models. Rather, it is recommended to create stateless utility methods that operate on your models. It is recommended to keep models self-contained and to do orchestration around models in utilities around it. | ||
1. A type. This can be a simple primitive type like `types.boolean`, see `// 2`, or a complex, possible earlier defined type (`// 4`) | ||
2. A primitive. Using a primitive as type as type is syntactic sugar for introducing an property with a default value. See `// 3`, `endpoint: "http://localhost"` is the same as `endpoint: types.optional(types.string, "http://localhost")`. The primitive type is inferred from the default value. Properties with a default value can be omitted in snapshots. | ||
3. A [computed property](https://mobx.js.org/refguide/computed-decorator.html), see `// 6`. Computed properties are tracked and memoized by MobX. Computed properties will not be stored in snapshots or emit patch events. It is allowed to provid a setter for a computed property as well. A setter should always invoke an action. | ||
4. A view function (see `// 7`). A view function can, unlike computed properties, take arbitrary arguments. It won't be memoized, but it's value can be tracked by Mobx nonetheless. View functions are not allowed to change the model, but should rather be used to retrieve information from the model. | ||
## (Un) protecting state tree | ||
The _actions_ argument is a key-value set with actions that are available to manage the model. Only actions are allowed to manage models (including any contained objects). | ||
`afterCreate() { unprotect(this) }` | ||
It is also possible to define lifecycle hooks in the _actions_ object, these are actions with a predefined name that are run at a specific moment. See [Lifecycle hooks](#lifecycle-hooks-for-typesmodel). | ||
## Views | ||
_Tip: Note that `{ action1() { }, action2() { }}` is ES6 syntax for `{ action1: function() { }, action2: function() { } }`, in other words; it's just an object literal. | ||
For that reason a comma between each member of a model is mandatory, unlike classes which are syntactically a totally different concept._ | ||
TODO | ||
### Tree semantics in detail | ||
Views versus actions | ||
MST trees have very specific semantics. These semantics purposefully constraint what you can do with MST. The reward for that are all kind of generic features out of the box like snapshots, replayability etc. If these constraints don't suit your app, you are probably better of using plain mobx with your own model classes. Which is perfectly fine as well. | ||
Exception: `"Invariant failed: Side effects like changing state are not allowed at this point."` indicates that a view function tries to modifies a model. This is only allowed in actions. | ||
1. Each object in a MST tree is concidered a _node_. Each primitive (and frozen) value is considered a _leaf_. | ||
1. MST has only tree types of nodes; _model_, _array_, and _map_. | ||
1. Every _node_ tree in a MST tree is a tree in itself. Any operation that can be invoked on the complete tree, can also be applied to only a sub tree. | ||
1. A node can exists exactly only _once_ in a tree. This ensures it has an unique, identifiable position. | ||
2. It is however possible to refer to another object in the _same_ tree by using _references_ | ||
3. There is no limit to the amount of MST trees that live in an application. However, each node can live in exactly only one tree. | ||
4. All _leaves_ in the tree must be serializable; it is not possible to store for example functions in a MST. | ||
6. The only free form type in MST is frozen; with the requirement that frozen values are immutable so that the MST semantics can still be uphold. | ||
7. At any point in the tree it is possible to assign a snapshot to the tree instead of a concrete instance of the expect type. In that case an instance of the correc type, based on the snapshot, will be automatically created for you. | ||
8. Nodes in the MST tree will be reconciled (the exact same instance will be reused) when updating the tree by any means, based on their _identifier_ property. If there is no identifier property, instances won't be reconciled. | ||
9. If a node in the tree is replaced by another node, the original node will die and become unusable. This makes sure you are not accidentally holding on to stale objects anywhere in your application. | ||
10. If you want to create a new node based on an existing node in a tree, you can either `detach` that node, or `clone` it. | ||
## Protecting the state tree | ||
### Composing trees | ||
By default it is allowed to both directly modify a model or through an action. | ||
However, in some cases you want to guarantee that the state tree is only modified through actions. | ||
So that replaying action will reflect everything that can possible have happened to your objects, or that every mutation passes through your action middleware etc. | ||
To disable modifying data in the tree without action, simple call `protect(model)`. Protect protects the passed model an all it's children | ||
In MST every node in the tree is a tree in itself. | ||
Trees can be composed by composing their types: | ||
```javascript | ||
const Todo = types.model({ | ||
done: false | ||
}, { | ||
toggle() { | ||
this.done = !this.done | ||
} | ||
const TodoStore = types.model({ | ||
todos: types.array(Todo) | ||
}) | ||
const todo = new Todo() | ||
todo.done = true // OK | ||
protect(todo) | ||
todo.done = false // throws! | ||
todo.toggle() // OK | ||
const storeInstance = TodoStore.create({ | ||
todos: [{ | ||
title: "Get biscuit" | ||
}] | ||
}) | ||
``` | ||
## Identifiers | ||
The _snapshot_ passed to the `create` method of a type will recursively be turned in MST nodes. So you can safely call: | ||
Identifiers and references are two powerful abstraction that work well together. | ||
```javascript | ||
storeInstance.todos[0].setTitle("Chocolate instead plz") | ||
``` | ||
- Each model can define zero or one `identifier()` properties | ||
- The identifier property of an object cannot be modified after initialization | ||
- Identifiers should be unique within their parent collection (`array` or `map`) | ||
- Identifiers are used to reconcile items inside arrays and maps wherever possible when applying snapshots | ||
- The `map.put()` method can be used to simplify adding objects to maps that have identifiers | ||
Since any node in a tree, is an tree in itself, any built-in method in MST can be invoked on any node in the tree, not just the root. | ||
This makes it possible to get a patch stream of a certain subtree, or to apply middleware to a certain subtree only. | ||
Example: | ||
### Actions | ||
By default, nodes can only be modified by one of their actions, or actions higher up in the tree. | ||
Actions can be defined by passing a second object to to `types.model`: | ||
```javascript | ||
const Todo = types.model({ | ||
id: types.identifier(), | ||
title: "", | ||
done: false | ||
title: types.string | ||
}, { | ||
setTitle(newTitle) { | ||
this.title = newTitle | ||
} | ||
}) | ||
const todo1 = Todo.create() // not ok, identifier is required | ||
const todo1 = Todo.create({ id: "1" }) // ok | ||
applySnapshot(todo1, { id: "2", done: false}) // not ok; cannot modify the identifier of an object | ||
const store = types.map(Todo) | ||
store.put(todo1) // short-hand for store.set(todo1.id, todo) | ||
``` | ||
## References | ||
Actions are replayable and are therefore constrained in several ways: | ||
References can be used to refer to link to an arbitrarily different object in the tree transparently. | ||
This makes it possible to use the tree as graph, while behind the scenes the graph is still properly serialized as tree | ||
- Trying to modify a node without using an action will throw an exception. | ||
- All action arguments should be serializable. Some arguments can be serialized automatically, such as relative paths to other nodes | ||
- Actions can only modify models that belong to the (sub)tree on which they are invoked | ||
- Actions are automatically bound the their instance, so it is save to pass actions around first class without binding or wrapping in arrow functions. | ||
Example: | ||
Useful methods: | ||
```javascript | ||
const Store = types.model({ | ||
selectedTodo: types.reference(Todo), | ||
todos: types.array(Todo) | ||
}) | ||
- `onAction(model, listener)` listens to any action that is invoked on the model or any of it's descendants. See `onAction` for more details. | ||
- `addMiddleware(model, middleware)` listens to any action that is invoked on the model or any of it's descendants. See `addMiddleware` for more details. | ||
- `applyAction(model, action)` invokes an action on the model according to the given action description | ||
const store = Store({ todos: [ /* some todos */ ]}) | ||
#### Action listeners versus middleware | ||
store.selectedTodo = store.todos[0] // ok | ||
store.selectedTodo === store.todos[0] // true | ||
getSnapshot(store) // serializes properly as tree: { selectedTodo: { $ref: "../todos/0" }, todos: /* */ } | ||
The difference between action listeners and middlewares is: Middleware can intercept the action that is about to be invoked, modify arguments, return types etc. Action listeners cannot intercept, but are only notified. Action listeners receive the action arguments in a serializable format, while middleware receive the raw arguments. (`onAction` is actually just a built-in middleware) | ||
store.selectedTodo = Todo() // not ok; have to refer to something already in the same tree | ||
``` | ||
#### Disabling protected mode | ||
By default references can point to any arbitrary object in the same tree (as long as it has the proper type). | ||
If the default protection of mobx-state-tree doesn't fit your use case. For example if you are not interested in replayable actions or hate the effort of writing actions to modify any field; `unprotect(tree)` will disable the protected mode of a tree, allowing anyone to directly modify the tree. | ||
## References with predefined resolve paths | ||
### Snapshots | ||
It is also possible to specifiy in which collection the reference should resolve by passing a second argument, the resolve path (this can be relative): | ||
Snapshots are the immutable serialization in plain objects of a tree at a specific point in time. | ||
Snapshots can be inspected through `getSnapshot(node)`. | ||
Snapshots don't contain any type information and are stripped from all actions etc, so they are perfectly suitable for tranportation. | ||
Requesting a snapshot is cheap, as MST always maintains a snapshot of each node in the background, and uses structural sharing | ||
```javascript | ||
const Store = types.model({ | ||
selectedTodo: types.reference(Todo, "/todos/"), | ||
todos: types.array(Todo) | ||
}) | ||
``` | ||
coffeeTodo.setTitle("Tea instead plz") | ||
If a resolve path is provided, `reference` no longer stores a json pointer, but pinpoints the exact object that is being referred to by it's _identifier_. Assuming that `Todo` specified an `identifier()` property: | ||
```javascript | ||
getSnapshot(store) // serializes tree: { selectedTodo: "17" /* the identifier of the todo */, todos: /* */ } | ||
console.dir(getSnapshot(coffeeTodo)) | ||
// prints `{ title: "Tea instead plz" }` | ||
``` | ||
The advantage of this approach is that paths are less fragile, where default references serialize the path by for example using array indices, an identifier with a resolve path will find the object by using it's identifier. | ||
Some interesting properties of snapshots: | ||
## Utility methods | ||
- Snapshots are immutable | ||
- Snapshots can be transported | ||
- Snapshots can be used to update / restore models to a certain state | ||
- Snapshots are automatically converted to models when needed. So the two following statements are equivalent: `store.todos.push(Todo.create({ title: "test" }))` and `store.todos.push({ title: "test" })`. | ||
Useful methods: | ||
- No restriction in arguments and return types | ||
- Cannot modify data except though actions | ||
- `getSnapshot(model)`: returns a snapshot representing the current state of the model | ||
- `onSnapshot(model, callback)`: creates a listener that fires whenever a new snapshot is available (but only one per MobX transaction). | ||
- `applySnapshot(model, snapshot)`: updates the state of the model and all its descendants to the state represented by the snapshot | ||
@@ -395,13 +364,120 @@ ## Patches | ||
## Be careful with direct references to items in the tree | ||
### References and identifiers | ||
See [#10](https://github.com/mobxjs/mobx-state-tree/issues/10) | ||
References and identifiers are a first class concept in MST. | ||
This makes it possible to declare references and keeping the data normalized in the background, while you interect with it in a denormalized manner. | ||
## Factory composition | ||
Example: | ||
```javascript | ||
const Todo = types.model({ | ||
id: types.identifier(), | ||
title: types.string | ||
}) | ||
## Tree semantics | ||
const TodoStore = types.model({ | ||
todos: types.array(Todo), | ||
selectedTodo: types.reference(Todo, "todos") | ||
}) | ||
TODO: document | ||
// create a store with a normalized snapshot | ||
const storeInstance = TodoStore.create({ | ||
todos: [{ | ||
id: "47", | ||
title: "Get coffee" | ||
}], | ||
selectedTodo: "47" | ||
}) | ||
// because `selectedTodo` is declared to be a reference, it returns the actual Todo node with the matching identifier | ||
console.log(storeInstance.selectedTodo.title) | ||
// prints "Get coffee" | ||
``` | ||
#### Identifiers | ||
- Each model can define zero or one `identifier()` properties | ||
- The identifier property of an object cannot be modified after initialization | ||
- Identifiers should be unique within their parent collection (`array` or `map`) | ||
- Identifiers are used to reconcile items inside arrays and maps wherever possible when applying snapshots | ||
- The `map.put()` method can be used to simplify adding objects to maps that have identifiers | ||
#### References | ||
References can be defined in two ways, generic or namespaces. | ||
Namespaced references can only put to elements of the correct type, at a predefined location (namespace). Namespaced references always use the `identifier()` property of the targeted object. | ||
The above example: `selectedTodo: types.reference(Todo, "todos")` is namespaced, and resolves it's target in the collection on the relative path `"todos"`. (`"../todos"` can be used to identify a namespace one level higher in the tree etc.) | ||
Generic references can point to any element of the correct type in the current tree, and are stored behind the scenes as JSON path. The above example could also have been configured as `selectedTodo: types.reference(Todo)` to create a generic reference. | ||
_Tip: It is recommended to use namespaced references; as those are more stable, since they always use immutable references and a preconfigured namespace._ | ||
**Note: The exact semantics of references are still under investigation, and might change before MST 1.0. One of the two forms might be dropped_** | ||
### Listening to observables, snapshots, patches or actions | ||
MST is powered by MobX. This means that it is immediately compatible with `observer` components, or reactions like `autorun`: | ||
```javascript | ||
import { autorun } from "mobx" | ||
autorun(() => { | ||
console.log(storeInstance.selectedTodo.title) | ||
}) | ||
``` | ||
But since MST keeps immutable snapshots in te background, it is also possible to be notified when a new snapshot of the tree is available, similar to `.subscribe` on a redux store: | ||
```javascript | ||
onSnapshot(storeInstance, newSnapshot => { | ||
console.dir("Got new state: ", newSnapshot) | ||
}) | ||
``` | ||
However, sometimes it is more useful to precisely know what has changed rather than just receiving a complete new snapshot. | ||
For that, MST supports json-patches out of the box | ||
```javascript | ||
onPatch(storeInstance, patch => { | ||
console.dir("Got change: ", patch) | ||
}) | ||
storeInstance.todos[0].setTitle("Add milk") | ||
// prints: | ||
{ | ||
path: "/todos/0", | ||
op: "replace", | ||
value: "Add milk" | ||
} | ||
``` | ||
Similarly, you can be notified whenever an action is invoked by using `onAction` | ||
```javascript | ||
onAction(storeInstance, call => { | ||
console.dir("Action was called: ", call) | ||
}) | ||
storeInstance.todos[0].setTitle("Add milk") | ||
// prints: | ||
{ | ||
path: "/todos/0", | ||
name: "setTitle", | ||
args: ["Add milk"] | ||
} | ||
``` | ||
It is even possible to intercept actions before they are applied by adding middleware using `addMiddleware`: | ||
```javascript | ||
addMiddleware(storeInstance, (call, next) => { | ||
call.args[0] = call.args[0].replace(/tea/gi, "Coffee") | ||
return next(call) | ||
}) | ||
``` | ||
Finally, it is not only possible to be notified about snapshots, patches or actions. | ||
It is also possible to re-apply them by respectively `applySnapshot`, `applyPatch` or `applyAction`! | ||
# Types overview | ||
@@ -459,3 +535,3 @@ | ||
| `asReduxStore(node)` | Wraps a node in a Redux store compatible api | | ||
| `clone(node, keepEnvironment?: true | false | newEnvironment)` | Creates a full clone of a certain node. By default preserves the same environment | | ||
| `clone(node, keepEnvironment?: true \| false \| newEnvironment)` | Creates a full clone of a certain node. By default preserves the same environment | | ||
| `connectReduxDevtools(removeDevModule, node)` | Connects a node to the redux development tools [example](https://github.com/mobxjs/mobx-state-tree/blob/b01fe97d427ca664f7ecc99349d10e58d08d2d98/examples/redux-todomvc/src/index.js) | | ||
@@ -493,52 +569,95 @@ | `destroy(node)` | Kills a node, making it unusable. Removes it from any parent in the process | | ||
# FAQ | ||
# Tips | ||
## Single or multiple state | ||
### `optionals` and default value functions | ||
## Using mobx and mobx-state-tree together | ||
`types.optional` can takes as default function also a function, which will be invoked each time the default value is needed. This is useful to generate timestamps, identifiers or even complex objects: | ||
## Integrations | ||
`createdDate: types.optional(types.date, () => new Date())` | ||
### `toJSON()` for debugging | ||
**Should all state of my app be stored in `mobx-state-tree`?** | ||
No, or, not necessarily. An application can use both state trees and vanilla MobX observables at the same time. | ||
State trees are primarily designed to store your domain data, as this kind of state is often distributed and not very local. | ||
For, for example, local component state, vanilla MobX observables might often be simpler to use. | ||
For debugging you might want to use `getSnapshot(model)` to print the state of a model. But if you didn't import `getSnapshot` while debugging in some debugger; don't worry, `model.toJSON()` will produce the same snapshot. (For api consistency, this feature is not part of the typed api) | ||
**No constructors?** | ||
### Handle circular dependencies between files using `late` | ||
Neh, replayability. Use utilities instead | ||
On the exporting file: | ||
**No inheritance?** | ||
```javascript | ||
export function LateStore() { | ||
return types.model({ | ||
title: types.string | ||
}) | ||
} | ||
``` | ||
No use composition or unions instead. | ||
In the importing file | ||
```javascript | ||
import { LateStore } from "./circular-dep" | ||
## Constraints | ||
const Store = types.late(() => LateStore) | ||
``` | ||
Some model constructions which are supported by mobx are not supported by mobx-state-tree | ||
Thanks to function hoisting in combination with `types.late`, this makes sure you can have circular dependencies between types accross files. | ||
- Data graphs are not supported, only data trees | ||
- This means that each object needs to uniquely contained | ||
- Only containment relations are allowed. Associations need to be expressed with 'foreign keys'; strings identifying other objects. However there is a standard pattern enabling using real objects as references with a little boilerplate, see [working with associations](#working-with-associations). | ||
- `mobx-state-tree` does currently not support inheritance / subtyping. This could be changed by popular demand, but not supporting inheritance avoids the need to serialize type information or keeping a (global) type registery | ||
### Simulate inheritance by using type composition | ||
## Features | ||
There is no notion of inheritance in MST. The recommended approach is to keep an references to the original configuration of a model to compose it into a new one. (`types.extend` achieves this as well, but it might change or even be removed). So a classical animal inheritance could be expressed using composition as follows: | ||
- Provides immutable, structurally shared snapshots which can be used as serialization or for time travelling. Snapshots consists entirely of plain objects. | ||
- Provides [JSON patch](https://tools.ietf.org/html/rfc6902) streams for easy remote synchronization or easy diffing. | ||
- Each object is uniquely contained and has an explicit path like in a file system. This enables using relative references and is very useful for debugging. | ||
- State trees are composable | ||
- There can be many state trees in a single app. | ||
```javascript | ||
const animalProperties: { | ||
age: types.number, | ||
sound: types.string | ||
} | ||
## Comparison with immutable state trees | ||
const animalActions = { | ||
makeSound() { | ||
console.log(this.sound) | ||
} | ||
} | ||
So far this might look a lot like an immutable state tree as found for example in Redux apps, but there are a few differences: | ||
const Dog = types.model( | ||
{ ...animalProperties, sound: "woof" }, | ||
animalActions | ||
) | ||
- mobx-state-tree allow direct modification of any value in the tree, it is not needed to construct a new tree in your actions | ||
- mobx-state-tree allows for fine grained and efficient observability on any point in the state tree | ||
- mobx-state-tree generates json patches for any modification that is made | ||
- (?) mobx-state-tree is a valid redux store, providing the same api (TODO) | ||
const Cat = types.model( | ||
{ ...animalProperties, sound: "meaow" }, | ||
animalActions | ||
) | ||
## TypeScript & MST | ||
const Animal = types.union(Dog, Cat) | ||
``` | ||
### Creating enumerations | ||
There is no built-in type for enumerations, but enumarations can simply be constructed by combining unions and literals: | ||
```javascript | ||
const Temperature = types.union(types.literal("Hot"), types.literal("Cold")) | ||
``` | ||
Or, fancier: | ||
```javascript | ||
const Temperature = types.union(...["Hot", "Cold"].map(types.literal)) | ||
``` | ||
# FAQ | ||
### Creating async processes | ||
For asynchronous processes, for each step that intends to modify a model you need a separate action. So for example one to kick off the process. And one to update the model. In a multi stage async process, consider postponing all updates until the last step is completed. | ||
### Using mobx and mobx-state-tree together | ||
Yep, perfectly fine. No problem. Go on. `observer`, `autorun` etc will work as expected. | ||
### Should all state of my app be stored in `mobx-state-tree`? | ||
No, or, not necessarily. An application can use both state trees and vanilla MobX observables at the same time. | ||
State trees are primarily designed to store your domain data, as this kind of state is often distributed and not very local. | ||
For, for example, local component state, vanilla MobX observables might often be simpler to use. | ||
### TypeScript & MST | ||
TypeScript support is best effort, as not all patterns can be expressed in TypeScript. But except for assigning snapshots to properties we got pretty close! As MST uses the latest fancy typescript features it is recommended to use TypeScript 2.3 or higher, with `noImplicitThis` and `strictNullChecks` enabled. | ||
@@ -562,8 +681,19 @@ | ||
### How does MST compare to Redux | ||
## Circular dependencies: | ||
So far this might look a lot like an immutable state tree as found for example in Redux apps, but there are a few differences: | ||
`types.late(() => require("./OtherType"))` | ||
- like Redux, and unlike MobX, MST prescribes a very specific state architecture. | ||
- mobx-state-tree allow direct modification of any value in the tree, it is not needed to construct a new tree in your actions. | ||
- mobx-state-tree allows for fine grained and efficient observability on any point in the state tree. | ||
- mobx-state-tree generates json patches for any modification that is made. | ||
- mobx-state-tree provides utilties to turn any MST tree into a valid Redux store. | ||
- having multiple MSTs in a single application is perfectly fine. | ||
## Thanks | ||
Thanks to @gcanti who inspired lot of the Type and validation API! | ||
## Thanks! | ||
* [Mendix](https://mendix.com) for sponsoring and providing the opportunity to work on exploratory projects like MST. | ||
* [Dan Abramov](https://twitter.com/dan_abramov)'s work on [Redux](http://redux.js.org) has strongly influenced the idea of snapshots and transactional actions in MST. | ||
* [Giulio Canti](https://twitter.com/GiulioCanti)'s work on [tcomb](http://github.com/gcanti/tcomb) and type systems in general has strongly influenced the type system of MST. | ||
* All the early adopters encouraging to pursue this whole idea and proving it is something feasible. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
375520
4129
690