mobx-state-tree 6.0.1 → 7.0.0-pre.2
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/core/type/type.d.ts +4 -2
- package/dist/mobx-state-tree.js +18 -1
- package/dist/mobx-state-tree.min.js +1 -1
- package/dist/mobx-state-tree.module.js +18 -1
- package/dist/mobx-state-tree.umd.js +18 -1
- package/dist/mobx-state-tree.umd.min.js +1 -1
- package/dist/types/complex-types/model.d.ts +1 -1
- package/dist/types/utility-types/snapshotProcessor.d.ts +2 -2
- package/package.json +3 -3
package/dist/core/type/type.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { IValidationContext, IValidationResult, IStateTreeNode, ModelPrimitive } from "../../internal";
|
|
2
|
+
import type { WritableKeys } from "ts-essentials";
|
|
2
3
|
/**
|
|
3
4
|
* A state tree node value.
|
|
4
5
|
* @hidden
|
|
@@ -6,6 +7,7 @@ import { IValidationContext, IValidationResult, IStateTreeNode, ModelPrimitive }
|
|
|
6
7
|
export type STNValue<T, IT extends IAnyType> = T extends object ? T & IStateTreeNode<IT> : T;
|
|
7
8
|
/** @hidden */
|
|
8
9
|
declare const $type: unique symbol;
|
|
10
|
+
type ExcludeReadonly<T> = T extends {} ? T[WritableKeys<T>] : T;
|
|
9
11
|
/**
|
|
10
12
|
* A type, either complex or simple.
|
|
11
13
|
*/
|
|
@@ -25,7 +27,7 @@ export interface IType<C, S, T> {
|
|
|
25
27
|
*
|
|
26
28
|
* @returns An instance of that type.
|
|
27
29
|
*/
|
|
28
|
-
create(snapshot?: C
|
|
30
|
+
create(snapshot?: C | ExcludeReadonly<T>, env?: any): this["Type"];
|
|
29
31
|
/**
|
|
30
32
|
* Checks if a given snapshot / instance is of the given type.
|
|
31
33
|
*
|
|
@@ -40,7 +42,7 @@ export interface IType<C, S, T> {
|
|
|
40
42
|
* @param context Validation context, an array of { subpaths, subtypes } that should be validated
|
|
41
43
|
* @returns The validation result, an array with the list of validation errors.
|
|
42
44
|
*/
|
|
43
|
-
validate(thing: C, context: IValidationContext): IValidationResult;
|
|
45
|
+
validate(thing: C | T, context: IValidationContext): IValidationResult;
|
|
44
46
|
/**
|
|
45
47
|
* Gets the textual representation of the type as a string.
|
|
46
48
|
*/
|
package/dist/mobx-state-tree.js
CHANGED
|
@@ -4843,6 +4843,23 @@ var SnapshotProcessor = /** @class */ (function (_super) {
|
|
|
4843
4843
|
return this._subtype;
|
|
4844
4844
|
}
|
|
4845
4845
|
});
|
|
4846
|
+
/**
|
|
4847
|
+
* MST considers a given value to "be" of a subtype is the value is either:
|
|
4848
|
+
*
|
|
4849
|
+
* 1. And instance of the subtype
|
|
4850
|
+
* 2. A valid snapshot *in* of the subtype
|
|
4851
|
+
*
|
|
4852
|
+
* Before v7, we used to also consider processed models (as in, SnapshotOut values of this).
|
|
4853
|
+
* This is no longer the case, and is more in line with our overall "is" philosophy, which you can
|
|
4854
|
+
* see in `src/core/type/type.ts:104` (assuming lines don't change too much).
|
|
4855
|
+
*
|
|
4856
|
+
* For additonal commentary, see discussion in https://github.com/mobxjs/mobx-state-tree/pull/2182
|
|
4857
|
+
*
|
|
4858
|
+
* The `is` function specifically checks for `SnapshotIn` or `Instance` of a given type.
|
|
4859
|
+
*
|
|
4860
|
+
* @param thing
|
|
4861
|
+
* @returns
|
|
4862
|
+
*/
|
|
4846
4863
|
Object.defineProperty(SnapshotProcessor.prototype, "is", {
|
|
4847
4864
|
enumerable: false,
|
|
4848
4865
|
configurable: true,
|
|
@@ -4851,7 +4868,7 @@ var SnapshotProcessor = /** @class */ (function (_super) {
|
|
|
4851
4868
|
var value = isType(thing)
|
|
4852
4869
|
? this._subtype
|
|
4853
4870
|
: isStateTreeNode(thing)
|
|
4854
|
-
?
|
|
4871
|
+
? thing
|
|
4855
4872
|
: this.preProcessSnapshotSafe(thing);
|
|
4856
4873
|
if (value === $preProcessorFailed) {
|
|
4857
4874
|
return false;
|