mobx-state-tree 5.1.7 → 5.2.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,6 +12,10 @@ export interface IMiddlewareEvent extends IActionContext {
12
12
  /** Id of all events, from root until current (excluding current) */
13
13
  readonly allParentIds: number[];
14
14
  }
15
+ export interface FunctionWithFlag extends Function {
16
+ _isMSTAction?: boolean;
17
+ _isFlowAction?: boolean;
18
+ }
15
19
  export declare type IMiddlewareHandler = (actionCall: IMiddlewareEvent, next: (actionCall: IMiddlewareEvent, callback?: (value: any) => any) => void, abort: (value: any) => void) => any;
16
20
  /**
17
21
  * Middleware can be used to intercept any action is invoked on the subtree where it is attached.
@@ -372,9 +372,17 @@ export interface IModelReflectionData extends IModelReflectionPropertiesData {
372
372
  actions: string[];
373
373
  views: string[];
374
374
  volatile: string[];
375
+ flowActions: string[];
375
376
  }
376
377
  /**
377
- * Returns a reflection of the model node, including name, properties, views, volatile and actions.
378
+ * Returns a reflection of the model node, including name, properties, views, volatile state,
379
+ * and actions. `flowActions` is also provided as a separate array of names for any action that
380
+ * came from a flow generator as well.
381
+ *
382
+ * In the case where a model has two actions: `doSomething` and `doSomethingWithFlow`, where
383
+ * `doSomethingWithFlow` is a flow generator, the `actions` array will contain both actions,
384
+ * i.e. ["doSomething", "doSomethingWithFlow"], and the `flowActions` array will contain only
385
+ * the flow action, i.e. ["doSomethingWithFlow"].
378
386
  *
379
387
  * @param target
380
388
  * @returns
@@ -30,6 +30,7 @@ export * from "./types/utility-types/union";
30
30
  export * from "./types/utility-types/optional";
31
31
  export * from "./types/utility-types/maybe";
32
32
  export * from "./types/utility-types/late";
33
+ export * from "./types/utility-types/lazy";
33
34
  export * from "./types/utility-types/frozen";
34
35
  export * from "./types/utility-types/reference";
35
36
  export * from "./types/utility-types/identifier";
@@ -842,14 +842,21 @@ function getPropertyMembers(typeOrNode) {
842
842
  };
843
843
  }
844
844
  /**
845
- * Returns a reflection of the model node, including name, properties, views, volatile and actions.
845
+ * Returns a reflection of the model node, including name, properties, views, volatile state,
846
+ * and actions. `flowActions` is also provided as a separate array of names for any action that
847
+ * came from a flow generator as well.
848
+ *
849
+ * In the case where a model has two actions: `doSomething` and `doSomethingWithFlow`, where
850
+ * `doSomethingWithFlow` is a flow generator, the `actions` array will contain both actions,
851
+ * i.e. ["doSomething", "doSomethingWithFlow"], and the `flowActions` array will contain only
852
+ * the flow action, i.e. ["doSomethingWithFlow"].
846
853
  *
847
854
  * @param target
848
855
  * @returns
849
856
  */
