@jbrowse/mobx-state-tree 5.8.6 → 5.9.0
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.
- package/dist/index.d.ts +15 -14
- package/dist/mobx-state-tree.cjs +42 -50
- package/dist/mobx-state-tree.cjs.map +1 -1
- package/dist/mobx-state-tree.mjs +42 -50
- package/dist/mobx-state-tree.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1113,10 +1113,11 @@ interface IMiddlewareEvent extends IActionContext {
|
|
|
1113
1113
|
/** Id of all events, from root until current (excluding current) */
|
|
1114
1114
|
readonly allParentIds: number[];
|
|
1115
1115
|
}
|
|
1116
|
-
|
|
1116
|
+
type FunctionWithFlag = ((...args: any[]) => any) & {
|
|
1117
1117
|
_isMSTAction?: boolean;
|
|
1118
1118
|
_isFlowAction?: boolean;
|
|
1119
|
-
|
|
1119
|
+
$mst_middleware?: IMiddleware[];
|
|
1120
|
+
};
|
|
1120
1121
|
/**
|
|
1121
1122
|
* @internal
|
|
1122
1123
|
* @hidden
|
|
@@ -1160,7 +1161,7 @@ declare function addMiddleware(target: IAnyStateTreeNode, handler: IMiddlewareHa
|
|
|
1160
1161
|
* @param includeHooks
|
|
1161
1162
|
* @returns The original function
|
|
1162
1163
|
*/
|
|
1163
|
-
declare function decorate<T extends
|
|
1164
|
+
declare function decorate<T extends (...args: any[]) => any>(handler: IMiddlewareHandler, fn: T, includeHooks?: boolean): T;
|
|
1164
1165
|
|
|
1165
1166
|
interface IActionContext {
|
|
1166
1167
|
/** Event name (action name for actions) */
|
|
@@ -1658,26 +1659,26 @@ type IsOptionalValue<C, TV, FV> = undefined extends C ? TV : FV;
|
|
|
1658
1659
|
type DefinablePropsNames<T> = {
|
|
1659
1660
|
[K in keyof T]: IsOptionalValue<T[K], never, K>;
|
|
1660
1661
|
}[keyof T];
|
|
1662
|
+
declare const $emptyObject: unique symbol;
|
|
1663
|
+
type EmptyObject = {
|
|
1664
|
+
[$emptyObject]?: never;
|
|
1665
|
+
};
|
|
1661
1666
|
/** @hidden */
|
|
1662
|
-
|
|
1663
|
-
/** @hidden */
|
|
1664
|
-
interface NonEmptyObject {
|
|
1665
|
-
[$nonEmptyObject]?: any;
|
|
1666
|
-
}
|
|
1667
|
+
type MaybeEmpty<T> = keyof T extends never ? EmptyObject : T;
|
|
1667
1668
|
/** @hidden */
|
|
1668
1669
|
type ExtractCFromProps<P extends ModelProperties> = {
|
|
1669
1670
|
[k in keyof P]: P[k]["CreationType"];
|
|
1670
1671
|
};
|
|
1671
1672
|
/** @hidden */
|
|
1672
|
-
type ModelCreationType<PC> = {
|
|
1673
|
+
type ModelCreationType<PC> = MaybeEmpty<{
|
|
1673
1674
|
[P in DefinablePropsNames<PC>]: PC[P];
|
|
1674
|
-
} & Partial<PC
|
|
1675
|
+
}> & Partial<PC>;
|
|
1675
1676
|
/** @hidden */
|
|
1676
|
-
type ModelCreationType2<P extends ModelProperties, CustomC> =
|
|
1677
|
+
type ModelCreationType2<P extends ModelProperties, CustomC> = MaybeEmpty<_CustomOrOther<CustomC, ModelCreationType<ExtractCFromProps<P>>>>;
|
|
1677
1678
|
/** @hidden */
|
|
1678
|
-
type ModelSnapshotType<P extends ModelProperties> = {
|
|
1679
|
+
type ModelSnapshotType<P extends ModelProperties> = MaybeEmpty<{
|
|
1679
1680
|
[K in keyof P]: P[K]["SnapshotType"];
|
|
1680
|
-
}
|
|
1681
|
+
}>;
|
|
1681
1682
|
/** @hidden */
|
|
1682
1683
|
type ModelSnapshotType2<P extends ModelProperties, CustomS> = _CustomOrOther<CustomS, ModelSnapshotType<P>>;
|
|
1683
1684
|
/**
|
|
@@ -1686,7 +1687,7 @@ type ModelSnapshotType2<P extends ModelProperties, CustomS> = _CustomOrOther<Cus
|
|
|
1686
1687
|
*/
|
|
1687
1688
|
type ModelInstanceTypeProps<P extends ModelProperties> = {
|
|
1688
1689
|
[K in keyof P]: P[K]["Type"];
|
|
1689
|
-
}
|
|
1690
|
+
};
|
|
1690
1691
|
/**
|
|
1691
1692
|
* @hidden
|
|
1692
1693
|
* do not transform this to an interface or model instance type generated declarations will be longer
|
package/dist/mobx-state-tree.cjs
CHANGED
|
@@ -702,7 +702,6 @@ function walk(target, processor) {
|
|
|
702
702
|
assertIsStateTreeNode(target, 1);
|
|
703
703
|
assertIsFunction(processor, 2);
|
|
704
704
|
const node = getStateTreeNode(target);
|
|
705
|
-
// tslint:disable-next-line:no_unused-variable
|
|
706
705
|
node.getChildren().forEach(child => {
|
|
707
706
|
if (isStateTreeNode(child.storedValue)) {
|
|
708
707
|
walk(child.storedValue, processor);
|
|
@@ -2440,8 +2439,11 @@ function addMiddleware(target, handler, includeHooks = true) {
|
|
|
2440
2439
|
*/
|
|
2441
2440
|
function decorate(handler, fn, includeHooks = true) {
|
|
2442
2441
|
const middleware = { handler, includeHooks };
|
|
2443
|
-
|
|
2444
|
-
|
|
2442
|
+
const f = fn;
|
|
2443
|
+
if (!f.$mst_middleware) {
|
|
2444
|
+
f.$mst_middleware = [];
|
|
2445
|
+
}
|
|
2446
|
+
f.$mst_middleware.push(middleware);
|
|
2445
2447
|
return fn;
|
|
2446
2448
|
}
|
|
2447
2449
|
class CollectedMiddlewares {
|
|
@@ -2450,8 +2452,9 @@ class CollectedMiddlewares {
|
|
|
2450
2452
|
middlewares = [];
|
|
2451
2453
|
constructor(node, fn) {
|
|
2452
2454
|
// we just push middleware arrays into an array of arrays to avoid making copies
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
+
const mw = fn.$mst_middleware;
|
|
2456
|
+
if (mw) {
|
|
2457
|
+
this.middlewares.push(mw);
|
|
2455
2458
|
}
|
|
2456
2459
|
let n = node;
|
|
2457
2460
|
// Find all middlewares. Optimization: cache this?
|
|
@@ -2493,7 +2496,7 @@ function runMiddleWares(node, baseCall, originalFn) {
|
|
|
2493
2496
|
return mobx.action(originalFn)(...call.args);
|
|
2494
2497
|
}
|
|
2495
2498
|
// skip hooks if asked to
|
|
2496
|
-
if (!middleware.includeHooks &&
|
|
2499
|
+
if (!middleware.includeHooks && call.name in Hook) {
|
|
2497
2500
|
return runNextMiddleware(call);
|
|
2498
2501
|
}
|
|
2499
2502
|
let nextInvoked = false;
|
|
@@ -3171,17 +3174,15 @@ function freeze(value) {
|
|
|
3171
3174
|
* Recursively freeze a value (if not in production)
|
|
3172
3175
|
*/
|
|
3173
3176
|
function deepFreeze(value) {
|
|
3174
|
-
if (
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
!Object.isFrozen(value[propKey])) {
|
|
3182
|
-
deepFreeze(value[propKey]);
|
|
3177
|
+
if (devMode()) {
|
|
3178
|
+
freeze(value);
|
|
3179
|
+
if (isPlainObject(value)) {
|
|
3180
|
+
for (const v of Object.values(value)) {
|
|
3181
|
+
if (!isPrimitive(v) && !Object.isFrozen(v)) {
|
|
3182
|
+
deepFreeze(v);
|
|
3183
|
+
}
|
|
3183
3184
|
}
|
|
3184
|
-
}
|
|
3185
|
+
}
|
|
3185
3186
|
}
|
|
3186
3187
|
return value;
|
|
3187
3188
|
}
|
|
@@ -3547,8 +3548,9 @@ function createFlowSpawner(name, generator) {
|
|
|
3547
3548
|
parentEvent: parentContext,
|
|
3548
3549
|
parentActionEvent: parentActionContext
|
|
3549
3550
|
};
|
|
3551
|
+
const spawnerWithMw = spawner;
|
|
3550
3552
|
function wrap(fn, type, arg) {
|
|
3551
|
-
fn.$mst_middleware =
|
|
3553
|
+
fn.$mst_middleware = spawnerWithMw.$mst_middleware; // pick up any middleware attached to the flow
|
|
3552
3554
|
return runWithActionContext({
|
|
3553
3555
|
...contextBase,
|
|
3554
3556
|
type,
|
|
@@ -3561,7 +3563,7 @@ function createFlowSpawner(name, generator) {
|
|
|
3561
3563
|
gen = generator(...initArgs);
|
|
3562
3564
|
onFulfilled(undefined); // kick off the flow
|
|
3563
3565
|
};
|
|
3564
|
-
init.$mst_middleware =
|
|
3566
|
+
init.$mst_middleware = spawnerWithMw.$mst_middleware;
|
|
3565
3567
|
runWithActionContext({
|
|
3566
3568
|
...contextBase,
|
|
3567
3569
|
type: "flow_spawn",
|
|
@@ -4740,11 +4742,9 @@ class ModelType extends ComplexType {
|
|
|
4740
4742
|
}
|
|
4741
4743
|
// the goal of this is to make sure actions using "this" can call themselves,
|
|
4742
4744
|
// while still allowing the middlewares to register them
|
|
4743
|
-
const middlewares = action2.$mst_middleware; // make sure middlewares are not lost
|
|
4744
4745
|
const boundAction = action2.bind(actions);
|
|
4745
|
-
boundAction._isFlowAction =
|
|
4746
|
-
|
|
4747
|
-
boundAction.$mst_middleware = middlewares;
|
|
4746
|
+
boundAction._isFlowAction = action2._isFlowAction ?? false;
|
|
4747
|
+
boundAction.$mst_middleware = action2.$mst_middleware;
|
|
4748
4748
|
const actionInvoker = createActionInvoker(self, name, boundAction);
|
|
4749
4749
|
actions[name] = actionInvoker;
|
|
4750
4750
|
(!devMode() ? addHiddenFinalProp : addHiddenWritableProp)(self, name, actionInvoker);
|
|
@@ -4870,36 +4870,35 @@ class ModelType extends ComplexType {
|
|
|
4870
4870
|
mobx.intercept(instance, this.willChange);
|
|
4871
4871
|
mobx.observe(instance, this.didChange);
|
|
4872
4872
|
}
|
|
4873
|
-
willChange(
|
|
4874
|
-
// TODO: mobx typings don't seem to take into account that newValue can be set even when removing a prop
|
|
4875
|
-
const change = chg;
|
|
4873
|
+
willChange(change) {
|
|
4876
4874
|
const node = getStateTreeNode(change.object);
|
|
4877
4875
|
const subpath = change.name;
|
|
4878
4876
|
node.assertWritable({ subpath });
|
|
4879
|
-
|
|
4880
|
-
// only
|
|
4881
|
-
if (
|
|
4882
|
-
|
|
4883
|
-
|
|
4877
|
+
// MST's removeChild sets the property to undefined rather than deleting it,
|
|
4878
|
+
// so mobx only ever delivers "update"/"add" changes here, never "remove".
|
|
4879
|
+
if (change.type !== "remove") {
|
|
4880
|
+
const childType = node.type.properties[subpath];
|
|
4881
|
+
// only properties are typed, state are stored as-is references
|
|
4882
|
+
if (childType) {
|
|
4883
|
+
typecheckInternal(childType, change.newValue);
|
|
4884
|
+
change.newValue = childType.reconcile(node.getChildNode(subpath), change.newValue, node, subpath);
|
|
4885
|
+
}
|
|
4884
4886
|
}
|
|
4885
4887
|
return change;
|
|
4886
4888
|
}
|
|
4887
|
-
didChange(
|
|
4888
|
-
// TODO: mobx typings don't seem to take into account that newValue can be set even when removing a prop
|
|
4889
|
-
const change = chg;
|
|
4889
|
+
didChange(change) {
|
|
4890
4890
|
const childNode = getStateTreeNode(change.object);
|
|
4891
4891
|
const childType = childNode.type.properties[change.name];
|
|
4892
|
-
|
|
4893
|
-
|
|
4894
|
-
|
|
4892
|
+
// skip volatile state (no childType) and never-actually-occurring "remove" changes
|
|
4893
|
+
if (childType && change.type !== "remove") {
|
|
4894
|
+
const oldChildValue = change.type === "update" ? change.oldValue.snapshot : undefined;
|
|
4895
|
+
childNode.emitPatch({
|
|
4896
|
+
op: "replace",
|
|
4897
|
+
path: escapeJsonPath(change.name),
|
|
4898
|
+
value: change.newValue.snapshot,
|
|
4899
|
+
oldValue: oldChildValue
|
|
4900
|
+
}, childNode);
|
|
4895
4901
|
}
|
|
4896
|
-
const oldChildValue = change.oldValue ? change.oldValue.snapshot : undefined;
|
|
4897
|
-
childNode.emitPatch({
|
|
4898
|
-
op: "replace",
|
|
4899
|
-
path: escapeJsonPath(change.name),
|
|
4900
|
-
value: change.newValue.snapshot,
|
|
4901
|
-
oldValue: oldChildValue
|
|
4902
|
-
}, childNode);
|
|
4903
4902
|
}
|
|
4904
4903
|
getChildren(node) {
|
|
4905
4904
|
const res = [];
|
|
@@ -5074,7 +5073,6 @@ class CoreType extends SimpleType {
|
|
|
5074
5073
|
this.flags = flags;
|
|
5075
5074
|
this.checker = checker;
|
|
5076
5075
|
this.initializer = initializer;
|
|
5077
|
-
this.flags = flags;
|
|
5078
5076
|
}
|
|
5079
5077
|
describe() {
|
|
5080
5078
|
return this.name;
|
|
@@ -5105,7 +5103,6 @@ class CoreType extends SimpleType {
|
|
|
5105
5103
|
* })
|
|
5106
5104
|
* ```
|
|
5107
5105
|
*/
|
|
5108
|
-
// tslint:disable-next-line:variable-name
|
|
5109
5106
|
const string = new CoreType("string", TypeFlags.String, v => typeof v === "string");
|
|
5110
5107
|
/**
|
|
5111
5108
|
* `types.number` - Creates a type that can only contain a numeric value.
|
|
@@ -5119,7 +5116,6 @@ const string = new CoreType("string", TypeFlags.String, v => typeof v === "strin
|
|
|
5119
5116
|
* })
|
|
5120
5117
|
* ```
|
|
5121
5118
|
*/
|
|
5122
|
-
// tslint:disable-next-line:variable-name
|
|
5123
5119
|
const number = new CoreType("number", TypeFlags.Number, v => typeof v === "number");
|
|
5124
5120
|
/**
|
|
5125
5121
|
* `types.integer` - Creates a type that can only contain an integer value.
|
|
@@ -5132,7 +5128,6 @@ const number = new CoreType("number", TypeFlags.Number, v => typeof v === "numbe
|
|
|
5132
5128
|
* })
|
|
5133
5129
|
* ```
|
|
5134
5130
|
*/
|
|
5135
|
-
// tslint:disable-next-line:variable-name
|
|
5136
5131
|
const integer = new CoreType("integer", TypeFlags.Integer, v => isInteger(v));
|
|
5137
5132
|
/**
|
|
5138
5133
|
* `types.float` - Creates a type that can only contain an float value.
|
|
@@ -5145,7 +5140,6 @@ const integer = new CoreType("integer", TypeFlags.Integer, v => isInteger(v));
|
|
|
5145
5140
|
* })
|
|
5146
5141
|
* ```
|
|
5147
5142
|
*/
|
|
5148
|
-
// tslint:disable-next-line:variable-name
|
|
5149
5143
|
const float = new CoreType("float", TypeFlags.Float, v => isFloat(v));
|
|
5150
5144
|
/**
|
|
5151
5145
|
* `types.finite` - Creates a type that can only contain an finite value.
|
|
@@ -5158,7 +5152,6 @@ const float = new CoreType("float", TypeFlags.Float, v => isFloat(v));
|
|
|
5158
5152
|
* })
|
|
5159
5153
|
* ```
|
|
5160
5154
|
*/
|
|
5161
|
-
// tslint:disable-next-line:variable-name
|
|
5162
5155
|
const finite = new CoreType("finite", TypeFlags.Finite, v => isFinite(v));
|
|
5163
5156
|
/**
|
|
5164
5157
|
* `types.boolean` - Creates a type that can only contain a boolean value.
|
|
@@ -5172,7 +5165,6 @@ const finite = new CoreType("finite", TypeFlags.Finite, v => isFinite(v));
|
|
|
5172
5165
|
* })
|
|
5173
5166
|
* ```
|
|
5174
5167
|
*/
|
|
5175
|
-
// tslint:disable-next-line:variable-name
|
|
5176
5168
|
const boolean = new CoreType("boolean", TypeFlags.Boolean, v => typeof v === "boolean");
|
|
5177
5169
|
/**
|
|
5178
5170
|
* `types.null` - The type of the value `null`
|