mobx-state-tree 7.0.0-pre.2 → 7.0.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/mobx-state-tree.js +31 -19
- package/dist/mobx-state-tree.min.js +1 -1
- package/dist/mobx-state-tree.module.js +31 -19
- package/dist/mobx-state-tree.umd.js +31 -19
- package/dist/mobx-state-tree.umd.min.js +1 -1
- package/dist/types/complex-types/model.d.ts +10 -7
- package/dist/types/utility-types/union.d.ts +13 -4
- package/package.json +4 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IAnyType, IType, _CustomOrOther, _NotCustomized
|
|
1
|
+
import { FunctionWithFlag, IAnyType, IType, Instance, _CustomOrOther, _NotCustomized } from "../../internal";
|
|
2
2
|
/** @hidden */
|
|
3
3
|
export interface ModelProperties {
|
|
4
4
|
[key: string]: IAnyType;
|
|
@@ -9,6 +9,8 @@ export type ModelPrimitive = string | number | boolean | Date;
|
|
|
9
9
|
export interface ModelPropertiesDeclaration {
|
|
10
10
|
[key: string]: ModelPrimitive | IAnyType;
|
|
11
11
|
}
|
|
12
|
+
/** intersect two object types, but omit keys of B from A before doing so */
|
|
13
|
+
type OmitMerge<A, B> = Omit<A, keyof B> & B;
|
|
12
14
|
/**
|
|
13
15
|
* Unmaps syntax property declarations to a map of { propName: IType }
|
|
14
16
|
*
|
|
@@ -32,6 +34,7 @@ export type ModelPropertiesDeclarationToProperties<T extends ModelPropertiesDecl
|
|
|
32
34
|
* - unknown = true
|
|
33
35
|
*/
|
|
34
36
|
type IsOptionalValue<C, TV, FV> = undefined extends C ? TV : FV;
|
|
37
|
+
type AnyObject = Record<string, any>;
|
|
35
38
|
/**
|
|
36
39
|
* Name of the properties of an object that can't be set to undefined, any or unknown
|
|
37
40
|
* @hidden
|
|
@@ -81,15 +84,15 @@ export interface ModelActions {
|
|
|
81
84
|
export interface IModelType<PROPS extends ModelProperties, OTHERS, CustomC = _NotCustomized, CustomS = _NotCustomized> extends IType<ModelCreationType2<PROPS, CustomC>, ModelSnapshotType2<PROPS, CustomS>, ModelInstanceType<PROPS, OTHERS>> {
|
|
82
85
|
readonly properties: PROPS;
|
|
83
86
|
named(newName: string): IModelType<PROPS, OTHERS, CustomC, CustomS>;
|
|
84
|
-
props<PROPS2 extends ModelPropertiesDeclaration>(props: PROPS2): IModelType<PROPS
|
|
85
|
-
views<V extends
|
|
86
|
-
actions<A extends ModelActions>(fn: (self: Instance<this>) => A): IModelType<PROPS, OTHERS
|
|
87
|
-
volatile<
|
|
88
|
-
extend<A extends ModelActions = {}, V extends
|
|
87
|
+
props<PROPS2 extends ModelPropertiesDeclaration>(props: PROPS2): IModelType<OmitMerge<PROPS, ModelPropertiesDeclarationToProperties<PROPS2>>, OTHERS, CustomC, CustomS>;
|
|
88
|
+
views<V extends AnyObject>(fn: (self: Instance<this>) => V): IModelType<PROPS, OmitMerge<OTHERS, V>, CustomC, CustomS>;
|
|
89
|
+
actions<A extends ModelActions>(fn: (self: Instance<this>) => A): IModelType<PROPS, OmitMerge<OTHERS, A>, CustomC, CustomS>;
|
|
90
|
+
volatile<VS extends AnyObject>(fn: (self: Instance<this>) => VS): IModelType<PROPS, OmitMerge<OTHERS, VS>, CustomC, CustomS>;
|
|
91
|
+
extend<A extends ModelActions = {}, V extends AnyObject = {}, VS extends AnyObject = {}>(fn: (self: Instance<this>) => {
|
|
89
92
|
actions?: A;
|
|
90
93
|
views?: V;
|
|
91
94
|
state?: VS;
|
|
92
|
-
}): IModelType<PROPS, OTHERS
|
|
95
|
+
}): IModelType<PROPS, OmitMerge<OTHERS, A & V & VS>, CustomC, CustomS>;
|
|
93
96
|
preProcessSnapshot<NewC = ModelCreationType2<PROPS, CustomC>>(fn: (snapshot: NewC) => WithAdditionalProperties<ModelCreationType2<PROPS, CustomC>>): IModelType<PROPS, OTHERS, NewC, CustomS>;
|
|
94
97
|
postProcessSnapshot<NewS = ModelSnapshotType2<PROPS, CustomS>>(fn: (snapshot: ModelSnapshotType2<PROPS, CustomS>) => NewS): IModelType<PROPS, OTHERS, CustomC, NewS>;
|
|
95
98
|
}
|
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
import { IType, IAnyType, _NotCustomized } from "../../internal";
|
|
2
|
-
export type ITypeDispatcher = (snapshot:
|
|
3
|
-
export interface UnionOptions {
|
|
2
|
+
export type ITypeDispatcher<Types extends IAnyType[]> = (snapshot: Types[number]["SnapshotType"]) => Types[number];
|
|
3
|
+
export interface UnionOptions<Types extends IAnyType[]> {
|
|
4
|
+
/**
|
|
5
|
+
* Whether or not to use eager validation.
|
|
6
|
+
*
|
|
7
|
+
* When `true`, the first matching type will be used. Otherwise, all types will be checked and the
|
|
8
|
+
* validation will pass if and only if a single type matches.
|
|
9
|
+
*/
|
|
4
10
|
eager?: boolean;
|
|
5
|
-
|
|
11
|
+
/**
|
|
12
|
+
* A function that returns the type to be used given an input snapshot.
|
|
13
|
+
*/
|
|
14
|
+
dispatcher?: ITypeDispatcher<Types>;
|
|
6
15
|
}
|
|
7
16
|
/**
|
|
8
17
|
* Transform _NotCustomized | _NotCustomized... to _NotCustomized, _NotCustomized | A | B to A | B
|
|
@@ -14,7 +23,7 @@ export interface ITypeUnion<C, S, T> extends IType<_CustomCSProcessor<C>, _Custo
|
|
|
14
23
|
}
|
|
15
24
|
export type IUnionType<Types extends IAnyType[]> = ITypeUnion<Types[number]["CreationType"], Types[number]["SnapshotType"], Types[number]["TypeWithoutSTN"]>;
|
|
16
25
|
export declare function union<Types extends IAnyType[]>(...types: Types): IUnionType<Types>;
|
|
17
|
-
export declare function union<Types extends IAnyType[]>(options: UnionOptions
|
|
26
|
+
export declare function union<Types extends IAnyType[]>(options: UnionOptions<Types>, ...types: Types): IUnionType<Types>;
|
|
18
27
|
/**
|
|
19
28
|
* Returns if a given value represents a union type.
|
|
20
29
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mobx-state-tree",
|
|
3
|
-
"version": "7.0.0
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"description": "Opinionated, transactional, MobX powered state container",
|
|
5
5
|
"main": "dist/mobx-state-tree.js",
|
|
6
6
|
"umd:main": "dist/mobx-state-tree.umd.js",
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
"scripts": {
|
|
18
18
|
"clean": "shx rm -rf dist lib",
|
|
19
19
|
"build": "bun run clean && tsc && cpr lib/src dist --filter=\\.js$ && rollup -c",
|
|
20
|
-
"test:dev": "
|
|
21
|
-
"test:prod": "
|
|
20
|
+
"test:dev": "NODE_ENV=development bun test",
|
|
21
|
+
"test:prod": "MST_TESTING=1 NODE_ENV=production bun test",
|
|
22
22
|
"test:all": "bun run test:dev && bun run test:prod && bun run size",
|
|
23
23
|
"test:perf": "bun test ./__tests__/perf/",
|
|
24
24
|
"test:perf:compiled": "bun run build && bun run jest:perf && TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\"}' /usr/bin/time node --expose-gc --require ts-node/register __tests__/perf/report.ts",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"cpr": "^3.0.1",
|
|
62
62
|
"husky": "^7.0.0",
|
|
63
63
|
"lint-staged": "^11.1.2",
|
|
64
|
-
"mobx": "^6.
|
|
64
|
+
"mobx": "^6.13.1",
|
|
65
65
|
"prettier": "^2.4.1",
|
|
66
66
|
"rollup": "^2.18.1",
|
|
67
67
|
"rollup-plugin-commonjs": "^10.0.0",
|