mobx-state-tree
Advanced tools
Comparing version 0.5.1 to 0.6.0
@@ -0,5 +1,15 @@ | ||
# 0.6.0 | ||
* **BREAKING** `types.withDefault` has been renamed to `types.optional` | ||
* **BREAKING** Array and map types can no longer be left out of snapshots by default. Use `optional` to make them optional in the snapshot | ||
* **BREAKING** Literals no longer have a default value by default (use optional + literal instead) | ||
* **BREAKING** Disabled inlining type.model definitions as introduced in 0.5.1; to many subtle issues | ||
* Improved identifier support, they are no properly propageted through utility types like `maybe`, `union` etc | ||
* Fixed issue where fields where not referted back to default when a partial snapshot was provided | ||
* Fixed #122: `types.identifier` now also accepts a subtype to override the default string type; e.g. `types.identifier(types.number)` | ||
# 0.5.1 | ||
* Introduced support for lazy evaluating values in `withDefault`, useful to generate UUID's, timestamps or non-primitive default values | ||
* It is now possible to define something like | ||
* ~~It is now possible to define something like~~ Removed in 0.6.0 | ||
@@ -6,0 +16,0 @@ ```javascript |
@@ -126,2 +126,4 @@ "use strict"; | ||
get: function () { | ||
if (!this._isAlive) | ||
return undefined; | ||
// advantage of using computed for a snapshot is that nicely respects transactions etc. | ||
@@ -193,2 +195,3 @@ // Optimization: only freeze on dev builds | ||
// optimization: overload for a single old / new value to avoid all the array allocations | ||
// optimization: skip reconciler for non-complex types | ||
var res = new Array(newValues.length); | ||
@@ -200,2 +203,4 @@ var oldValuesByNode = {}; | ||
oldValues.forEach(function (oldValue) { | ||
if (!oldValue) | ||
return; | ||
if (identifierAttribute) { | ||
@@ -202,0 +207,0 @@ var id = oldValue[identifierAttribute]; |
@@ -61,7 +61,8 @@ "use strict"; | ||
var target = mst_node_1.getMSTAdministration(value); | ||
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 (this.targetIdAttribute) | ||
this.identifier = value[this.targetIdAttribute]; | ||
else | ||
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"); | ||
this.identifier = mst_node_1.getRelativePathForNodes(base, target); | ||
} | ||
} | ||
@@ -68,0 +69,0 @@ else if (this.targetIdAttribute) { |
@@ -24,4 +24,5 @@ import { IObservableArray, IArrayWillChange, IArrayWillSplice, IArrayChange, IArraySplice } from "mobx"; | ||
removeChild(node: MSTAdministration, subpath: string): void; | ||
readonly identifierAttribute: null; | ||
} | ||
export declare function createArrayFactory<S, T>(subtype: IType<S, T>): IComplexType<S[], IObservableArray<T>>; | ||
export declare function array<S, T>(subtype: IType<S, T>): IComplexType<S[], IObservableArray<T>>; | ||
export declare function isArrayFactory<S, T>(type: any): type is IComplexType<S[], IObservableArray<T>>; |
@@ -24,3 +24,2 @@ "use strict"; | ||
var complex_type_1 = require("./complex-type"); | ||
var with_default_1 = require("../utility-types/with-default"); | ||
function arrayToString() { | ||
@@ -154,2 +153,9 @@ return core_1.getMSTAdministration(this) + "(" + this.length + " items)"; | ||
}; | ||
Object.defineProperty(ArrayType.prototype, "identifierAttribute", { | ||
get: function () { | ||
return null; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
return ArrayType; | ||
@@ -161,6 +167,6 @@ }(complex_type_1.ComplexType)); | ||
exports.ArrayType = ArrayType; | ||
function createArrayFactory(subtype) { | ||
return with_default_1.createDefaultValueFactory(new ArrayType(subtype.name + "[]", subtype), []); | ||
function array(subtype) { | ||
return new ArrayType(subtype.name + "[]", subtype); | ||
} | ||
exports.createArrayFactory = createArrayFactory; | ||
exports.array = array; | ||
function isArrayFactory(type) { | ||
@@ -167,0 +173,0 @@ return type_1.isType(type) && type.isArrayFactory === true; |
@@ -15,2 +15,6 @@ "use strict"; | ||
var type_1 = require("../type"); | ||
var utils_1 = require("../../utils"); | ||
function toJSON() { | ||
return mst_node_1.getMSTAdministration(this).snapshot; | ||
} | ||
/** | ||
@@ -36,9 +40,20 @@ * A complex type produces a MST node (Node in the state tree) | ||
var node = new mst_node_administration_1.MSTAdministration(parent, subpath, instance, this, environment); | ||
node.pseudoAction(function () { | ||
_this.finalizeNewInstance(instance, snapshot); | ||
}); | ||
node.fireHook("afterCreate"); | ||
if (parent) | ||
node.fireHook("afterAttach"); | ||
return instance; | ||
var sawException = true; | ||
try { | ||
node.pseudoAction(function () { | ||
_this.finalizeNewInstance(instance, snapshot); | ||
}); | ||
utils_1.addReadOnlyProp(instance, "toJSON", toJSON); | ||
node.fireHook("afterCreate"); | ||
if (parent) | ||
node.fireHook("afterAttach"); | ||
sawException = false; | ||
return instance; | ||
} | ||
finally { | ||
if (sawException) { | ||
// short-cut to die the instance, to avoid the snapshot computed starting to throw... | ||
node._isAlive = false; | ||
} | ||
} | ||
}; | ||
@@ -45,0 +60,0 @@ ComplexType.prototype.is = function (value) { |
@@ -29,4 +29,5 @@ import { ObservableMap, IMapChange, IMapWillChange } from "mobx"; | ||
removeChild(node: MSTAdministration, subpath: string): void; | ||
readonly identifierAttribute: null; | ||
} | ||
export declare function createMapFactory<S, T>(subtype: IType<S, T>): IComplexType<{ | ||
export declare function map<S, T>(subtype: IType<S, T>): IComplexType<{ | ||
[key: string]: S; | ||
@@ -33,0 +34,0 @@ }, IExtendedObservableMap<T>>; |
@@ -19,3 +19,2 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var with_default_1 = require("../utility-types/with-default"); | ||
var object_1 = require("./object"); | ||
@@ -50,3 +49,3 @@ var mobx_1 = require("mobx"); | ||
MapType.prototype.createNewInstance = function () { | ||
var identifierAttr = object_1.getIdentifierAttribute(this.subType); | ||
// const identifierAttr = getIdentifierAttribute(this.subType) | ||
var map = mobx_1.observable.shallowMap(); | ||
@@ -80,3 +79,3 @@ utils_1.addHiddenFinalProp(map, "put", put); | ||
// Q: how to create a map that is not keyed by identifier, but contains objects with identifiers? Is that a use case? A: No, that is were reference maps should come into play... | ||
var identifierAttr = object_1.getIdentifierAttribute(node); | ||
var identifierAttr = object_1.getIdentifierAttribute(node.type); | ||
if (identifierAttr && change.newValue && typeof change.newValue === "object" && change.newValue[identifierAttr] !== change.name) | ||
@@ -191,2 +190,9 @@ utils_1.fail("A map of objects containing an identifier should always store the object under their own identifier. Trying to store key '" + change.name + "', but expected: '" + change.newValue[identifierAttr] + "'"); | ||
}; | ||
Object.defineProperty(MapType.prototype, "identifierAttribute", { | ||
get: function () { | ||
return null; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
return MapType; | ||
@@ -198,6 +204,6 @@ }(complex_type_1.ComplexType)); | ||
exports.MapType = MapType; | ||
function createMapFactory(subtype) { | ||
return with_default_1.createDefaultValueFactory(new MapType("map<string, " + subtype.name + ">", subtype), {}); | ||
function map(subtype) { | ||
return new MapType("map<string, " + subtype.name + ">", subtype); | ||
} | ||
exports.createMapFactory = createMapFactory; | ||
exports.map = map; | ||
function isMapFactory(factory) { | ||
@@ -204,0 +210,0 @@ return type_1.isType(factory) && factory.isMapFactory === true; |
@@ -44,6 +44,6 @@ import { IObjectChange, IObjectWillChange } from "mobx"; | ||
} | ||
export declare function createModelFactory<T>(properties: IModelProperties<T> & ThisType<T>): IModelType<T, {}>; | ||
export declare function createModelFactory<T>(name: string, properties: IModelProperties<T> & ThisType<T>): IModelType<T, {}>; | ||
export declare function createModelFactory<T, A>(properties: IModelProperties<T> & ThisType<T>, operations: A & ThisType<T & A>): IModelType<T, A>; | ||
export declare function createModelFactory<T, A>(name: string, properties: IModelProperties<T> & ThisType<T>, operations: A & ThisType<T & A>): IModelType<T, A>; | ||
export declare function model<T>(properties: IModelProperties<T> & ThisType<T>): IModelType<T, {}>; | ||
export declare function model<T>(name: string, properties: IModelProperties<T> & ThisType<T>): IModelType<T, {}>; | ||
export declare function model<T, A>(properties: IModelProperties<T> & ThisType<T>, operations: A & ThisType<T & A>): IModelType<T, A>; | ||
export declare function model<T, A>(name: string, properties: IModelProperties<T> & ThisType<T>, operations: A & ThisType<T & A>): IModelType<T, A>; | ||
export declare function extend<A, B, AA, BA>(name: string, a: IModelType<A, AA>, b: IModelType<B, BA>): IModelType<A & B, AA & BA>; | ||
@@ -54,2 +54,2 @@ export declare function extend<A, B, C, AA, BA, CA>(name: string, a: IModelType<A, AA>, b: IModelType<B, BA>, c: IModelType<C, CA>): IModelType<A & B & C, AA & BA & CA>; | ||
export declare function isObjectFactory(type: any): boolean; | ||
export declare function getIdentifierAttribute(factory: any): string | null; | ||
export declare function getIdentifierAttribute(type: IType<any, any>): string | null; |
@@ -25,3 +25,3 @@ "use strict"; | ||
var primitives_1 = require("../primitives"); | ||
var with_default_1 = require("../utility-types/with-default"); | ||
var optional_1 = require("../utility-types/optional"); | ||
var reference_1 = require("../utility-types/reference"); | ||
@@ -80,3 +80,3 @@ var identifier_1 = require("../utility-types/identifier"); | ||
var _a = this, baseModel = _a.baseModel, baseActions = _a.baseActions; | ||
var _loop_1 = function (key) { | ||
for (var key in baseModel) | ||
if (utils_1.hasOwnProperty(baseModel, key)) { | ||
@@ -86,35 +86,38 @@ // TODO: check that hooks are not defined as part of baseModel | ||
if ("get" in descriptor) { | ||
this_1.props[key] = new computed_property_1.ComputedProperty(key, descriptor.get, descriptor.set); | ||
return "continue"; | ||
this.props[key] = new computed_property_1.ComputedProperty(key, descriptor.get, descriptor.set); | ||
continue; | ||
} | ||
var value_1 = descriptor.value; | ||
if (value_1 === null || undefined) { | ||
var value = descriptor.value; | ||
if (value === null || undefined) { | ||
utils_1.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 (identifier_1.isIdentifierFactory(value_1)) { | ||
utils_1.invariant(!this_1.identifierAttribute, "Cannot define property '" + key + "' as object identifier, property '" + this_1.identifierAttribute + "' is already defined as identifier property"); | ||
this_1.identifierAttribute = key; | ||
this_1.props[key] = new identifier_property_1.IdentifierProperty(key); | ||
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"); | ||
this.identifierAttribute = key; | ||
this.props[key] = new identifier_property_1.IdentifierProperty(key, value.primitiveType); | ||
} | ||
else if (utils_1.isPrimitive(value_1)) { | ||
var baseType = primitives_1.getPrimitiveFactoryFromValue(value_1); | ||
this_1.props[key] = new value_property_1.ValueProperty(key, with_default_1.createDefaultValueFactory(baseType, value_1)); | ||
else if (utils_1.isPrimitive(value)) { | ||
var baseType = primitives_1.getPrimitiveFactoryFromValue(value); | ||
this.props[key] = new value_property_1.ValueProperty(key, optional_1.optional(baseType, value)); | ||
} | ||
else if (type_1.isType(value_1)) { | ||
this_1.props[key] = new value_property_1.ValueProperty(key, value_1); | ||
else if (type_1.isType(value)) { | ||
this.props[key] = new value_property_1.ValueProperty(key, value); | ||
} | ||
else if (reference_1.isReferenceFactory(value_1)) { | ||
this_1.props[key] = new reference_property_1.ReferenceProperty(key, value_1.targetType, value_1.basePath); | ||
else if (reference_1.isReferenceFactory(value)) { | ||
this.props[key] = new reference_property_1.ReferenceProperty(key, value.targetType, value.basePath); | ||
} | ||
else if (typeof value_1 === "function") { | ||
this_1.props[key] = new view_property_1.ViewProperty(key, value_1); | ||
else if (typeof value === "function") { | ||
this.props[key] = new view_property_1.ViewProperty(key, value); | ||
} | ||
else if (typeof value_1 === "object") { | ||
if (!Array.isArray(value_1) && utils_1.isPlainObject(value_1)) { | ||
this_1.props[key] = new value_property_1.ValueProperty(key, with_default_1.createDefaultValueFactory(createModelFactory(this_1.name + "__" + key, value_1), function () { return value_1; })); | ||
} | ||
else { | ||
// TODO: in future also expand on `[Type]` and `[{ x: 3 }]` | ||
utils_1.fail("In property '" + key + "': base model's should not contain complex values: '" + value_1 + "'"); | ||
} | ||
else if (typeof value === "object") { | ||
// if (!Array.isArray(value) && isPlainObject(value)) { | ||
// TODO: also check if the entire type is simple! (no identifiers and other complex types) | ||
// this.props[key] = new ValueProperty(key, createDefaultValueFactory( | ||
// createModelFactory(this.name + "__" + key, value), | ||
// () => value) | ||
// ) | ||
// } else { | ||
// TODO: in future also expand on `[Type]` and `[{ x: 3 }]` | ||
utils_1.fail("In property '" + key + "': base model's should not contain complex values: '" + value + "'"); | ||
// } | ||
} | ||
@@ -125,7 +128,2 @@ else { | ||
} | ||
}; | ||
var this_1 = this; | ||
for (var key in baseModel) { | ||
_loop_1(key); | ||
} | ||
for (var key in baseActions) | ||
@@ -162,6 +160,3 @@ if (utils_1.hasOwnProperty(baseActions, key)) { | ||
utils_1.invariant(patch.op === "replace" || patch.op === "add"); | ||
this.applySnapshot(node, (_a = {}, | ||
_a[subpath] = patch.value, | ||
_a)); | ||
var _a; | ||
node.target[subpath] = patch.value; | ||
}; | ||
@@ -172,6 +167,4 @@ ObjectType.prototype.applySnapshot = function (node, snapshot) { | ||
node.pseudoAction(function () { | ||
for (var key in snapshot) | ||
if (key in _this.props) { | ||
_this.props[key].deserialize(node.target, snapshot); | ||
} | ||
for (var key in _this.props) | ||
_this.props[key].deserialize(node.target, snapshot); | ||
}); | ||
@@ -220,3 +213,3 @@ }; | ||
exports.ObjectType = ObjectType; | ||
function createModelFactory(arg1, arg2, arg3) { | ||
function model(arg1, arg2, arg3) { | ||
var name = typeof arg1 === "string" ? arg1 : "AnonymousModel"; | ||
@@ -227,3 +220,3 @@ var baseModel = typeof arg1 === "string" ? arg2 : arg1; | ||
} | ||
exports.createModelFactory = createModelFactory; | ||
exports.model = model; | ||
function getObjectFactoryBaseModel(item) { | ||
@@ -241,3 +234,3 @@ var type = type_1.isType(item) ? item : core_1.getType(item); | ||
var factoryName = typeof args[0] === "string" ? args[0] : baseFactories.map(function (f) { return f.name; }).join("_"); | ||
return createModelFactory(factoryName, utils_1.extend.apply(null, [{}].concat(baseFactories.map(getObjectFactoryBaseModel)))); | ||
return model(factoryName, utils_1.extend.apply(null, [{}].concat(baseFactories.map(getObjectFactoryBaseModel)))); | ||
} | ||
@@ -249,6 +242,9 @@ exports.extend = extend; | ||
exports.isObjectFactory = isObjectFactory; | ||
function getIdentifierAttribute(factory) { | ||
return isObjectFactory(factory) ? factory.identifierAttribute : null; | ||
function getIdentifierAttribute(type) { | ||
// TODO: this should be a general property of types | ||
if (type instanceof ObjectType) | ||
return type.identifierAttribute; | ||
return null; | ||
} | ||
exports.getIdentifierAttribute = getIdentifierAttribute; | ||
//# sourceMappingURL=object.js.map |
import { IObservableArray } from "mobx"; | ||
import { IType, ISimpleType } from "./type"; | ||
import { IType, ISimpleType, IComplexType } from "./type"; | ||
import { IExtendedObservableMap } from "./complex-types/map"; | ||
@@ -37,3 +37,3 @@ import { IModelType } from "./complex-types/object"; | ||
}; | ||
withDefault: { | ||
optional: { | ||
<S, T>(type: IType<S, T>, defaultValueOrFunction: S): IType<S, T>; | ||
@@ -54,8 +54,11 @@ <S, T>(type: IType<S, T>, defaultValueOrFunction: T): IType<S, T>; | ||
Date: ISimpleType<Date>; | ||
map: <S, T>(subFactory: IType<S, T>) => IType<{ | ||
map: <S, T>(subtype: IType<S, T>) => IComplexType<{ | ||
[key: string]: S; | ||
}, IExtendedObservableMap<T>>; | ||
array: <S, T>(subFactory: IType<S, T>) => IType<T[], IObservableArray<T>>; | ||
array: <S, T>(subtype: IType<S, T>) => IComplexType<S[], IObservableArray<T>>; | ||
frozen: ISimpleType<any>; | ||
identifier: () => string; | ||
identifier: { | ||
<T>(baseType: IType<T, T>): T; | ||
(): string; | ||
}; | ||
late: { | ||
@@ -62,0 +65,0 @@ <S, T>(type: () => IType<S, T>): IType<S, T>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// tslint:disable-next-line:no_unused-variable | ||
var map_1 = require("./complex-types/map"); | ||
@@ -10,3 +11,3 @@ var array_1 = require("./complex-types/array"); | ||
var union_1 = require("./utility-types/union"); | ||
var with_default_1 = require("./utility-types/with-default"); | ||
var optional_1 = require("./utility-types/optional"); | ||
var literal_1 = require("./utility-types/literal"); | ||
@@ -18,31 +19,11 @@ var maybe_1 = require("./utility-types/maybe"); | ||
var late_1 = require("./utility-types/late"); | ||
/** | ||
* | ||
* | ||
* @export | ||
* @param {ModelFactory} [subFactory=primitiveFactory] | ||
* @returns | ||
*/ | ||
function map(subFactory) { | ||
return map_1.createMapFactory(subFactory); | ||
} | ||
/** | ||
* | ||
* | ||
* @export | ||
* @param {ModelFactory} [subFactory=primitiveFactory] | ||
* @returns | ||
*/ | ||
function array(subFactory) { | ||
return array_1.createArrayFactory(subFactory); | ||
} | ||
exports.types = { | ||
model: object_1.createModelFactory, | ||
model: object_1.model, | ||
extend: object_1.extend, | ||
reference: reference_1.reference, | ||
union: union_1.createUnionFactory, | ||
withDefault: with_default_1.createDefaultValueFactory, | ||
literal: literal_1.createLiteralFactory, | ||
maybe: maybe_1.createMaybeFactory, | ||
refinement: refinement_1.createRefinementFactory, | ||
union: union_1.union, | ||
optional: optional_1.optional, | ||
literal: literal_1.literal, | ||
maybe: maybe_1.maybe, | ||
refinement: refinement_1.refinement, | ||
string: primitives_1.string, | ||
@@ -52,4 +33,4 @@ boolean: primitives_1.boolean, | ||
Date: primitives_1.DatePrimitive, | ||
map: map, | ||
array: array, | ||
map: map_1.map, | ||
array: array_1.array, | ||
frozen: frozen_1.frozen, | ||
@@ -56,0 +37,0 @@ identifier: identifier_1.identifier, |
@@ -8,2 +8,3 @@ import { ISimpleType, Type } from "./type"; | ||
is(thing: any): thing is T; | ||
readonly identifierAttribute: null; | ||
} | ||
@@ -10,0 +11,0 @@ export declare const string: ISimpleType<string>; |
@@ -33,2 +33,9 @@ "use strict"; | ||
}; | ||
Object.defineProperty(CoreType.prototype, "identifierAttribute", { | ||
get: function () { | ||
return null; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
return CoreType; | ||
@@ -35,0 +42,0 @@ }(type_1.Type)); |
import { IObjectWillChange } from "mobx"; | ||
import { Property } from "./property"; | ||
import { IType } from "../type"; | ||
export declare class IdentifierProperty extends Property { | ||
constructor(propertyName: string); | ||
subtype: IType<any, any>; | ||
constructor(propertyName: string, subtype: IType<any, any>); | ||
initialize(target: any, snapshot: any): void; | ||
@@ -10,2 +12,3 @@ willChange(change: IObjectWillChange): IObjectWillChange | null; | ||
isValidSnapshot(snapshot: any): boolean; | ||
isValidIdentifier(identifier: any): boolean; | ||
} |
@@ -17,6 +17,9 @@ "use strict"; | ||
var utils_1 = require("../../utils"); | ||
var type_1 = require("../type"); | ||
var IdentifierProperty = (function (_super) { | ||
__extends(IdentifierProperty, _super); | ||
function IdentifierProperty(propertyName) { | ||
return _super.call(this, propertyName) || this; | ||
function IdentifierProperty(propertyName, subtype) { | ||
var _this = _super.call(this, propertyName) || this; | ||
_this.subtype = subtype; | ||
return _this; | ||
} | ||
@@ -30,15 +33,18 @@ IdentifierProperty.prototype.initialize = function (target, snapshot) { | ||
IdentifierProperty.prototype.willChange = function (change) { | ||
if (!utils_1.isValidIdentifier(change.newValue)) | ||
utils_1.fail("Not a valid identifier: '" + change.newValue); | ||
var identifier = change.newValue; | ||
if (typeof identifier !== "number" && !utils_1.isValidIdentifier(identifier)) | ||
utils_1.fail("Not a valid identifier: '" + identifier); | ||
type_1.typecheck(this.subtype, identifier); | ||
var node = core_1.getMSTAdministration(change.object); | ||
node.assertWritable(); | ||
var oldValue = change.object[this.name]; | ||
if (oldValue !== undefined && oldValue !== change.newValue) | ||
utils_1.fail("It is not allowed to change the identifier of an object, got: '" + change.newValue + "' but expected: '" + oldValue + "'"); | ||
if (oldValue !== undefined && oldValue !== identifier) | ||
utils_1.fail("It is not allowed to change the identifier of an object, got: '" + identifier + "' but expected: '" + oldValue + "'"); | ||
return change; | ||
}; | ||
IdentifierProperty.prototype.serialize = function (instance, snapshot) { | ||
if (!utils_1.isValidIdentifier(instance[this.name])) | ||
utils_1.fail("Object does not have a valid identifier yet: '" + instance[this.name] + "'"); | ||
snapshot[this.name] = instance[this.name]; | ||
var identifier = instance[this.name]; | ||
if (!this.isValidIdentifier(identifier)) | ||
utils_1.fail("Object does not have a valid identifier yet: '" + identifier + "'"); | ||
snapshot[this.name] = identifier; | ||
}; | ||
@@ -49,4 +55,9 @@ IdentifierProperty.prototype.deserialize = function (instance, snapshot) { | ||
IdentifierProperty.prototype.isValidSnapshot = function (snapshot) { | ||
return utils_1.isValidIdentifier(snapshot[this.name]); | ||
return this.isValidIdentifier(snapshot[this.name]); | ||
}; | ||
IdentifierProperty.prototype.isValidIdentifier = function (identifier) { | ||
if (typeof identifier !== "number" && !utils_1.isValidIdentifier(identifier)) | ||
return false; | ||
return this.subtype.is(identifier); | ||
}; | ||
return IdentifierProperty; | ||
@@ -53,0 +64,0 @@ }(property_1.Property)); |
@@ -11,2 +11,3 @@ export interface ISnapshottable<S> { | ||
SnapshotType: S; | ||
identifierAttribute: string | null; | ||
} | ||
@@ -27,4 +28,5 @@ export interface ISimpleType<T> extends IType<T, T> { | ||
readonly SnapshotType: S; | ||
readonly abstract identifierAttribute: string | null; | ||
} | ||
export declare function typecheck(type: IType<any, any>, value: any): void; | ||
import { IMSTNode } from "../core/mst-node"; |
@@ -34,3 +34,3 @@ "use strict"; | ||
utils_1.fail("Value" + currentTypename + " '" + (utils_1.isSerializable(value) ? JSON.stringify(value) : value) + "' is not assignable to type: " + type.name + | ||
(primitives_1.isPrimitiveType(type) || (type instanceof with_default_1.DefaultValue && primitives_1.isPrimitiveType(type.type)) | ||
(primitives_1.isPrimitiveType(type) || (type instanceof optional_1.OptionalValue && primitives_1.isPrimitiveType(type.type)) | ||
? "." | ||
@@ -45,3 +45,3 @@ : (", expected an instance of " + type.name + " or a snapshot like '" + type.describe() + "' instead." + | ||
var primitives_1 = require("./primitives"); | ||
var with_default_1 = require("./utility-types/with-default"); | ||
var optional_1 = require("./utility-types/optional"); | ||
//# sourceMappingURL=type.js.map |
@@ -7,3 +7,4 @@ import { ISimpleType, Type } from "../type"; | ||
is(value: any): value is T; | ||
readonly identifierAttribute: null; | ||
} | ||
export declare const frozen: ISimpleType<any>; |
@@ -42,2 +42,9 @@ "use strict"; | ||
}; | ||
Object.defineProperty(Frozen.prototype, "identifierAttribute", { | ||
get: function () { | ||
return null; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
return Frozen; | ||
@@ -44,0 +51,0 @@ }(type_1.Type)); |
@@ -1,5 +0,8 @@ | ||
export interface IIdentifierDescriptor { | ||
import { IType } from "../type"; | ||
export interface IIdentifierDescriptor<T> { | ||
isIdentifier: true; | ||
primitiveType: IType<T, T>; | ||
} | ||
export declare function identifier<T>(baseType: IType<T, T>): T; | ||
export declare function identifier(): string; | ||
export declare function isIdentifierFactory(thing: any): thing is IIdentifierDescriptor; | ||
export declare function isIdentifierFactory(thing: any): thing is IIdentifierDescriptor<any>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
// TODO: properly turn this into a factory, that reuses `types.string`? | ||
// See: https://github.com/mobxjs/mobx-state-tree/pull/65#issuecomment-289603441 | ||
// todo: change to const `types.identifier` | ||
function identifier() { | ||
var primitives_1 = require("../primitives"); | ||
var utils_1 = require("../../utils"); | ||
function identifier(baseType) { | ||
if (baseType === void 0) { baseType = primitives_1.string; } | ||
if (baseType !== primitives_1.string && baseType !== primitives_1.number) | ||
utils_1.fail("Only 'types.number' and 'types.string' are acceptable as type specification for identifiers"); | ||
return { | ||
isIdentifier: true | ||
isIdentifier: true, | ||
primitiveType: baseType | ||
}; | ||
@@ -10,0 +13,0 @@ } |
@@ -10,2 +10,3 @@ import { Type, IType } from "../type"; | ||
is(value: any): value is T; | ||
readonly identifierAttribute: string | null; | ||
} | ||
@@ -12,0 +13,0 @@ export declare type ILateType<S, T> = () => IType<S, T>; |
@@ -43,2 +43,9 @@ "use strict"; | ||
}; | ||
Object.defineProperty(Late.prototype, "identifierAttribute", { | ||
get: function () { | ||
return this.subType.identifierAttribute; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
return Late; | ||
@@ -45,0 +52,0 @@ }(type_1.Type)); |
@@ -5,6 +5,7 @@ import { ISimpleType, Type } from "../type"; | ||
constructor(value: any); | ||
create(): any; | ||
create(snapshot: any): any; | ||
describe(): string; | ||
is(value: any): value is T; | ||
readonly identifierAttribute: null; | ||
} | ||
export declare function createLiteralFactory<S>(value: S): ISimpleType<S>; | ||
export declare function literal<S>(value: S): ISimpleType<S>; |
@@ -13,3 +13,2 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var with_default_1 = require("./with-default"); | ||
var type_1 = require("../type"); | ||
@@ -24,3 +23,4 @@ var utils_1 = require("../../utils"); | ||
} | ||
Literal.prototype.create = function () { | ||
Literal.prototype.create = function (snapshot) { | ||
type_1.typecheck(this, snapshot); | ||
return this.value; | ||
@@ -34,10 +34,17 @@ }; | ||
}; | ||
Object.defineProperty(Literal.prototype, "identifierAttribute", { | ||
get: function () { | ||
return null; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
return Literal; | ||
}(type_1.Type)); | ||
exports.Literal = Literal; | ||
function createLiteralFactory(value) { | ||
function literal(value) { | ||
utils_1.invariant(utils_1.isPrimitive(value), "Literal types can be built only on top of primitives"); | ||
return with_default_1.createDefaultValueFactory(new Literal(value), value); | ||
return new Literal(value); | ||
} | ||
exports.createLiteralFactory = createLiteralFactory; | ||
exports.literal = literal; | ||
//# sourceMappingURL=literal.js.map |
import { IType } from "../type"; | ||
export declare function createMaybeFactory<S, T>(type: IType<S, T>): IType<S | null | undefined, T | null>; | ||
export declare function maybe<S, T>(type: IType<S, T>): IType<S | null | undefined, T | null>; |
@@ -5,7 +5,9 @@ "use strict"; | ||
var literal_1 = require("./literal"); | ||
var nullFactory = literal_1.createLiteralFactory(null); | ||
function createMaybeFactory(type) { | ||
return union_1.createUnionFactory(nullFactory, type); | ||
var optional_1 = require("./optional"); | ||
var nullType = optional_1.optional(literal_1.literal(null), null); | ||
function maybe(type) { | ||
// TODO: is identifierAttr correct for maybe? | ||
return union_1.union(nullType, type); | ||
} | ||
exports.createMaybeFactory = createMaybeFactory; | ||
exports.maybe = maybe; | ||
//# sourceMappingURL=maybe.js.map |
@@ -9,4 +9,5 @@ import { IType, Type } from "../type"; | ||
is(value: any): value is any; | ||
readonly identifierAttribute: string | null; | ||
} | ||
export declare function createRefinementFactory<T>(name: string, type: IType<T, T>, predicate: (snapshot: T) => boolean): IType<T, T>; | ||
export declare function createRefinementFactory<S, T extends S, U extends S>(name: string, type: IType<S, T>, predicate: (snapshot: S) => snapshot is U): IType<S, U>; | ||
export declare function refinement<T>(name: string, type: IType<T, T>, predicate: (snapshot: T) => boolean): IType<T, T>; | ||
export declare function refinement<S, T extends S, U extends S>(name: string, type: IType<S, T>, predicate: (snapshot: S) => snapshot is U): IType<S, U>; |
@@ -38,6 +38,13 @@ "use strict"; | ||
}; | ||
Object.defineProperty(Refinement.prototype, "identifierAttribute", { | ||
get: function () { | ||
return this.type.identifierAttribute; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
return Refinement; | ||
}(type_1.Type)); | ||
exports.Refinement = Refinement; | ||
function createRefinementFactory(name, type, predicate) { | ||
function refinement(name, type, predicate) { | ||
// check if the subtype default value passes the predicate | ||
@@ -48,3 +55,3 @@ var inst = type.create(); | ||
} | ||
exports.createRefinementFactory = createRefinementFactory; | ||
exports.refinement = refinement; | ||
//# sourceMappingURL=refinement.js.map |
@@ -10,4 +10,5 @@ import { IType, Type } from "../type"; | ||
is(value: any): value is any; | ||
readonly identifierAttribute: string | null; | ||
} | ||
export declare function createUnionFactory<SA, SB, TA, TB>(dispatch: ITypeDispatcher, A: IType<SA, TA>, B: IType<SB, TB>): IType<SA | SB, TA | TB>; | ||
export declare function createUnionFactory<SA, SB, TA, TB>(A: IType<SA, TA>, B: IType<SB, TB>): IType<SA | SB, TA | TB>; | ||
export declare function union<SA, SB, TA, TB>(dispatch: ITypeDispatcher, A: IType<SA, TA>, B: IType<SB, TB>): IType<SA | SB, TA | TB>; | ||
export declare function union<SA, SB, TA, TB>(A: IType<SA, TA>, B: IType<SB, TB>): IType<SA | SB, TA | TB>; |
@@ -42,6 +42,16 @@ "use strict"; | ||
}; | ||
Object.defineProperty(Union.prototype, "identifierAttribute", { | ||
get: function () { | ||
var identifier0 = this.types[0].identifierAttribute; | ||
if (identifier0 && this.types.every(function (type) { return type.identifierAttribute === identifier0; })) | ||
return identifier0; | ||
return null; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
return Union; | ||
}(type_1.Type)); | ||
exports.Union = Union; | ||
function createUnionFactory(dispatchOrType) { | ||
function union(dispatchOrType) { | ||
var otherTypes = []; | ||
@@ -56,3 +66,3 @@ for (var _i = 1; _i < arguments.length; _i++) { | ||
} | ||
exports.createUnionFactory = createUnionFactory; | ||
exports.union = union; | ||
//# sourceMappingURL=union.js.map |
@@ -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(2),n(10);var i=n(23);e.types=i.types,r(n(6)),r(n(9));var o=n(4);e.isMST=o.isMST,e.getType=o.getType,e.getChildType=o.getChildType,e.onAction=o.onAction,e.applyAction=o.applyAction;var a=n(20);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 c(t){return!(null===t||"object"!=typeof t||t instanceof Date||t instanceof RegExp)}function u(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.fail=n,e.invariant=r,e.identity=i,e.nothing=o,e.extend=a,e.isPlainObject=s,e.isMutable=c,e.isPrimitive=u,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){return"object"==typeof t&&t&&t.isType===!0}function i(t,e){if(!t.is(e)){var n=s.maybeMST(e,function(t){return" of type "+t.type.name+":"},function(){return""}),r=s.isMST(e)&&t.is(s.getMSTAdministration(e).snapshot);a.fail("Value"+n+" '"+(a.isSerializable(e)?JSON.stringify(e):e)+"' is not assignable to type: "+t.name+(c.isPrimitiveType(t)||t instanceof u.DefaultValue&&c.isPrimitiveType(t.type)?".":", expected an instance of "+t.name+" or a snapshot like '"+t.describe()+"' instead."+(r?" (Note that a snapshot of the provided value is compatible with the targeted type)":"")))}}Object.defineProperty(e,"__esModule",{value:!0}),e.isType=r;var o=function(){function t(t){this.isType=!0,this.name=t}return 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,e.typecheck=i;var a=n(1),s=n(5),c=n(13),u=n(8)},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(5)),r(n(14)),r(n(12)),r(n(9)),r(n(6))},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 c(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 u(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=c,e.getRelativePathForNodes=u;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);R.runInAction(function(){e.forEach(function(t){return n.applyPatch(t)})})}function c(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 u(t,e){R.runInAction(function(){e.forEach(function(e){return I.applyAction(t,e)})})}function p(t){var e={actions:[],stop:function(){return n()},replay:function(t){u(t,e.actions)}},n=I.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),k.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),k.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 k.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 D.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 w(t,e){return z.getRelativePathForNodes(z.getMSTAdministration(t),z.getMSTAdministration(e))}function j(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 O(t){var e=z.getMSTAdministration(t);e.isRoot?e.die():e.parent.removeChild(e.subpath)}function M(t){return z.getMSTAdministration(t).isAlive}function x(t,e){z.getMSTAdministration(t).addDisposer(e)}function C(t){var e=z.getMSTAdministration(t),n=e.root._environment;return k.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 V(t,e){var n=z.getMSTAdministration(t);n.getChildMSTs().forEach(function(t){var n=(t[0],t[1]);V(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 u(i,n),y(i)}Object.defineProperty(e,"__esModule",{value:!0});var I=n(12),R=n(3),z=n(5),D=n(9),k=n(1);e.addMiddleware=r,e.onPatch=i,e.onSnapshot=o,e.applyPatch=a,e.applyPatches=s,e.recordPatches=c,e.applyActions=u,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=w,e.clone=j,e.detach=S,e.destroy=O,e.isAlive=M,e.addDisposer=x,e.getEnv=C,e.walk=V,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,n){"use strict";function r(t,e){var n="function"==typeof e?e():e,r=s.isMST(n)?s.getMSTAdministration(n).snapshot:n;return o.typecheck(t,r),new a(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(2),a=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=s.isMST(e)?s.getMSTAdministration(e).snapshot:e;return this.type.create(n)}return this.type.create(t)},e.prototype.is=function(t){return void 0===t||this.type.is(t)},e}(o.Type);e.DefaultValue=a,e.createDefaultValueFactory=r;var s=n(5)},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";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(3),o=n(2),a=function(t){function e(e){var n=t.call(this,e)||this;return n.create=i.action(n.name,n.create),n}return r(e,t),e.prototype.create=function(t,e,n,r){var i=this;void 0===t&&(t=this.getDefaultSnapshot()),void 0===e&&(e=void 0),void 0===n&&(n=null),void 0===r&&(r=""),o.typecheck(this,t);var a=this.createNewInstance(),s=new c.MSTAdministration(n,r,a,this,e);return s.pseudoAction(function(){i.finalizeNewInstance(a,t)}),s.fireHook("afterCreate"),n&&s.fireHook("afterAttach"),a},e.prototype.is=function(t){return!(!t||"object"!=typeof t)&&(s.isMST(t)?s.getType(t)===this:this.isValidSnapshot(t))},e}(o.Type);e.ComplexType=a;var s=n(5),c=n(14)},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 S(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 c(t){return s(t)?t.identifierAttribute:null}var u=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(3),l=n(1),h=n(4),d=n(2),y=n(10),v=n(13),b=n(8),g=n(17),m=n(15),_=n(26),P=n(27),T=n(25),A=n(28),w=n(24),j=n(29),S=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 u(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,r=function(t){if(l.hasOwnProperty(e,t)){var n=Object.getOwnPropertyDescriptor(e,t);if("get"in n)return o.props[t]=new T.ComputedProperty(t,n.get,n.set),"continue";var r=n.value;if(null===r)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(m.isIdentifierFactory(r))l.invariant(!o.identifierAttribute,"Cannot define property '"+t+"' as object identifier, property '"+o.identifierAttribute+"' is already defined as identifier property"),o.identifierAttribute=t,o.props[t]=new _.IdentifierProperty(t);else if(l.isPrimitive(r)){var a=v.getPrimitiveFactoryFromValue(r);o.props[t]=new A.ValueProperty(t,b.createDefaultValueFactory(a,r))}else d.isType(r)?o.props[t]=new A.ValueProperty(t,r):g.isReferenceFactory(r)?o.props[t]=new P.ReferenceProperty(t,r.targetType,r.basePath):"function"==typeof r?o.props[t]=new j.ViewProperty(t,r):"object"==typeof r?!Array.isArray(r)&&l.isPlainObject(r)?o.props[t]=new A.ValueProperty(t,b.createDefaultValueFactory(i(o.name+"__"+t,r),function(){return r})):l.fail("In property '"+t+"': base model's should not contain complex values: '"+r+"'"):l.fail("Unexpected value for property '"+t+"'")}},o=this;for(var a in e)r(a);for(var a in n)if(l.hasOwnProperty(n,a)){var s=n[a];a in this.baseModel&&l.fail("Property '"+a+"' was also defined as action. Actions and properties should not collide"),"function"==typeof s?this.props[a]=new w.ActionProperty(a,s):l.fail("Unexpected value for action '"+a+"'. Expected function, got "+typeof s)}},e.prototype.getChildMSTs=function(t){var e=[];return this.forAllProps(function(n){n instanceof A.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),this.applySnapshot(t,(r={},r[e]=n.value,r));var r},e.prototype.applySnapshot=function(t,e){var n=this;t.pseudoAction(function(){for(var r in e)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){if(!l.isPlainObject(t))return!1;for(var e in this.props)if(!this.props[e].isValidSnapshot(t))return!1;return!0},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 A.ValueProperty?e+": "+n.type.describe():n instanceof _.IdentifierProperty?e+": identifier":""}).filter(Boolean).join("; ")+" }"},e.prototype.getDefaultSnapshot=function(){return{}},e.prototype.removeChild=function(t,e){t.target[e]=null},e}(y.ComplexType);p([f.action],S.prototype,"applySnapshot",null),e.ObjectType=S,e.createModelFactory=i,e.extend=a,e.isObjectFactory=s,e.getIdentifierAttribute=c},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))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 c(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 u(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 c(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(3);e.createActionInvoker=a,e.applyAction=u,e.onAction=p;var l=n(5),h=n(6),d=n(1)},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 s.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(2),s=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 s.invariant(s.isPrimitive(t),"Not a primitive: '"+t+"'"),s.invariant(this.checker(t),"Value is not assignable to '"+this.name+"'"),t},e.prototype.is=function(t){return s.isPrimitive(t)&&this.checker(t)},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";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(3),o=n(2),a=n(5),s=n(1),c=n(9),u=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 c=i.reaction(function(){return a.snapshot},function(t){a.snapshotSubscribers.forEach(function(e){return e(t)})});c.onError(function(t){throw t}),this.addDisposer(c)}return Object.defineProperty(t.prototype,"path",{get:function(){return this.parent?this.parent.path+"/"+c.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(){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=c.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,c=new Array(n.length),p={},f={},l=u.getIdentifierAttribute(t);e.forEach(function(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 u=""+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+"/"+u+"', but it lives already at '"+h.path+"'");p[h.nodeId]=void 0,h.setParent(i,u),c[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,u),h.applySnapshot(e),c[n]=y):c[n]=t.create(e,void 0,i,u)}else o.typecheck(t,e),c[n]=t.create(e,void 0,i,u)});for(var h in p)p[h]&&a.getMSTAdministration(p[h]).die();return c},t.prototype.resolve=function(t,e){return void 0===e&&(e=!0),this.resolvePath(c.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 '"+c.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=u.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(6)},function(t,e){"use strict";function n(){return{isIdentifier:!0}}function r(t){return"object"==typeof t&&t&&t.isIdentifier===!0}Object.defineProperty(e,"__esModule",{value:!0}),e.identifier=n,e.isIdentifierFactory=r},function(t,e,n){"use strict";function r(t){return s.invariant(s.isPrimitive(t),"Literal types can be built only on top of primitives"),o.createDefaultValueFactory(new c(t),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(8),a=n(2),s=n(1),c=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(){return this.value},e.prototype.describe=function(){return JSON.stringify(this.value)},e.prototype.is=function(t){return t===this.value&&s.isPrimitive(t)},e}(a.Type);e.Literal=c,e.createLiteralFactory=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 s(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(2),a=n(1),s=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.invariant(this.is(t),"Value "+JSON.stringify(t)+" is not assignable to union "+this.name),null!==this.dispatcher)return this.dispatcher(t).create(t);var e=this.types.filter(function(e){return e.is(t)});return e.length>1?a.fail("Ambiguos snapshot "+JSON.stringify(t)+" for union "+this.name+". Please provide a dispatch in the union declaration."):e[0].create(t); | ||
},e.prototype.is=function(t){return this.types.some(function(e){return e.is(t)})},e}(o.Type);e.Union=s,e.createUnionFactory=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(3),o=n(5),a=n(1),s=n(11),c=n(2),u=n(6),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=u.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 u.resolve(this.owner,n)},enumerable:!0,configurable:!0}),t.prototype.setNewValue=function(t){if(t)if(o.isMST(t)){c.typecheck(this.type,t);var e=o.getMSTAdministration(this.owner),n=o.getMSTAdministration(t);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.targetIdAttribute?this.identifier=t[this.targetIdAttribute]: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 c.getSnapshot(t)},dispatch:function(e){o(e,a.slice(),function(e){return u.applyAction(t,i(e))})},subscribe:function(e){return c.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,c.applySnapshot(e,i),r=!1)}),u.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,c.getSnapshot(e))}})}Object.defineProperty(e,"__esModule",{value:!0});var s=n(4),c=n(6),u=n(12),p=n(1);e.asReduxStore=r,e.connectReduxDevtools=a},function(t,e,n){"use strict";function r(){return u.getMSTAdministration(this)+"("+this.length+" items)"}function i(t){return h.createDefaultValueFactory(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 c=n(3),u=n(4),p=n(1),f=n(2),l=n(10),h=n(8);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=c.observable.shallowArray();return p.addHiddenFinalProp(t,"toString",r),t},e.prototype.finalizeNewInstance=function(t,e){var n=this;c.intercept(t,function(t){return n.willChange(t)}),c.observe(t,this.didChange),u.getMSTAdministration(t).applySnapshot(e)},e.prototype.getChildMSTs=function(t){var e=t.target,n=[];return e.forEach(function(t,e){u.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?u.maybeMST(n[r],p.identity,p.nothing):null},e.prototype.willChange=function(t){var e=u.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){u.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(u.valueToSnapshot)},e.prototype.didChange=function(t){var e=u.getMSTAdministration(t.object);switch(t.type){case"update":return void e.emitPatch({op:"replace",path:""+t.index,value:u.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:u.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){var e=this;return Array.isArray(t)&&t.every(function(t){return e.subType.is(t)})},e.prototype.getDefaultSnapshot=function(){return[]},e.prototype.removeChild=function(t,e){t.target.splice(parseInt(e,10),1)},e}(l.ComplexType);s([c.action],d.prototype,"applySnapshot",null),e.ArrayType=d,e.createArrayFactory=i,e.isArrayFactory=o},function(t,e,n){"use strict";function r(){return l.getMSTAdministration(this)+"("+this.size+" items)"}function i(t){var e=p.getIdentifierAttribute(l.getMSTAdministration(this).type.subType);return h.invariant(!!e,"Map.put is only supported if the subtype has an idenfier attribute"),h.invariant(!!t,"Map.put cannot be used to set empty values"),this.set(t[e],t),this}function o(t){return u.createDefaultValueFactory(new v("map<string, "+t.name+">",t),{})}function a(t){return d.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)}}(),c=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(8),p=n(11),f=n(3),l=n(4),h=n(1),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.getIdentifierAttribute(this.subType),f.observable.shallowMap());return h.addHiddenFinalProp(t,"put",i),h.addHiddenFinalProp(t,"toString",r),t},e.prototype.finalizeNewInstance=function(t,e){var n=this;f.intercept(t,function(t){return n.willChange(t)}),f.observe(t,this.didChange),l.getMSTAdministration(t).applySnapshot(e)},e.prototype.getChildMSTs=function(t){var e=[];return t.target.forEach(function(t,n){l.maybeMST(t,function(t){e.push([n,t])})}),e},e.prototype.getChildMST=function(t,e){var n=t.target;return n.has(e)?l.maybeMST(n.get(e),h.identity,h.nothing):null},e.prototype.willChange=function(t){var e=l.getMSTAdministration(t.object);e.assertWritable();var n=p.getIdentifierAttribute(e);switch(n&&t.newValue&&"object"==typeof t.newValue&&t.newValue[n]!==t.name&&h.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]=l.valueToSnapshot(t)}),n},e.prototype.didChange=function(t){var e=l.getMSTAdministration(t.object);switch(t.type){case"update":case"add":return void e.emitPatch({op:"add"===t.type?"add":"replace",path:l.escapeJsonPath(t.name),value:l.valueToSnapshot(t.newValue)},e);case"delete":return void e.emitPatch({op:"remove",path:l.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=p.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]&&h.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&&!h.isPrimitive(n)?(o[t]=!0,l.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){var e=this;return h.isPlainObject(t)&&Object.keys(t).every(function(n){return e.subType.is(t[n])})},e.prototype.getDefaultSnapshot=function(){return{}},e.prototype.removeChild=function(t,e){t.target.delete(e)},e}(y.ComplexType);c([f.action],v.prototype,"applySnapshot",null),e.MapType=v,e.createMapFactory=o,e.isMapFactory=a},function(t,e,n){"use strict";function r(t){return o.createMapFactory(t)}function i(t){return a.createArrayFactory(t)}Object.defineProperty(e,"__esModule",{value:!0});var o=n(22),a=n(21),s=n(15),c=n(11),u=n(17),p=n(18),f=n(8),l=n(16),h=n(32),d=n(33),y=n(30),v=n(13),b=n(31);e.types={model:c.createModelFactory,extend:c.extend,reference:u.reference,union:p.createUnionFactory,withDefault:f.createDefaultValueFactory,literal:l.createLiteralFactory,maybe:h.createMaybeFactory,refinement:d.createRefinementFactory,string:v.string,boolean:v.boolean,number:v.number,Date:v.DatePrimitive,map:r,array:i,frozen:y.frozen,identifier:s.identifier,late:b.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(4),a=n(7),s=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.isValidSnapshot=function(t){return!(this.name in t)},e}(a.Property);e.ActionProperty=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(3),o=n(7),a=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.isValidSnapshot=function(t){return!(this.name in t)},e}(o.Property);e.ComputedProperty=a},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(3),a=n(7),s=n(1),c=function(t){function e(e){return t.call(this,e)||this}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){s.isValidIdentifier(t.newValue)||s.fail("Not a valid identifier: '"+t.newValue);var e=i.getMSTAdministration(t.object);e.assertWritable();var n=t.object[this.name];return void 0!==n&&n!==t.newValue&&s.fail("It is not allowed to change the identifier of an object, got: '"+t.newValue+"' but expected: '"+n+"'"),t},e.prototype.serialize=function(t,e){s.isValidIdentifier(t[this.name])||s.fail("Object does not have a valid identifier yet: '"+t[this.name]+"'"),e[this.name]=t[this.name]},e.prototype.deserialize=function(t,e){t[this.name]=e[this.name]},e.prototype.isValidSnapshot=function(t){return s.isValidIdentifier(t[this.name])},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(7),o=n(1),a=n(4),s=n(19),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.isValidSnapshot=function(t){return this.name in t},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(3),o=n(7),a=n(4),s=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.isValidSnapshot=function(t){return this.type.is(t[this.name])},e}(o.Property);e.ValueProperty=s},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(3),a=n(1),s=n(4),c=n(7),u=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.isValidSnapshot=function(t){return!(this.name in t)},e}(c.Property);e.ViewProperty=u,e.createViewInvoker=r},function(t,e,n){"use strict";function r(t){return Object.freeze(t),a.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(2),a=n(1),s=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 a.invariant(a.isSerializable(t),"Given value should be serializable"),a.isMutable(t)?r(t):t},e.prototype.is=function(t){return a.isSerializable(t)},e}(o.Type);e.Frozen=s,e.frozen=new s},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(2),s=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.is=function(t){return this.subType.is(t)},e}(a.Type);e.Late=s,e.late=r},function(t,e,n){"use strict";function r(t){return i.createUnionFactory(a,t)}Object.defineProperty(e,"__esModule",{value:!0});var i=n(18),o=n(16),a=o.createLiteralFactory(null);e.createMaybeFactory=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(2),a=n(1),s=n(4),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.is=function(t){return this.type.is(t)&&this.predicate(t)},e}(o.Type);e.Refinement=c,e.createRefinementFactory=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(2),n(9);var i=n(23);e.types=i.types,r(n(6)),r(n(8));var o=n(4);e.isMST=o.isMST,e.getType=o.getType,e.getChildType=o.getChildType,e.onAction=o.onAction,e.applyAction=o.applyAction;var a=n(20);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.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){return"object"==typeof t&&t&&t.isType===!0}function i(t,e){if(!t.is(e)){var n=s.maybeMST(e,function(t){return" of type "+t.type.name+":"},function(){return""}),r=s.isMST(e)&&t.is(s.getMSTAdministration(e).snapshot);a.fail("Value"+n+" '"+(a.isSerializable(e)?JSON.stringify(e):e)+"' is not assignable to type: "+t.name+(u.isPrimitiveType(t)||t instanceof c.OptionalValue&&u.isPrimitiveType(t.type)?".":", expected an instance of "+t.name+" or a snapshot like '"+t.describe()+"' instead."+(r?" (Note that a snapshot of the provided value is compatible with the targeted type)":"")))}}Object.defineProperty(e,"__esModule",{value:!0}),e.isType=r;var o=function(){function t(t){this.isType=!0,this.name=t}return 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,e.typecheck=i;var a=n(1),s=n(5),u=n(11),c=n(12)},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(5)),r(n(14)),r(n(13)),r(n(8)),r(n(6))},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(8);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=k.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 k.getMSTAdministration(t).onPatch(e)}function o(t,e){return k.getMSTAdministration(t).onSnapshot(e)}function a(t,e){return k.getMSTAdministration(t).applyPatch(e)}function s(t,e){var n=k.getMSTAdministration(t);z.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){z.runInAction(function(){e.forEach(function(e){return V.applyAction(t,e)})})}function p(t){var e={actions:[],stop:function(){return n()},replay:function(t){c(t,e.actions)}},n=V.onAction(t,e.actions.push.bind(e.actions));return e}function f(t){k.getMSTAdministration(t).isProtectionEnabled=!0}function l(t){k.getMSTAdministration(t).isProtectionEnabled=!1}function h(t){return k.getMSTAdministration(t).isProtectionEnabled}function d(t,e){return k.getMSTAdministration(t).applySnapshot(e)}function y(t){return k.getMSTAdministration(t).snapshot}function v(t,e){void 0===e&&(e=1),F.invariant(e>=0,"Invalid depth: "+e+", should be >= 1");for(var n=k.getMSTAdministration(t).parent;n;){if(0===--e)return!0;n=n.parent}return!1}function b(t,e){void 0===e&&(e=1),F.invariant(e>=0,"Invalid depth: "+e+", should be >= 1");for(var n=e,r=k.getMSTAdministration(t).parent;r;){if(0===--n)return r.target;r=r.parent}return F.fail("Failed to find the parent of "+k.getMSTAdministration(t)+" at depth "+e)}function g(t){return k.getMSTAdministration(t).root.target}function m(t){return k.getMSTAdministration(t).path}function _(t){return E.splitJsonPath(k.getMSTAdministration(t).path)}function P(t){return k.getMSTAdministration(t).isRoot}function T(t,e){var n=k.getMSTAdministration(t).resolve(e);return n?n.target:void 0}function A(t,e){var n=k.getMSTAdministration(t).resolve(e,!1);if(void 0!==n)return n?n.target:void 0}function j(t,e){return k.getRelativePathForNodes(k.getMSTAdministration(t),k.getMSTAdministration(e))}function O(t,e){void 0===e&&(e=!0);var n=k.getMSTAdministration(t);return n.type.create(n.snapshot,e===!0?n.root._environment:e===!1?void 0:e)}function S(t){return k.getMSTAdministration(t).detach(),t}function w(t){var e=k.getMSTAdministration(t);e.isRoot?e.die():e.parent.removeChild(e.subpath)}function M(t){return k.getMSTAdministration(t).isAlive}function x(t,e){k.getMSTAdministration(t).addDisposer(e)}function C(t){var e=k.getMSTAdministration(t),n=e.root._environment;return F.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 I(t,e){var n=k.getMSTAdministration(t);n.getChildMSTs().forEach(function(t){var n=(t[0],t[1]);I(n.target,e)}),e(n.target)}function R(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 V=n(13),z=n(3),k=n(5),E=n(8),F=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=x,e.getEnv=C,e.walk=I,e.testActions=R},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 c.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(3),a=n(2),s=n(1),u=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=""),a.typecheck(this,t);var u=this.createNewInstance(),c=new p.MSTAdministration(n,i,u,this,e),f=!0;try{return c.pseudoAction(function(){o.finalizeNewInstance(u,t)}),s.addReadOnlyProp(u,"toJSON",r),c.fireHook("afterCreate"),n&&c.fireHook("afterAttach"),f=!1,u}finally{f&&(c._isAlive=!1)}},e.prototype.is=function(t){return!(!t||"object"!=typeof t)&&(c.isMST(t)?c.getType(t)===this:this.isValidSnapshot(t))},e}(a.Type);e.ComplexType=u;var c=n(5),p=n(14)},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 S(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 S?t.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(3),l=n(1),h=n(4),d=n(2),y=n(9),v=n(11),b=n(12),g=n(17),m=n(15),_=n(26),P=n(27),T=n(25),A=n(28),j=n(24),O=n(29),S=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 T.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(m.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 _.IdentifierProperty(r,o.primitiveType);else if(l.isPrimitive(o)){var a=v.getPrimitiveFactoryFromValue(o);this.props[r]=new A.ValueProperty(r,b.optional(a,o))}else d.isType(o)?this.props[r]=new A.ValueProperty(r,o):g.isReferenceFactory(o)?this.props[r]=new P.ReferenceProperty(r,o.targetType,o.basePath):"function"==typeof o?this.props[r]=new O.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 j.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 A.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){if(!l.isPlainObject(t))return!1;for(var e in this.props)if(!this.props[e].isValidSnapshot(t))return!1;return!0},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 A.ValueProperty?e+": "+n.type.describe():n instanceof _.IdentifierProperty?e+": identifier":""}).filter(Boolean).join("; ")+" }"},e.prototype.getDefaultSnapshot=function(){return{}},e.prototype.removeChild=function(t,e){t.target[e]=null},e}(y.ComplexType);p([f.action],S.prototype,"applySnapshot",null),e.ObjectType=S,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 s.fail("Cannot determine primtive type from value "+t)}function i(t){return t instanceof u}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(2),s=n(1),u=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 s.invariant(s.isPrimitive(t),"Not a primitive: '"+t+"'"),s.invariant(this.checker(t),"Value is not assignable to '"+this.name+"'"),t},e.prototype.is=function(t){return s.isPrimitive(t)&&this.checker(t)},Object.defineProperty(e.prototype,"identifierAttribute",{get:function(){return null},enumerable:!0,configurable:!0}),e}(a.Type);e.CoreType=u,e.string=new u("string",function(t){return"string"==typeof t}),e.number=new u("number",function(t){return"number"==typeof t}),e.boolean=new u("boolean",function(t){return"boolean"==typeof t}),e.DatePrimitive=new u("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=s.isMST(n)?s.getMSTAdministration(n).snapshot:n;return o.typecheck(t,r),new a(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(2),a=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=s.isMST(e)?s.getMSTAdministration(e).snapshot:e;return this.type.create(n)}return this.type.create(t)},e.prototype.is=function(t){return void 0===t||this.type.is(t)},Object.defineProperty(e.prototype,"identifierAttribute",{get:function(){return this.type.identifierAttribute},enumerable:!0,configurable:!0}),e}(o.Type);e.OptionalValue=a,e.optional=r;var s=n(5)},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))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(3);e.createActionInvoker=a,e.applyAction=c,e.onAction=p;var l=n(5),h=n(6),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(3),o=n(2),a=n(5),s=n(1),u=n(8),c=n(10),p=n(9),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(6)},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(11),a=n(1);e.identifier=r,e.isIdentifierFactory=i},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 s(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(2),a=n(1),s=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 o.typecheck(this,t),this.value},e.prototype.describe=function(){return JSON.stringify(this.value)},e.prototype.is=function(t){return t===this.value&&a.isPrimitive(t)},Object.defineProperty(e.prototype,"identifierAttribute",{get:function(){return null},enumerable:!0,configurable:!0}),e}(o.Type);e.Literal=s,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 s(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(2),a=n(1),s=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.invariant(this.is(t),"Value "+JSON.stringify(t)+" is not assignable to union "+this.name),null!==this.dispatcher)return this.dispatcher(t).create(t);var e=this.types.filter(function(e){return e.is(t)});return e.length>1?a.fail("Ambiguos snapshot "+JSON.stringify(t)+" for union "+this.name+". Please provide a dispatch in the union declaration."):e[0].create(t)},e.prototype.is=function(t){return this.types.some(function(e){return e.is(t)})},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=s,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(3),o=n(5),a=n(1),s=n(10),u=n(2),c=n(6),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(4),u=n(6),c=n(13),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 h(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(3),c=n(4),p=n(1),f=n(2),l=n(9);e.arrayToString=r;var h=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){var e=this;return Array.isArray(t)&&t.every(function(t){return e.subType.is(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}(l.ComplexType);s([u.action],h.prototype,"applySnapshot",null),e.ArrayType=h,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 y("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(10),p=n(3),f=n(4),l=n(1),h=n(2),d=n(9);e.mapToString=r;var y=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){var e=this;return l.isPlainObject(t)&&Object.keys(t).every(function(n){return e.subType.is(t[n])})},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}(d.ComplexType);u([p.action],y.prototype,"applySnapshot",null),e.MapType=y,e.map=o,e.isMapFactory=a},function(t,e,n){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var r=n(22),i=n(21),o=n(15),a=n(10),s=n(17),u=n(18),c=n(12),p=n(16),f=n(32),l=n(33),h=n(30),d=n(11),y=n(31);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(4),a=n(7),s=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.isValidSnapshot=function(t){return!(this.name in t)},e}(a.Property);e.ActionProperty=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(3),o=n(7),a=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.isValidSnapshot=function(t){return!(this.name in t)},e}(o.Property);e.ComputedProperty=a},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(3),a=n(7),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.isValidSnapshot=function(t){return this.isValidIdentifier(t[this.name])},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(7),o=n(1),a=n(4),s=n(19),u=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.isValidSnapshot=function(t){return this.name in t},e}(i.Property);e.ReferenceProperty=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(3),o=n(7),a=n(4),s=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.isValidSnapshot=function(t){return this.type.is(t[this.name])},e}(o.Property);e.ValueProperty=s},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(3),a=n(1),s=n(4),u=n(7),c=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.isValidSnapshot=function(t){return!(this.name in t)},e}(u.Property);e.ViewProperty=c,e.createViewInvoker=r},function(t,e,n){"use strict";function r(t){return Object.freeze(t),a.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(2),a=n(1),s=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 a.invariant(a.isSerializable(t),"Given value should be serializable"),a.isMutable(t)?r(t):t},e.prototype.is=function(t){return a.isSerializable(t)},Object.defineProperty(e.prototype,"identifierAttribute",{get:function(){return null},enumerable:!0,configurable:!0}),e}(o.Type);e.Frozen=s,e.frozen=new s},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(2),s=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.is=function(t){return this.subType.is(t)},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(18),o=n(16),a=n(12),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 u(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(2),a=n(1),s=n(4),u=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.is=function(t){return this.type.is(t)&&this.predicate(t)},Object.defineProperty(e.prototype,"identifierAttribute",{get:function(){return this.type.identifierAttribute},enumerable:!0,configurable:!0}),e}(o.Type);e.Refinement=u,e.refinement=r}])}); |
{ | ||
"name": "mobx-state-tree", | ||
"version": "0.5.1", | ||
"version": "0.6.0", | ||
"description": "Opinionated, transactional, MobX powered state container", | ||
@@ -13,3 +13,3 @@ "main": "lib/index.js", | ||
"test": "npm run build-tests && ava", | ||
"watch": "concurrently --kill-others --names 'build-tests,test-runner' 'tsc --watch -p test' --raw 'ava --watch'", | ||
"watch": "tsc -p test && concurrently --kill-others --names 'build-tests,test-runner' 'tsc --watch -p test' --raw 'ava --watch'", | ||
"_prepublish": "npm run build && npm run build-docs", | ||
@@ -16,0 +16,0 @@ "coverage": "npm run build-tests && nyc ava && nyc report -r html && nyc report -r lcov", |
# mobx-state-tree | ||
## _This package is work in progress, stay tuned_ | ||
_Opinionated, transactional, MobX powered state container_ | ||
@@ -14,37 +12,62 @@ | ||
An introduction to the philosophy can be watched [here](https://youtu.be/ta8QKmNRXZM?t=21m52s). [Slides](https://immer-mutable-state.surge.sh/). Or, as [markdown](https://github.com/mweststrate/reactive2016-slides/blob/master/slides.md) to read it quickly. | ||
# Installation | ||
NPM: | ||
* NPM: `npm install mobx-state-tree --save` | ||
* Yarn: `yarn add mobx-state-tree` | ||
* CDN: https://unpkg.com/mobx-state-tree/mobx-state-tree.umd.js (exposed as `window.mobxStateTree`) | ||
* JSBin [playground](http://jsbin.com/petoxeheta/edit?html,js,console) (without UI) | ||
npm install mobx-state-tree --save-dev | ||
# Philosophy | ||
CDN: | ||
`mobx-state-tree` is a state container that combines the _simplicity and ease of mutable data_ with the _traceability of immutable data_ and the _reactiveness and performance of observable data_. | ||
<https://unpkg.com/mobx-state-tree/mobx-state-tree.umd.js> | ||
Put simply, mobx-state-tree tries to combine the best features of both immutability (transactionality, traceability and composition) and mutability (discoverability, co-location and encapsulation) based approaches to state management; everything to provide the best developer experience possible. | ||
Unlike MobX itself, mobx-state-tree is very opinionated on how data should be structured and updated. | ||
This makes it possible to solve many common problems out of the box. | ||
# Philosophy | ||
Central in MST (mobx-state-tree) is the concept of a *living tree*. The tree consists of mutable, but strictly protected objects enriched with _runtime type information_. | ||
From this living tree, (structurally shared) snapshots are generated automatically. | ||
`mobx-state-tree` is a state container that combines the _simplicity and ease of mutable data_ with the _traceability of immutable data_ and the _reactiveness and performance of observable data_. | ||
(example) | ||
It is an opt-in state container that can be used in MobX, but also Redux based applications. | ||
By using the type information available; snapshots can be converted to living trees and vice versa with zero effort. | ||
Because of this, [time travelling](https://github.com/mobxjs/mobx-state-tree/blob/master/examples/boxes/src/stores/time.js) is supported out of the box, and tools like HMR are trivial to support. | ||
If MobX is like a spreadsheet mechanism for javascript, then mobx-state-tree is like storing your spreadsheet in git. | ||
(example) | ||
Unlike MobX itself, mobx-state-tree is quite opinionated on how you structure your data. | ||
This makes it possible to solve many problems generically and out of the box, like: | ||
The type information is designed in such a way that it is used both at design- and run-time to verify type correctness (Design time type checking is TypeScript only atm, Flow PR's are welcome!) | ||
- (De-) serialization | ||
- Snapshotting state | ||
- Replaying actions | ||
- Time travelling | ||
- Emitting and applying JSON patches | ||
- Protecting state against uncontrolled mutations | ||
- Using middleware | ||
- Using dependency injection | ||
- Maintaining invariants | ||
(screenshot) | ||
`mobx-state-tree` tries to take the best features from both object oriented (discoverability, co-location and encapsulation), and immutable based state management approaches (transactionality, sharing functionality through composition). | ||
Because state trees are living, mutable models actions are straight-forward to write. | ||
(Example) | ||
But 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)). | ||
Moreover; since changes can be detected on a fine grained level. JSON patches are supported out of the box. | ||
Simply subscribing to the patch stream of a tree is another way to sync diffs with for example back-end servers or other clients ([example](https://github.com/mobxjs/mobx-state-tree/blob/master/examples/boxes/src/stores/socket.js)). | ||
Since MST uses MobX behind the scenes, it integrates seamlessly with [mobx](todo) and [mobx-react](todo). But even cooler; because it supports snapshots, middleware and replayable actions out of the box. It is even possible to replace a Redux store and reducer with a MobX state tree. This makes it even possible to connect the Redux devtools to MST. See the [Redux / MST TodoMVC example](todo). | ||
Finally, MST has built-in support for references, identifiers, dependency injection, change recording and circular type definitions (even across files). | ||
Even fancier; it analyses liveleness of objects, failing early when you try to access accidentally cached information! (More on that later) | ||
Despite all that, you will see that the [API](api.md) is pretty straight forward! | ||
--- | ||
Another way to look at mobx-state-tree is to consider it, as argued by Daniel Earwicker, to be ["React, but for data"](http://danielearwicker.github.io/json_mobx_Like_React_but_for_Data_Part_2_.html). | ||
Like React, MST consists of composable components, called *models*, which capture a small piece of state. They are instantiated from props (snapshots) and after that manage and protect their own internal state (using actions). Moreover, when applying snapshots, tree nodes are reconciled as much as possible. There is even a context-like mechanism, called environments, to pass information to deep descendants. | ||
An introduction to the philosophy can be watched [here](https://youtu.be/ta8QKmNRXZM?t=21m52s). [Slides](https://immer-mutable-state.surge.sh/). Or, as [markdown](https://github.com/mweststrate/reactive2016-slides/blob/master/slides.md) to read it quickly. | ||
TODO: react europe talk | ||
# Examples | ||
TODO: move https://github.com/mweststrate/react-mobx-shop/tree/mobx-state-tree to this repo | ||
# Concepts | ||
@@ -51,0 +74,0 @@ |
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
316311
3794
415
104