850
857
  function getMembers(target) {
851
858
  var type = getStateTreeNode(target).type;
852
- var reflected = __assign(__assign({}, getPropertyMembers(type)), { actions: [], volatile: [], views: [] });
859
+ var reflected = __assign(__assign({}, getPropertyMembers(type)), { actions: [], volatile: [], views: [], flowActions: [] });
853
860
  var props = Object.getOwnPropertyNames(target);
854
861
  props.forEach(function (key) {
855
862
  if (key in reflected.properties)
@@ -864,6 +871,8 @@ function getMembers(target) {
864
871
  }
865
872
  if (descriptor.value._isMSTAction === true)
866
873
  reflected.actions.push(key);
874
+ if (descriptor.value._isFlowAction === true)
875
+ reflected.flowActions.push(key);
867
876
  else if (mobx.isObservableProp(target, key))
868
877
  reflected.volatile.push(key);
869
878
  else
@@ -1590,9 +1599,10 @@ var ObjectNode = /** @class */ (function (_super) {
1590
1599
  enumerable: false,
1591
1600
  configurable: true,
1592
1601
  writable: true,
1593
- value: function () {
1602
+ value: function (fireHooks) {
1603
+ if (fireHooks === void 0) { fireHooks = true; }
1594
1604
  if (this._observableInstanceState === 0 /* UNINITIALIZED */) {
1595
- this.createObservableInstance();
1605
+ this.createObservableInstance(fireHooks);
1596
1606
  }
1597
1607
  }
1598
1608
  });
@@ -1600,8 +1610,9 @@ var ObjectNode = /** @class */ (function (_super) {
1600
1610
  enumerable: false,
1601
1611
  configurable: true,
1602
1612
  writable: true,
1603
- value: function () {
1604
- var e_1, _a;
1613
+ value: function (fireHooks) {
1614
+ var e_1, _a, e_2, _b;
1615
+ if (fireHooks === void 0) { fireHooks = true; }
1605
1616
  if (devMode()) {
1606
1617
  if (this.state !== NodeLifeCycle.INITIALIZING) {
1607
1618
  // istanbul ignore next
@@ -1626,7 +1637,8 @@ var ObjectNode = /** @class */ (function (_super) {
1626
1637
  // initialize the uninitialized parent chain from parent to child
1627
1638
  for (var parentChain_1 = __values(parentChain), parentChain_1_1 = parentChain_1.next(); !parentChain_1_1.done; parentChain_1_1 = parentChain_1.next()) {
1628
1639
  var p = parentChain_1_1.value;
1629
- p.createObservableInstanceIfNeeded();
1640
+ // delay firing hooks until after all parents have been created
1641
+ p.createObservableInstanceIfNeeded(false);
1630
1642
  }
1631
1643
  }
1632
1644
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
@@ -1657,8 +1669,28 @@ var ObjectNode = /** @class */ (function (_super) {
1657
1669
  this._addSnapshotReaction();
1658
1670
  this._childNodes = EMPTY_OBJECT;
1659
1671
  this.state = NodeLifeCycle.CREATED;
1660
- this.fireHook(Hook.afterCreate);
1661
- this.finalizeCreation();
1672
+ if (fireHooks) {
1673
+ this.fireHook(Hook.afterCreate);
1674
+ // Note that the parent might not be finalized at this point
1675
+ // so afterAttach won't be called until later in that case
1676
+ this.finalizeCreation();
1677
+ try {
1678
+ // fire the hooks of the parents that we created
1679
+ for (var _c = __values(parentChain.reverse()), _d = _c.next(); !_d.done; _d = _c.next()) {
1680
+ var p = _d.value;
1681
+ p.fireHook(Hook.afterCreate);
1682
+ // This will call afterAttach on the child if necessary
1683
+ p.finalizeCreation();
1684
+ }
1685
+ }
1686
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
1687
+ finally {
1688
+ try {
1689
+ if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
1690
+ }
1691
+ finally { if (e_2) throw e_2.error; }
1692
+ }
1693
+ }
1662
1694
  }
1663
1695
  });
1664
1696
  Object.defineProperty(ObjectNode.prototype, "root", {
@@ -1957,19 +1989,19 @@ var ObjectNode = /** @class */ (function (_super) {
1957
1989
  value: function () {
1958
1990
  var _this = this;
1959
1991
  this.baseFinalizeCreation(function () {
1960
- var e_2, _a;
1992
+ var e_3, _a;
1961
1993
  try {
1962
1994
  for (var _b = __values(_this.getChildren()), _c = _b.next(); !_c.done; _c = _b.next()) {
1963
1995
  var child = _c.value;
1964
1996
  child.finalizeCreation();
1965
1997
  }
1966
1998
  }
1967
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
1999
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
1968
2000
  finally {
1969
2001
  try {
1970
2002
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1971
2003
  }
1972
- finally { if (e_2) throw e_2.error; }
2004
+ finally { if (e_3) throw e_3.error; }
1973
2005
  }
1974
2006
  _this.fireInternalHook(Hook.afterCreationFinalization);
1975
2007
  });
@@ -2293,6 +2325,9 @@ var TypeFlags;
2293
2325
  TypeFlags[TypeFlags["Integer"] = 131072] = "Integer";
2294
2326
  TypeFlags[TypeFlags["Custom"] = 262144] = "Custom";
2295
2327
  TypeFlags[TypeFlags["SnapshotProcessor"] = 524288] = "SnapshotProcessor";
2328
+ TypeFlags[TypeFlags["Lazy"] = 1048576] = "Lazy";
2329
+ TypeFlags[TypeFlags["Finite"] = 2097152] = "Finite";
2330
+ TypeFlags[TypeFlags["Float"] = 4194304] = "Float";
2296
2331
  })(TypeFlags || (TypeFlags = {}));
2297
2332
  /**
2298
2333
  * @internal
@@ -3141,6 +3176,7 @@ function createActionInvoker(target, name, fn) {
3141
3176
  }, fn);
3142
3177
  };
3143
3178
  res._isMSTAction = true;
3179
+ res._isFlowAction = fn._isFlowAction;
3144
3180
  return res;
3145
3181
  }
3146
3182
  /**
@@ -3556,17 +3592,25 @@ var IdentifierCache = /** @class */ (function () {
3556
3592
  enumerable: false,
3557
3593
  configurable: true,
3558
3594
  writable: true,
3559
- value: function (node) {
3595
+ value: function (splitNode) {
3560
3596
  var _this = this;
3561
- var res = new IdentifierCache();
3562
- var basePath = node.path;
3597
+ var newCache = new IdentifierCache();
3598
+ // The slash is added here so we only match children of the splitNode. In version 5.1.8 and
3599
+ // earlier there was no trailing slash, so non children that started with the same path string
3600
+ // were being matched incorrectly.
3601
+ var basePath = splitNode.path + "/";
3563
3602
  mobx.entries(this.cache).forEach(function (_a) {
3564
3603
  var _b = __read(_a, 2), id = _b[0], nodes = _b[1];
3565
3604
  var modified = false;
3566
3605
  for (var i = nodes.length - 1; i >= 0; i--) {
3567
- if (nodes[i].path.indexOf(basePath) === 0) {
3568
- res.addNodeToCache(nodes[i], false); // no need to update lastUpdated since it is a whole new cache
3606
+ var node = nodes[i];
3607
+ if (node === splitNode || node.path.indexOf(basePath) === 0) {
3608
+ newCache.addNodeToCache(node, false); // no need to update lastUpdated since it is a whole new cache
3569
3609
  nodes.splice(i, 1);
3610
+ // remove empty sets from cache
3611
+ if (!nodes.length) {
3612
+ _this.cache.delete(id);
3613
+ }
3570
3614
  modified = true;
3571
3615
  }
3572
3616
  }
@@ -3574,7 +3618,7 @@ var IdentifierCache = /** @class */ (function () {
3574
3618
  _this.updateLastCacheModificationPerId(id);
3575
3619
  }
3576
3620
  });
3577
- return res;
3621
+ return newCache;
3578
3622
  }
3579
3623
  });
3580
3624
  Object.defineProperty(IdentifierCache.prototype, "has", {
@@ -3858,15 +3902,24 @@ function identity(_) {
3858
3902
  return _;
3859
3903
  }
3860
3904
  /**
3861
- * pollyfill (for IE) suggested in MDN:
3862
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isInteger
3863
3905
  * @internal
3864
3906
  * @hidden
3865
3907
  */
3866
- var isInteger = Number.isInteger ||
3867
- function (value) {
3868
- return typeof value === "number" && isFinite(value) && Math.floor(value) === value;
3869
- };
3908
+ var isInteger = Number.isInteger;
3909
+ /**
3910
+ * @internal
3911
+ * @hidden
3912
+ */
3913
+ function isFloat(val) {
3914
+ return Number(val) === val && val % 1 !== 0;
3915
+ }
3916
+ /**
3917
+ * @internal
3918
+ * @hidden
3919
+ */
3920
+ function isFinite(val) {
3921
+ return Number.isFinite(val);
3922
+ }
3870
3923
  /**
3871
3924
  * @internal
3872
3925
  * @hidden
@@ -4410,7 +4463,7 @@ function createFlowSpawner(name, generator) {
4410
4463
  var args = arguments;
4411
4464
  function wrap(fn, type, arg) {
4412
4465
  fn.$mst_middleware = spawner.$mst_middleware; // pick up any middleware attached to the flow
4413
- runWithActionContext(__assign(__assign({}, contextBase), { type: type, args: [arg] }), fn);
4466
+ return runWithActionContext(__assign(__assign({}, contextBase), { type: type, args: [arg] }), fn);
4414
4467
  }
4415
4468
  return new Promise(function (resolve, reject) {
4416
4469
  var gen;
@@ -4424,7 +4477,10 @@ function createFlowSpawner(name, generator) {
4424
4477
  var ret;
4425
4478
  try {
4426
4479
  // prettier-ignore
4427
- wrap(function (r) { ret = gen.next(r); }, "flow_resume", res);
4480
+ var cancelError = wrap(function (r) { ret = gen.next(r); }, "flow_resume", res);
4481
+ if (cancelError instanceof Error) {
4482
+ ret = gen.throw(cancelError);
4483
+ }
4428
4484
  }
4429
4485
  catch (e) {
4430
4486
  // prettier-ignore
@@ -4468,6 +4524,7 @@ function createFlowSpawner(name, generator) {
4468
4524
  }
4469
4525
  });
4470
4526
  };
4527
+ spawner._isFlowAction = true;
4471
4528
  return spawner;
4472
4529
  }
4473
4530
 
@@ -4881,8 +4938,8 @@ var MapIdentifierMode;
4881
4938
  })(MapIdentifierMode || (MapIdentifierMode = {}));
4882
4939
  var MSTMap = /** @class */ (function (_super) {
4883
4940
  __extends(MSTMap, _super);
4884
- function MSTMap(initialData) {
4885
- return _super.call(this, initialData, mobx.observable.ref.enhancer) || this;
4941
+ function MSTMap(initialData, name) {
4942
+ return _super.call(this, initialData, mobx.observable.ref.enhancer, name) || this;
4886
4943
  }
4887
4944
  Object.defineProperty(MSTMap.prototype, "get", {
4888
4945
  enumerable: false,
@@ -5070,7 +5127,7 @@ var MapType = /** @class */ (function (_super) {
5070
5127
  configurable: true,
5071
5128
  writable: true,
5072
5129
  value: function (childNodes) {
5073
- return new MSTMap(childNodes);
5130
+ return new MSTMap(childNodes, this.describe());
5074
5131
  }
5075
5132
  });
5076
5133
  Object.defineProperty(MapType.prototype, "finalizeNewInstance", {
@@ -5412,7 +5469,8 @@ var ArrayType = /** @class */ (function (_super) {
5412
5469
  configurable: true,
5413
5470
  writable: true,
5414
5471
  value: function (childNodes) {
5415
- return mobx.observable.array(convertChildNodesToArray(childNodes), mobxShallow);
5472
+ var options = __assign(__assign({}, mobxShallow), { name: this.describe() });
5473
+ return mobx.observable.array(convertChildNodesToArray(childNodes), options);
5416
5474
  }
5417
5475
  });
5418
5476
  Object.defineProperty(ArrayType.prototype, "finalizeNewInstance", {
@@ -6016,6 +6074,7 @@ var ModelType = /** @class */ (function (_super) {
6016
6074
  // while still allowing the middlewares to register them
6017
6075
  var middlewares = action2.$mst_middleware; // make sure middlewares are not lost
6018
6076
  var boundAction = action2.bind(actions);
6077
+ boundAction._isFlowAction = action2._isFlowAction || false;
6019
6078
  boundAction.$mst_middleware = middlewares;
6020
6079
  var actionInvoker = createActionInvoker(self, name, boundAction);
6021
6080
  actions[name] = actionInvoker;
@@ -6141,7 +6200,8 @@ var ModelType = /** @class */ (function (_super) {
6141
6200
  configurable: true,
6142
6201
  writable: true,
6143
6202
  value: function (childNodes) {
6144
- return mobx.observable.object(childNodes, EMPTY_OBJECT, mobxShallow);
6203
+ var options = __assign(__assign({}, mobxShallow), { name: this.describe() });
6204
+ return mobx.observable.object(childNodes, EMPTY_OBJECT, options);
6145
6205
  }
6146
6206
  });
6147
6207
  Object.defineProperty(ModelType.prototype, "finalizeNewInstance", {
@@ -6272,8 +6332,8 @@ var ModelType = /** @class */ (function (_super) {
6272
6332
  configurable: true,
6273
6333
  writable: true,
6274
6334
  value: function (node, snapshot) {
6335
+ typecheckInternal(this, snapshot);
6275
6336
  var preProcessedSnapshot = this.applySnapshotPreProcessor(snapshot);
6276
- typecheckInternal(this, preProcessedSnapshot);
6277
6337
  this.forAllProps(function (name) {
6278
6338
  node.storedValue[name] = preProcessedSnapshot[name];
6279
6339
  });
@@ -6375,6 +6435,9 @@ function model() {
6375
6435
  for (var _i = 0; _i < arguments.length; _i++) {
6376
6436
  args[_i] = arguments[_i];
6377
6437
  }
6438
+ if (devMode() && typeof args[0] !== "string" && args[1]) {
6439
+ throw fail$1("Model creation failed. First argument must be a string when two arguments are provided");
6440
+ }
6378
6441
  var name = typeof args[0] === "string" ? args.shift() : "AnonymousModel";
6379
6442
  var properties = args.shift() || {};
6380
6443
  return new ModelType({ name: name, properties: properties });
@@ -6528,7 +6591,6 @@ var string = new CoreType("string", TypeFlags.String, function (v) { return type
6528
6591
  var number = new CoreType("number", TypeFlags.Number, function (v) { return typeof v === "number"; });
6529
6592
  /**
6530
6593
  * `types.integer` - Creates a type that can only contain an integer value.
6531
- * This type is used for integer values by default
6532
6594
  *
6533
6595
  * Example:
6534
6596
  * ```ts
@@ -6540,6 +6602,32 @@ var number = new CoreType("number", TypeFlags.Number, function (v) { return type
6540
6602
  */
6541
6603
  // tslint:disable-next-line:variable-name
6542
6604
  var integer = new CoreType("integer", TypeFlags.Integer, function (v) { return isInteger(v); });
6605
+ /**
6606
+ * `types.float` - Creates a type that can only contain an float value.
6607
+ *
6608
+ * Example:
6609
+ * ```ts
6610
+ * const Size = types.model({
6611
+ * width: types.float,
6612
+ * height: 10
6613
+ * })
6614
+ * ```
6615
+ */
6616
+ // tslint:disable-next-line:variable-name
6617
+ var float = new CoreType("float", TypeFlags.Float, function (v) { return isFloat(v); });
6618
+ /**
6619
+ * `types.finite` - Creates a type that can only contain an finite value.
6620
+ *
6621
+ * Example:
6622
+ * ```ts
6623
+ * const Size = types.model({
6624
+ * width: types.finite,
6625
+ * height: 10
6626
+ * })
6627
+ * ```
6628
+ */
6629
+ // tslint:disable-next-line:variable-name
6630
+ var finite = new CoreType("finite", TypeFlags.Finite, function (v) { return isFinite(v); });
6543
6631
  /**
6544
6632
  * `types.boolean` - Creates a type that can only contain a boolean value.
6545
6633
  * This type is used for boolean values by default
@@ -7079,7 +7167,7 @@ var OptionalValue = /** @class */ (function (_super) {
7079
7167
  writable: true,
7080
7168
  value: function (parent, subpath, environment, initialValue) {
7081
7169
  if (this.optionalValues.indexOf(initialValue) >= 0) {
7082
- var defaultInstanceOrSnapshot = this.getDefaultInstanceOrSnapshot();
7170
+ var defaultInstanceOrSnapshot = this.getDefaultInstanceOrSnapshot(parent);
7083
7171
  return this._subtype.instantiate(parent, subpath, environment, defaultInstanceOrSnapshot);
7084
7172
  }
7085
7173
  return this._subtype.instantiate(parent, subpath, environment, initialValue);
@@ -7092,16 +7180,16 @@ var OptionalValue = /** @class */ (function (_super) {
7092
7180
  value: function (current, newValue, parent, subpath) {
7093
7181
  return this._subtype.reconcile(current, this.optionalValues.indexOf(newValue) < 0 && this._subtype.is(newValue)
7094
7182
  ? newValue
7095
- : this.getDefaultInstanceOrSnapshot(), parent, subpath);
7183
+ : this.getDefaultInstanceOrSnapshot(parent), parent, subpath);
7096
7184
  }
7097
7185
  });
7098
7186
  Object.defineProperty(OptionalValue.prototype, "getDefaultInstanceOrSnapshot", {
7099
7187
  enumerable: false,
7100
7188
  configurable: true,
7101
7189
  writable: true,
7102
- value: function () {
7190
+ value: function (parent) {
7103
7191
  var defaultInstanceOrSnapshot = typeof this._defaultValue === "function"
7104
- ? this._defaultValue()
7192
+ ? this._defaultValue(parent)
7105
7193
  : this._defaultValue;
7106
7194
  // while static values are already snapshots and checked on types.optional
7107
7195
  // generator functions must always be rechecked just in case
@@ -7389,6 +7477,120 @@ function isLateType(type) {
7389
7477
  return isType(type) && (type.flags & TypeFlags.Late) > 0;
7390
7478
  }
7391
7479
 
7480
+ function lazy(name, options) {
7481
+ // TODO: fix this unknown casting to be stricter
7482
+ return new Lazy(name, options);
7483
+ }
7484
+ /**
7485
+ * @internal
7486
+ * @hidden
7487
+ */
7488
+ var Lazy = /** @class */ (function (_super) {
7489
+ __extends(Lazy, _super);
7490
+ function Lazy(name, options) {
7491
+ var _this = _super.call(this, name) || this;
7492
+ Object.defineProperty(_this, "options", {
7493
+ enumerable: true,
7494
+ configurable: true,
7495
+ writable: true,
7496
+ value: options
7497
+ });
7498
+ Object.defineProperty(_this, "flags", {
7499
+ enumerable: true,
7500
+ configurable: true,
7501
+ writable: true,
7502
+ value: TypeFlags.Lazy
7503
+ });
7504
+ Object.defineProperty(_this, "loadedType", {
7505
+ enumerable: true,
7506
+ configurable: true,
7507
+ writable: true,
7508
+ value: null
7509
+ });
7510
+ Object.defineProperty(_this, "pendingNodeList", {
7511
+ enumerable: true,
7512
+ configurable: true,
7513
+ writable: true,
7514
+ value: mobx.observable.array()
7515
+ });
7516
+ mobx.when(function () {
7517
+ return _this.pendingNodeList.length > 0 &&
7518
+ _this.pendingNodeList.some(function (node) {
7519
+ return node.isAlive &&
7520
+ _this.options.shouldLoadPredicate(node.parent ? node.parent.value : null);
7521
+ });
7522
+ }, function () {
7523
+ _this.options.loadType().then(mobx.action(function (type) {
7524
+ _this.loadedType = type;
7525
+ _this.pendingNodeList.forEach(function (node) {
7526
+ if (!node.parent)
7527
+ return;
7528
+ if (!_this.loadedType)
7529
+ return;
7530
+ node.parent.applyPatches([
7531
+ {
7532
+ op: "replace",
7533
+ path: "/" + node.subpath,
7534
+ value: node.snapshot
7535
+ }
7536
+ ]);
7537
+ });
7538
+ }));
7539
+ });
7540
+ return _this;
7541
+ }
7542
+ Object.defineProperty(Lazy.prototype, "describe", {
7543
+ enumerable: false,
7544
+ configurable: true,
7545
+ writable: true,
7546
+ value: function () {
7547
+ return "<lazy " + this.name + ">";
7548
+ }
7549
+ });
7550
+ Object.defineProperty(Lazy.prototype, "instantiate", {
7551
+ enumerable: false,
7552
+ configurable: true,
7553
+ writable: true,
7554
+ value: function (parent, subpath, environment, value) {
7555
+ var _this = this;
7556
+ if (this.loadedType) {
7557
+ return this.loadedType.instantiate(parent, subpath, environment, value);
7558
+ }
7559
+ var node = createScalarNode(this, parent, subpath, environment, deepFreeze(value));
7560
+ this.pendingNodeList.push(node);
7561
+ mobx.when(function () { return !node.isAlive; }, function () { return _this.pendingNodeList.splice(_this.pendingNodeList.indexOf(node), 1); });
7562
+ return node;
7563
+ }
7564
+ });
7565
+ Object.defineProperty(Lazy.prototype, "isValidSnapshot", {
7566
+ enumerable: false,
7567
+ configurable: true,
7568
+ writable: true,
7569
+ value: function (value, context) {
7570
+ if (this.loadedType) {
7571
+ return this.loadedType.validate(value, context);
7572
+ }
7573
+ if (!isSerializable(value)) {
7574
+ return typeCheckFailure(context, value, "Value is not serializable and cannot be lazy");
7575
+ }
7576
+ return typeCheckSuccess();
7577
+ }
7578
+ });
7579
+ Object.defineProperty(Lazy.prototype, "reconcile", {
7580
+ enumerable: false,
7581
+ configurable: true,
7582
+ writable: true,
7583
+ value: function (current, value, parent, subpath) {
7584
+ if (this.loadedType) {
7585
+ current.die();
7586
+ return this.loadedType.instantiate(parent, subpath, parent.environment, value);
7587
+ }
7588
+ return _super.prototype.reconcile.call(this, current, value, parent, subpath);
7589
+ }
7590
+ });
7591
+ return Lazy;
7592
+ }(SimpleType));
7593
+
7392
7594
  /**
7393
7595
  * @internal
7394
7596
  * @hidden
@@ -8327,6 +8529,8 @@ var types = {
8327
8529
  boolean: boolean,
8328
8530
  number: number,
8329
8531
  integer: integer,
8532
+ float: float,
8533
+ finite: finite,
8330
8534
  Date: DatePrimitive,
8331
8535
  map: map,
8332
8536
  array: array,
@@ -8334,6 +8538,7 @@ var types = {
8334
8538
  identifier: identifier,
8335
8539
  identifierNumber: identifierNumber,
8336
8540
  late: late,
8541
+ lazy: lazy,
8337
8542
  undefined: undefinedType,
8338
8543
  null: nullType,
8339
8544
  snapshotProcessor: snapshotProcessor