@jbrowse/mobx-state-tree 5.10.6 → 5.10.8

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.
@@ -978,7 +978,7 @@ class BaseNode {
978
978
  if (this._escapedSubpath === undefined) {
979
979
  this._escapedSubpath = !this._subpath ? "" : escapeJsonPath(this._subpath);
980
980
  }
981
- return (this.parent.getEscapedPath(reportObserved) + "/" + this._escapedSubpath);
981
+ return `${this.parent.getEscapedPath(reportObserved)}/${this._escapedSubpath}`;
982
982
  }
983
983
  get isRoot() {
984
984
  return this.parent === null;
@@ -1212,9 +1212,8 @@ class ObjectNode extends BaseNode {
1212
1212
  // uninitialized parent
1213
1213
  // this is done to avoid traversing the whole tree to the root when using
1214
1214
  // the same reference again
1215
- while (parent &&
1216
- parent._observableInstanceState ===
1217
- 0 /* ObservableInstanceLifecycle.UNINITIALIZED */) {
1215
+ while (parent?._observableInstanceState ===
1216
+ 0 /* ObservableInstanceLifecycle.UNINITIALIZED */) {
1218
1217
  parentChain.unshift(parent);
1219
1218
  parent = parent.parent;
1220
1219
  }
@@ -1402,12 +1401,9 @@ class ObjectNode extends BaseNode {
1402
1401
  actionContext = actionContext.parentActionEvent;
1403
1402
  }
1404
1403
  let actionFullPath = "";
1405
- if (actionContext && actionContext.name != null) {
1404
+ if (actionContext?.name != null) {
1406
1405
  // try to use the context, and if it not available use the node one
1407
- const actionPath = (actionContext &&
1408
- actionContext.context &&
1409
- getPath(actionContext.context)) ||
1410
- escapedPath;
1406
+ const actionPath = (actionContext.context && getPath(actionContext.context)) || escapedPath;
1411
1407
  actionFullPath = `${actionPath}.${actionContext.name}()`;
1412
1408
  }
1413
1409
  return `You are trying to read or write to an object that is no longer part of a state tree. (Object type: '${this.type.name}', Path upon death: '${escapedPath}', Subpath: '${subpath}', Action: '${actionFullPath}'). Either detach nodes first, or don't use objects after removing / replacing them in the tree.`;
@@ -1554,9 +1550,10 @@ class ObjectNode extends BaseNode {
1554
1550
  }
1555
1551
  emitPatch(basePatch, source) {
1556
1552
  if (this._internalEventsHasSubscribers("patch" /* InternalEvents.Patch */)) {
1557
- const localizedPatch = extend({}, basePatch, {
1558
- path: source.path.substr(this.path.length) + "/" + basePatch.path // calculate the relative path of the patch
1559
- });
1553
+ const localizedPatch = {
1554
+ ...basePatch,
1555
+ path: `${source.path.substr(this.path.length)}/${basePatch.path}` // calculate the relative path of the patch
1556
+ };
1560
1557
  const [patch, reversePatch] = splitPatch(localizedPatch);
1561
1558
  this._internalEventsEmit("patch" /* InternalEvents.Patch */, patch, reversePatch);
1562
1559
  }
@@ -1885,7 +1882,7 @@ class SimpleType extends BaseType {
1885
1882
  * @returns `true` if the value is a type.
1886
1883
  */
1887
1884
  function isType(value) {
1888
- return typeof value === "object" && value && value.isType === true;
1885
+ return typeof value === "object" && value?.isType === true;
1889
1886
  }
1890
1887
  /**
1891
1888
  * @internal
@@ -2037,8 +2034,8 @@ function createActionTrackingMiddleware2(middlewareHooks) {
2037
2034
  const newCall = {
2038
2035
  ...call,
2039
2036
  // make a shallow copy of the parent action env
2040
- env: parentRunningAction && parentRunningAction.call.env,
2041
- parentCall: parentRunningAction && parentRunningAction.call
2037
+ env: parentRunningAction?.call.env,
2038
+ parentCall: parentRunningAction?.call
2042
2039
  };
2043
2040
  const passesFilter = !middlewareHooks.filter || middlewareHooks.filter(newCall);
2044
2041
  const hooks = passesFilter ? middlewareHooks : undefined;
@@ -2119,8 +2116,7 @@ function serializeArgument(node, actionName, index, arg) {
2119
2116
  return serializeTheUnserializable(`[function]`);
2120
2117
  }
2121
2118
  if (typeof arg === "object" && !isPlainObject(arg) && !isArray(arg)) {
2122
- return serializeTheUnserializable(`[object ${(arg && arg.constructor && arg.constructor.name) ||
2123
- "Complex Object"}]`);
2119
+ return serializeTheUnserializable(`[object ${arg?.constructor?.name || "Complex Object"}]`);
2124
2120
  }
2125
2121
  try {
2126
2122
  // Check if serializable, cycle free etc...
@@ -2129,7 +2125,7 @@ function serializeArgument(node, actionName, index, arg) {
2129
2125
  return arg;
2130
2126
  }
2131
2127
  catch (e) {
2132
- return serializeTheUnserializable("" + e);
2128
+ return serializeTheUnserializable(`${e}`);
2133
2129
  }
2134
2130
  }
2135
2131
  function deserializeArgument(adm, value) {
@@ -2489,7 +2485,7 @@ function runMiddleWares(node, baseCall, originalFn) {
2489
2485
  let result = null;
2490
2486
  function runNextMiddleware(call) {
2491
2487
  const middleware = middlewares.getNextMiddleware();
2492
- const handler = middleware && middleware.handler;
2488
+ const handler = middleware?.handler;
2493
2489
  if (!handler) {
2494
2490
  return action(originalFn)(...call.args);
2495
2491
  }
@@ -2597,7 +2593,7 @@ function safeStringify(value) {
2597
2593
  */
2598
2594
  function prettyPrintValue(value) {
2599
2595
  return typeof value === "function"
2600
- ? `<function${value.name ? " " + value.name : ""}>`
2596
+ ? `<function${value.name ? ` ${value.name}` : ""}>`
2601
2597
  : isStateTreeNode(value)
2602
2598
  ? `<${value}>`
2603
2599
  : `\`${safeStringify(value)}\``;
@@ -2621,16 +2617,13 @@ function toErrorString(error) {
2621
2617
  ? "value"
2622
2618
  : "snapshot";
2623
2619
  const isSnapshotCompatible = type && isStateTreeNode(value) && type.is(getStateTreeNode(value).snapshot);
2624
- return (`${pathPrefix}${currentTypename} ${shortenPrintValue(prettyPrintValue(value))} is not assignable ${type ? `to type: \`${type.name}\`` : ``}` +
2625
- (error.message ? ` (${error.message})` : "") +
2626
- (type
2627
- ? isPrimitiveType(type) || isPrimitive(value)
2628
- ? `.`
2629
- : `, expected an instance of \`${type.name}\` or a snapshot like \`${shortenPrintValue(type.describe())}\` instead.` +
2630
- (isSnapshotCompatible
2631
- ? " (Note that a snapshot of the provided value is compatible with the targeted type)"
2632
- : "")
2633
- : `.`));
2620
+ return `${pathPrefix}${currentTypename} ${shortenPrintValue(prettyPrintValue(value))} is not assignable ${type ? `to type: \`${type.name}\`` : ``}${error.message ? ` (${error.message})` : ""}${type
2621
+ ? isPrimitiveType(type) || isPrimitive(value)
2622
+ ? `.`
2623
+ : `, expected an instance of \`${type.name}\` or a snapshot like \`${shortenPrintValue(type.describe())}\` instead.${isSnapshotCompatible
2624
+ ? " (Note that a snapshot of the provided value is compatible with the targeted type)"
2625
+ : ""}`
2626
+ : `.`}`;
2634
2627
  }
2635
2628
  /**
2636
2629
  * @internal
@@ -2719,7 +2712,7 @@ function validationErrorsToString(type, value, errors) {
2719
2712
  if (errors.length === 0) {
2720
2713
  return undefined;
2721
2714
  }
2722
- return (`Error while converting ${shortenPrintValue(prettyPrintValue(value))} to \`${type.name}\`:\n\n ` + formatValidationErrorLines(errors).join("\n "));
2715
+ return `Error while converting ${shortenPrintValue(prettyPrintValue(value))} to \`${type.name}\`:\n\n ${formatValidationErrorLines(errors).join("\n ")}`;
2723
2716
  }
2724
2717
 
2725
2718
  let identifierCacheId = 0;
@@ -2751,7 +2744,7 @@ class IdentifierCache {
2751
2744
  this.cache.set(identifier, observable.array([], mobxShallow));
2752
2745
  }
2753
2746
  const set = this.cache.get(identifier);
2754
- if (set.indexOf(node) !== -1) {
2747
+ if (set.includes(node)) {
2755
2748
  throw fail(`Already registered`);
2756
2749
  }
2757
2750
  set.push(node);
@@ -2784,12 +2777,12 @@ class IdentifierCache {
2784
2777
  // The slash is added here so we only match children of the splitNode. In version 5.1.8 and
2785
2778
  // earlier there was no trailing slash, so non children that started with the same path string
2786
2779
  // were being matched incorrectly.
2787
- const basePath = splitNode.path + "/";
2780
+ const basePath = `${splitNode.path}/`;
2788
2781
  entries(this.cache).forEach(([id, nodes]) => {
2789
2782
  let modified = false;
2790
2783
  for (let i = nodes.length - 1; i >= 0; i--) {
2791
2784
  const node = nodes[i];
2792
- if (node === splitNode || node.path.indexOf(basePath) === 0) {
2785
+ if (node === splitNode || node.path.startsWith(basePath)) {
2793
2786
  newCache.addNodeToCache(node, false); // no need to update lastUpdated since it is a whole new cache
2794
2787
  nodes.splice(i, 1);
2795
2788
  // remove empty sets from cache
@@ -2887,7 +2880,7 @@ var NodeLifeCycle;
2887
2880
  * @returns true if the value is a state tree node.
2888
2881
  */
2889
2882
  function isStateTreeNode(value) {
2890
- return !!(value && value.$treenode);
2883
+ return !!value?.$treenode;
2891
2884
  }
2892
2885
  /**
2893
2886
  * @internal
@@ -2912,7 +2905,7 @@ function getStateTreeNode(value) {
2912
2905
  * @hidden
2913
2906
  */
2914
2907
  function getStateTreeNodeSafe(value) {
2915
- return (value && value.$treenode) || null;
2908
+ return value?.$treenode || null;
2916
2909
  }
2917
2910
  /**
2918
2911
  * @internal
@@ -3039,7 +3032,7 @@ const DEPRECATION_MESSAGE = "See https://github.com/mobxjs/mobx-state-tree/issue
3039
3032
  * @returns {Promise}
3040
3033
  */
3041
3034
  function process$1(asyncAction) {
3042
- deprecated("process", "`process()` has been renamed to `flow()`. " + DEPRECATION_MESSAGE);
3035
+ deprecated("process", `\`process()\` has been renamed to \`flow()\`. ${DEPRECATION_MESSAGE}`);
3043
3036
  return flow(asyncAction);
3044
3037
  }
3045
3038
 
@@ -3067,7 +3060,7 @@ Object.freeze(mobxShallow);
3067
3060
  * @hidden
3068
3061
  */
3069
3062
  function fail(message = "Illegal state") {
3070
- return new Error("[mobx-state-tree] " + message);
3063
+ return new Error(`[mobx-state-tree] ${message}`);
3071
3064
  }
3072
3065
  /**
3073
3066
  * @internal
@@ -3115,19 +3108,6 @@ function asArray(val) {
3115
3108
  }
3116
3109
  return [val];
3117
3110
  }
3118
- /**
3119
- * @internal
3120
- * @hidden
3121
- */
3122
- function extend(a, ...b) {
3123
- for (let i = 0; i < b.length; i++) {
3124
- const current = b[i];
3125
- for (const key in current) {
3126
- a[key] = current[key];
3127
- }
3128
- }
3129
- return a;
3130
- }
3131
3111
  /**
3132
3112
  * @internal
3133
3113
  * @hidden
@@ -3261,7 +3241,7 @@ class EventHandler {
3261
3241
  };
3262
3242
  }
3263
3243
  has(fn) {
3264
- return this.handlers.indexOf(fn) >= 0;
3244
+ return this.handlers.includes(fn);
3265
3245
  }
3266
3246
  unregister(fn) {
3267
3247
  if (this.emitting) {
@@ -3310,8 +3290,7 @@ class EventHandler {
3310
3290
  class EventHandlers {
3311
3291
  eventHandlers;
3312
3292
  hasSubscribers(event) {
3313
- const handler = this.eventHandlers && this.eventHandlers[event];
3314
- return !!handler && handler.hasSubscribers;
3293
+ return this.eventHandlers?.[event]?.hasSubscribers ?? false;
3315
3294
  }
3316
3295
  register(event, fn, atTheBeginning = false) {
3317
3296
  if (!this.eventHandlers) {
@@ -3324,11 +3303,10 @@ class EventHandlers {
3324
3303
  return handler.register(fn, atTheBeginning);
3325
3304
  }
3326
3305
  has(event, fn) {
3327
- const handler = this.eventHandlers && this.eventHandlers[event];
3328
- return !!handler && handler.has(fn);
3306
+ return this.eventHandlers?.[event]?.has(fn) ?? false;
3329
3307
  }
3330
3308
  unregister(event, fn) {
3331
- const handler = this.eventHandlers && this.eventHandlers[event];
3309
+ const handler = this.eventHandlers?.[event];
3332
3310
  if (handler) {
3333
3311
  handler.unregister(fn);
3334
3312
  }
@@ -3342,19 +3320,12 @@ class EventHandlers {
3342
3320
  this.eventHandlers = undefined;
3343
3321
  }
3344
3322
  emit(event, ...args) {
3345
- const handler = this.eventHandlers && this.eventHandlers[event];
3323
+ const handler = this.eventHandlers?.[event];
3346
3324
  if (handler) {
3347
3325
  handler.emit(...args);
3348
3326
  }
3349
3327
  }
3350
3328
  }
3351
- /**
3352
- * @internal
3353
- * @hidden
3354
- */
3355
- function stringStartsWith(str, beginning) {
3356
- return str.indexOf(beginning) === 0;
3357
- }
3358
3329
  /**
3359
3330
  * @internal
3360
3331
  * @hidden
@@ -3366,7 +3337,7 @@ const deprecated = function (id, message) {
3366
3337
  }
3367
3338
  // warn if hasn't been warned before
3368
3339
  if (deprecated.ids && !deprecated.ids.hasOwnProperty(id)) {
3369
- warnError("Deprecation warning: " + message);
3340
+ warnError(`Deprecation warning: ${message}`);
3370
3341
  }
3371
3342
  // mark as warned to avoid duplicate warn message
3372
3343
  if (deprecated.ids) {
@@ -3381,15 +3352,27 @@ deprecated.ids = {};
3381
3352
  function warnError(msg) {
3382
3353
  console.warn(new Error(`[mobx-state-tree] ${msg}`));
3383
3354
  }
3355
+ let _typeChecking;
3356
+ /**
3357
+ * Forces full run-time type-checking on or off, overriding the dev-mode and
3358
+ * `ENABLE_TYPE_CHECK` env-var defaults. Pass `true` to get better error messages
3359
+ * in production builds without relying on an environment variable, `false` to
3360
+ * force it off, or `undefined` to restore the default behavior.
3361
+ */
3362
+ function setTypeChecking(enabled) {
3363
+ _typeChecking = enabled;
3364
+ }
3384
3365
  /**
3385
3366
  * @internal
3386
3367
  * @hidden
3387
3368
  */
3388
3369
  function isTypeCheckingEnabled() {
3389
- return (devMode() ||
3390
- (typeof process !== "undefined" &&
3391
- process.env &&
3392
- process.env.ENABLE_TYPE_CHECK === "true"));
3370
+ // an explicit setTypeChecking() override (incl. `false`) wins over the
3371
+ // dev-mode / env-var default, hence ?? rather than ||
3372
+ return (_typeChecking ??
3373
+ (devMode() ||
3374
+ (typeof process !== "undefined" &&
3375
+ process.env?.ENABLE_TYPE_CHECK === "true")));
3393
3376
  }
3394
3377
  let _devMode = process.env.NODE_ENV !== "production";
3395
3378
  /**
@@ -3623,7 +3606,7 @@ function createFlowSpawner(name, generator) {
3623
3606
  // TODO: support more type of values? See https://github.com/tj/co/blob/249bbdc72da24ae44076afd716349d2089b31c4c/index.js#L100
3624
3607
  if (!ret.value || typeof ret.value.then !== "function") {
3625
3608
  // istanbul ignore next
3626
- throw fail("Only promises can be yielded to `async`, got: " + ret);
3609
+ throw fail(`Only promises can be yielded to \`async\`, got: ${ret}`);
3627
3610
  }
3628
3611
  return ret.value.then(onFulfilled, onRejected);
3629
3612
  }
@@ -3680,22 +3663,13 @@ function invertPatch(patch) {
3680
3663
  };
3681
3664
  }
3682
3665
  }
3683
- /**
3684
- * Simple simple check to check it is a number.
3685
- */
3686
- function isNumber(x) {
3687
- return typeof x === "number";
3688
- }
3689
3666
  /**
3690
3667
  * Escape slashes and backslashes.
3691
3668
  *
3692
3669
  * http://tools.ietf.org/html/rfc6901
3693
3670
  */
3694
3671
  function escapeJsonPath(path) {
3695
- if (isNumber(path) === true) {
3696
- return "" + path;
3697
- }
3698
- if (path.indexOf("/") === -1 && path.indexOf("~") === -1) {
3672
+ if (!path.includes("/") && !path.includes("~")) {
3699
3673
  return path;
3700
3674
  }
3701
3675
  return path.replace(/~/g, "~0").replace(/\//g, "~1");
@@ -3724,7 +3698,7 @@ function joinJsonPath(path) {
3724
3698
  }
3725
3699
  else {
3726
3700
  // absolute
3727
- return "/" + getPathStr(path);
3701
+ return `/${getPathStr(path)}`;
3728
3702
  }
3729
3703
  }
3730
3704
  /**
@@ -3739,9 +3713,9 @@ function splitJsonPath(path) {
3739
3713
  const valid = path === "" ||
3740
3714
  path === "." ||
3741
3715
  path === ".." ||
3742
- stringStartsWith(path, "/") ||
3743
- stringStartsWith(path, "./") ||
3744
- stringStartsWith(path, "../");
3716
+ path.startsWith("/") ||
3717
+ path.startsWith("./") ||
3718
+ path.startsWith("../");
3745
3719
  if (!valid) {
3746
3720
  throw fail(`a json path must be either rooted, empty or relative, but got '${path}'`);
3747
3721
  }
@@ -3949,16 +3923,16 @@ class MSTMap extends ObservableMap {
3949
3923
  }
3950
3924
  get(key) {
3951
3925
  // maybe this is over-enthousiastic? normalize numeric keys to strings
3952
- return super.get("" + key);
3926
+ return super.get(`${key}`);
3953
3927
  }
3954
3928
  has(key) {
3955
- return super.has("" + key);
3929
+ return super.has(`${key}`);
3956
3930
  }
3957
3931
  delete(key) {
3958
- return super.delete("" + key);
3932
+ return super.delete(`${key}`);
3959
3933
  }
3960
3934
  set(key, value) {
3961
- return super.set("" + key, value);
3935
+ return super.set(`${key}`, value);
3962
3936
  }
3963
3937
  put(value) {
3964
3938
  if (!value) {
@@ -4083,9 +4057,9 @@ class MapType extends ComplexType {
4083
4057
  return values(node.storedValue);
4084
4058
  }
4085
4059
  getChildNode(node, key) {
4086
- const childNode = node.storedValue.get("" + key);
4060
+ const childNode = node.storedValue.get(`${key}`);
4087
4061
  if (!childNode) {
4088
- throw fail("Not a child " + key);
4062
+ throw fail(`Not a child ${key}`);
4089
4063
  }
4090
4064
  return childNode;
4091
4065
  }
@@ -4193,7 +4167,7 @@ class MapType extends ComplexType {
4193
4167
  // Don't use target.replace, as it will throw away all existing items first
4194
4168
  for (const key in snapshot) {
4195
4169
  target.set(key, snapshot[key]);
4196
- currentKeys["" + key] = true;
4170
+ currentKeys[`${key}`] = true;
4197
4171
  }
4198
4172
  }
4199
4173
  Object.keys(currentKeys).forEach(key => {
@@ -4293,7 +4267,7 @@ class ArrayType extends ComplexType {
4293
4267
  const subType = objNode.type._subType;
4294
4268
  const result = {};
4295
4269
  snapshot.forEach((item, index) => {
4296
- const subpath = "" + index;
4270
+ const subpath = `${index}`;
4297
4271
  result[subpath] = subType.instantiate(objNode, subpath, undefined, item);
4298
4272
  });
4299
4273
  return result;
@@ -4327,11 +4301,11 @@ class ArrayType extends ComplexType {
4327
4301
  if (index < node.storedValue.length) {
4328
4302
  return node.storedValue[index];
4329
4303
  }
4330
- throw fail("Not a child: " + key);
4304
+ throw fail(`Not a child: ${key}`);
4331
4305
  }
4332
4306
  willChange(change) {
4333
4307
  const node = getStateTreeNode(change.object);
4334
- node.assertWritable({ subpath: "" + change.index });
4308
+ node.assertWritable({ subpath: `${change.index}` });
4335
4309
  const subType = node.type._subType;
4336
4310
  const childNodes = node.getChildren();
4337
4311
  switch (change.type) {
@@ -4357,7 +4331,7 @@ class ArrayType extends ComplexType {
4357
4331
  change.added = addedNodes;
4358
4332
  // update paths of remaining items
4359
4333
  for (let i = index + removedCount; i < childNodes.length; i++) {
4360
- childNodes[i].setParent(node, "" + (i + added.length - removedCount));
4334
+ childNodes[i].setParent(node, `${i + added.length - removedCount}`);
4361
4335
  }
4362
4336
  }
4363
4337
  break;
@@ -4380,7 +4354,7 @@ class ArrayType extends ComplexType {
4380
4354
  case "update":
4381
4355
  return void node.emitPatch({
4382
4356
  op: "replace",
4383
- path: "" + change.index,
4357
+ path: `${change.index}`,
4384
4358
  value: change.newValue.snapshot,
4385
4359
  oldValue: change.oldValue ? change.oldValue.snapshot : undefined
4386
4360
  }, node);
@@ -4388,15 +4362,15 @@ class ArrayType extends ComplexType {
4388
4362
  for (let i = change.removedCount - 1; i >= 0; i--) {
4389
4363
  node.emitPatch({
4390
4364
  op: "remove",
4391
- path: "" + (change.index + i),
4365
+ path: `${change.index + i}`,
4392
4366
  oldValue: change.removed[i].snapshot
4393
4367
  }, node);
4394
4368
  }
4395
4369
  for (let i = 0; i < change.addedCount; i++) {
4396
4370
  node.emitPatch({
4397
4371
  op: "add",
4398
- path: "" + (change.index + i),
4399
- value: node.getChildNode("" + (change.index + i)).snapshot,
4372
+ path: `${change.index + i}`,
4373
+ value: node.getChildNode(`${change.index + i}`).snapshot,
4400
4374
  oldValue: undefined
4401
4375
  }, node);
4402
4376
  }
@@ -4431,7 +4405,7 @@ class ArrayType extends ComplexType {
4431
4405
  return typeCheckFailure(context, value, "Value is not an array");
4432
4406
  }
4433
4407
  for (let i = 0; i < value.length; i++) {
4434
- getContextForPath(context, "" + i, this._subType);
4408
+ getContextForPath(context, `${i}`, this._subType);
4435
4409
  const errors = this._subType.validate(value[i], context);
4436
4410
  popContext(context);
4437
4411
  if (errors.length > 0) {
@@ -4482,7 +4456,7 @@ function reconcileArrayChildren(parent, childType, oldNodes, newValues, newPaths
4482
4456
  const hasNewNode = i <= newValues.length - 1;
4483
4457
  const oldNode = oldNodes[i];
4484
4458
  let newValue = hasNewNode ? newValues[i] : undefined;
4485
- const newPath = "" + newPaths[i];
4459
+ const newPath = `${newPaths[i]}`;
4486
4460
  // for some reason, instead of newValue we got a node, fallback to the storedValue
4487
4461
  // TODO: https://github.com/mobxjs/mobx-state-tree/issues/340#issuecomment-325581681
4488
4462
  if (isNode(newValue)) {
@@ -4918,12 +4892,12 @@ class ModelType extends ComplexType {
4918
4892
  }
4919
4893
  getChildNode(node, key) {
4920
4894
  if (!(key in this.properties)) {
4921
- throw fail("Not a value property: " + key);
4895
+ throw fail(`Not a value property: ${key}`);
4922
4896
  }
4923
4897
  const adm = _getAdministration(node.storedValue, key);
4924
4898
  const childNode = adm.raw?.();
4925
4899
  if (!childNode) {
4926
- throw fail("Node not available for property " + key);
4900
+ throw fail(`Node not available for property ${key}`);
4927
4901
  }
4928
4902
  return childNode;
4929
4903
  }
@@ -5001,11 +4975,9 @@ class ModelType extends ComplexType {
5001
4975
  }
5002
4976
  describe() {
5003
4977
  // optimization: cache
5004
- return ("{ " +
5005
- this.propertyNames
5006
- .map(key => key + ": " + this.properties[key].describe())
5007
- .join("; ") +
5008
- " }");
4978
+ return `{ ${this.propertyNames
4979
+ .map(key => `${key}: ${this.properties[key].describe()}`)
4980
+ .join("; ")} }`;
5009
4981
  }
5010
4982
  getDefaultSnapshot() {
5011
4983
  return EMPTY_OBJECT;
@@ -5050,7 +5022,7 @@ function compose(...args) {
5050
5022
  }
5051
5023
  return args
5052
5024
  .reduce((prev, cur) => prev.cloneAndEnhance({
5053
- name: prev.name + "_" + cur.name,
5025
+ name: `${prev.name}_${cur.name}`,
5054
5026
  properties: cur.properties,
5055
5027
  initializers: cur.initializers,
5056
5028
  preProcessor: (snapshot) => cur.applySnapshotPreProcessor(prev.applySnapshotPreProcessor(snapshot)),
@@ -5217,7 +5189,7 @@ function getPrimitiveFactoryFromValue(value) {
5217
5189
  return DatePrimitive;
5218
5190
  }
5219
5191
  }
5220
- throw fail("Cannot determine primitive type from value " + value);
5192
+ throw fail(`Cannot determine primitive type from value ${value}`);
5221
5193
  }
5222
5194
  /**
5223
5195
  * Returns if a given value represents a primitive type.
@@ -5393,7 +5365,7 @@ function enumeration(name, options) {
5393
5365
  assertIsString(option, i + 1);
5394
5366
  });
5395
5367
  }
5396
- const type = union(...realOptions.map(option => literal("" + option)));
5368
+ const type = union(...realOptions.map(option => literal(`${option}`)));
5397
5369
  if (typeof name === "string") {
5398
5370
  type.name = name;
5399
5371
  }
@@ -5451,7 +5423,7 @@ class Union extends BaseType {
5451
5423
  return this._types.some(subType => subType.isAssignableFrom(type));
5452
5424
  }
5453
5425
  describe() {
5454
- return ("(" + this._types.map(factory => factory.describe()).join(" | ") + ")");
5426
+ return `(${this._types.map(factory => factory.describe()).join(" | ")})`;
5455
5427
  }
5456
5428
  instantiate(parent, subpath, environment, initialValue) {
5457
5429
  const type = this.determineType(initialValue, undefined);
@@ -5493,8 +5465,7 @@ class Union extends BaseType {
5493
5465
  if (errors.length === 0) {
5494
5466
  return baseWithDiscriminator;
5495
5467
  }
5496
- return (`${baseWithDiscriminator}:\n ` +
5497
- formatValidationErrorLines(errors).join("\n "));
5468
+ return `${baseWithDiscriminator}:\n ${formatValidationErrorLines(errors).join("\n ")}`;
5498
5469
  }
5499
5470
  _findCandidateByTypeDiscriminator(discriminator) {
5500
5471
  let found;
@@ -5724,7 +5695,7 @@ function union(optionsOrType, ...otherTypes) {
5724
5695
  const types = isType(optionsOrType)
5725
5696
  ? [optionsOrType, ...otherTypes]
5726
5697
  : otherTypes;
5727
- const name = "(" + types.map(type => type.name).join(" | ") + ")";
5698
+ const name = `(${types.map(type => type.name).join(" | ")})`;
5728
5699
  // check all options
5729
5700
  if (devMode()) {
5730
5701
  if (options) {
@@ -5791,17 +5762,17 @@ class OptionalValue extends BaseType {
5791
5762
  this.optionalValues = optionalValues;
5792
5763
  }
5793
5764
  describe() {
5794
- return this._subtype.describe() + "?";
5765
+ return `${this._subtype.describe()}?`;
5795
5766
  }
5796
5767
  instantiate(parent, subpath, environment, initialValue) {
5797
- if (this.optionalValues.indexOf(initialValue) >= 0) {
5768
+ if (this.optionalValues.includes(initialValue)) {
5798
5769
  const defaultInstanceOrSnapshot = this.getDefaultInstanceOrSnapshot();
5799
5770
  return this._subtype.instantiate(parent, subpath, environment, defaultInstanceOrSnapshot);
5800
5771
  }
5801
5772
  return this._subtype.instantiate(parent, subpath, environment, initialValue);
5802
5773
  }
5803
5774
  reconcile(current, newValue, parent, subpath) {
5804
- return this._subtype.reconcile(current, this.optionalValues.indexOf(newValue) < 0 && this._subtype.is(newValue)
5775
+ return this._subtype.reconcile(current, !this.optionalValues.includes(newValue) && this._subtype.is(newValue)
5805
5776
  ? newValue
5806
5777
  : this.getDefaultInstanceOrSnapshot(), parent, subpath);
5807
5778
  }
@@ -5818,7 +5789,7 @@ class OptionalValue extends BaseType {
5818
5789
  }
5819
5790
  isValidSnapshot(value, context) {
5820
5791
  // defaulted values can be skipped
5821
- if (this.optionalValues.indexOf(value) >= 0) {
5792
+ if (this.optionalValues.includes(value)) {
5822
5793
  return typeCheckSuccess();
5823
5794
  }
5824
5795
  // bounce validation to the sub-type
@@ -6019,8 +5990,7 @@ function late(nameOrType, maybeType) {
6019
5990
  // checks that the type is actually a late type
6020
5991
  if (devMode()) {
6021
5992
  if (!(typeof type === "function" && type.length === 0)) {
6022
- throw fail("Invalid late type, expected a function with zero arguments that returns a type, got: " +
6023
- type);
5993
+ throw fail(`Invalid late type, expected a function with zero arguments that returns a type, got: ${type}`);
6024
5994
  }
6025
5995
  }
6026
5996
  return new Late(name, type);
@@ -6233,8 +6203,7 @@ class StoredReference {
6233
6203
  const normalizedId = normalizeIdentifier(this.identifier);
6234
6204
  const root = node.root;
6235
6205
  const lastCacheModification = root.identifierCache.getLastCacheModificationPerId(normalizedId);
6236
- if (!this.resolvedReference ||
6237
- this.resolvedReference.lastCacheModification !== lastCacheModification) {
6206
+ if (this.resolvedReference?.lastCacheModification !== lastCacheModification) {
6238
6207
  const { targetType } = this;
6239
6208
  // reference was initialized with the identifier of the target
6240
6209
  const target = root.identifierCache.resolve(targetType, normalizedId);
@@ -6243,7 +6212,7 @@ class StoredReference {
6243
6212
  }
6244
6213
  this.resolvedReference = {
6245
6214
  node: target,
6246
- lastCacheModification: lastCacheModification
6215
+ lastCacheModification
6247
6216
  };
6248
6217
  }
6249
6218
  }
@@ -6291,7 +6260,7 @@ class BaseReferenceType extends SimpleType {
6291
6260
  // since it is a scalar value (immutable-ish) and we need to change it
6292
6261
  // from the parent
6293
6262
  const storedRefParentNode = storedRefNode.parent;
6294
- if (!storedRefParentNode || !storedRefParentNode.isAlive) {
6263
+ if (!storedRefParentNode?.isAlive) {
6295
6264
  return;
6296
6265
  }
6297
6266
  const storedRefParentValue = storedRefParentNode.storedValue;
@@ -6363,7 +6332,7 @@ class BaseReferenceType extends SimpleType {
6363
6332
  }
6364
6333
  // make sure the target node is actually there and initialized
6365
6334
  const storedRefParentNode = storedRefNode.parent;
6366
- const storedRefParentValue = storedRefParentNode && storedRefParentNode.storedValue;
6335
+ const storedRefParentValue = storedRefParentNode?.storedValue;
6367
6336
  if (storedRefParentNode &&
6368
6337
  storedRefParentNode.isAlive &&
6369
6338
  storedRefParentValue) {
@@ -6677,7 +6646,7 @@ function isIdentifierType(type) {
6677
6646
  * @hidden
6678
6647
  */
6679
6648
  function normalizeIdentifier(id) {
6680
- return "" + id;
6649
+ return `${id}`;
6681
6650
  }
6682
6651
  /**
6683
6652
  * @internal
@@ -6773,7 +6742,7 @@ class CustomType extends SimpleType {
6773
6742
  instantiate(parent, subpath, environment, initialValue) {
6774
6743
  const valueToStore = this.options.isTargetType(initialValue)
6775
6744
  ? initialValue
6776
- : this.options.fromSnapshot(initialValue, parent && parent.root.environment);
6745
+ : this.options.fromSnapshot(initialValue, parent?.root.environment);
6777
6746
  return createScalarNode(this, parent, subpath, environment, valueToStore);
6778
6747
  }
6779
6748
  reconcile(current, value, parent, subpath) {
@@ -6948,5 +6917,5 @@ const types = {
6948
6917
  resilient
6949
6918
  };
6950
6919
 
6951
- export { addDisposer, addMiddleware, applyAction, applyPatch, applySnapshot, cast, castFlowReturn, castToReferenceSnapshot, castToSnapshot, clone, createActionTrackingMiddleware, createActionTrackingMiddleware2, decorate, destroy, detach, escapeJsonPath, flow, getChildType, getEnv, getIdentifier, getLivelinessChecking, getMembers, getNodeId, getParent, getParentOfType, getPath, getPathParts, getPropertyMembers, getRelativePath, getRoot, getRunningActionContext, getSnapshot, getType, getUnionSubtypes, hasParent, hasParentOfType, isActionContextChildOf, isActionContextThisOrChildOf, isAlive, isArrayType, isFrozenType, isIdentifierType, isLateType, isLiteralType, isMapType, isModelType, isOptionalType, isPrimitiveType, isProtected, isReferenceType, isRefinementType, isRoot, isStateTreeNode, isType, isUnionType, isValidReference, joinJsonPath, onAction, onPatch, onSnapshot, process$1 as process, protect, recordActions, recordPatches, resolveIdentifier, resolvePath, setDevMode, setLivelinessChecking, setLivelynessChecking, splitJsonPath, types as t, toGenerator, toGeneratorFunction, tryReference, tryResolve, typecheck, types, unescapeJsonPath, unprotect, walk };
6920
+ export { addDisposer, addMiddleware, applyAction, applyPatch, applySnapshot, cast, castFlowReturn, castToReferenceSnapshot, castToSnapshot, clone, createActionTrackingMiddleware, createActionTrackingMiddleware2, decorate, destroy, detach, escapeJsonPath, flow, getChildType, getEnv, getIdentifier, getLivelinessChecking, getMembers, getNodeId, getParent, getParentOfType, getPath, getPathParts, getPropertyMembers, getRelativePath, getRoot, getRunningActionContext, getSnapshot, getType, getUnionSubtypes, hasParent, hasParentOfType, isActionContextChildOf, isActionContextThisOrChildOf, isAlive, isArrayType, isFrozenType, isIdentifierType, isLateType, isLiteralType, isMapType, isModelType, isOptionalType, isPrimitiveType, isProtected, isReferenceType, isRefinementType, isRoot, isStateTreeNode, isType, isUnionType, isValidReference, joinJsonPath, onAction, onPatch, onSnapshot, process$1 as process, protect, recordActions, recordPatches, resolveIdentifier, resolvePath, setDevMode, setLivelinessChecking, setLivelynessChecking, setTypeChecking, splitJsonPath, types as t, toGenerator, toGeneratorFunction, tryReference, tryResolve, typecheck, types, unescapeJsonPath, unprotect, walk };
6952
6921
  //# sourceMappingURL=mobx-state-tree.mjs.map