mobx-state-tree 3.12.2 → 3.15.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/README.md +103 -23
- package/dist/core/action.d.ts +50 -48
- package/dist/core/actionContext.d.ts +27 -0
- package/dist/core/flow.d.ts +14 -30
- package/dist/core/json-patch.d.ts +36 -36
- package/dist/core/mst-operations.d.ts +451 -444
- package/dist/core/node/BaseNode.d.ts +1 -1
- package/dist/core/node/Hook.d.ts +17 -1
- package/dist/core/node/create-node.d.ts +1 -1
- package/dist/core/node/identifier-cache.d.ts +1 -1
- package/dist/core/node/livelinessChecking.d.ts +37 -37
- package/dist/core/node/node-utils.d.ts +28 -28
- package/dist/core/node/object-node.d.ts +1 -1
- package/dist/core/node/scalar-node.d.ts +1 -1
- package/dist/core/process.d.ts +45 -45
- package/dist/core/type/type-checker.d.ts +30 -30
- package/dist/core/type/type.d.ts +162 -177
- package/dist/index.d.ts +3 -3
- package/dist/internal.d.ts +37 -35
- package/dist/middlewares/create-action-tracking-middleware.d.ts +24 -22
- package/dist/middlewares/createActionTrackingMiddleware2.d.ts +34 -0
- package/dist/middlewares/on-action.d.ts +87 -79
- package/dist/mobx-state-tree.js +6285 -5985
- package/dist/mobx-state-tree.min.js +16 -1
- package/dist/mobx-state-tree.module.js +6234 -5938
- package/dist/mobx-state-tree.umd.js +6263 -5985
- package/dist/mobx-state-tree.umd.min.js +16 -1
- package/dist/types/complex-types/array.d.ts +52 -51
- package/dist/types/complex-types/map.d.ts +80 -79
- package/dist/types/complex-types/model.d.ts +133 -125
- package/dist/types/index.d.ts +29 -29
- package/dist/types/primitives.d.ts +81 -81
- package/dist/types/utility-types/custom.d.ts +60 -60
- package/dist/types/utility-types/enumeration.d.ts +5 -5
- package/dist/types/utility-types/frozen.d.ts +11 -11
- package/dist/types/utility-types/identifier.d.ts +44 -44
- package/dist/types/utility-types/late.d.ts +10 -10
- package/dist/types/utility-types/literal.d.ts +25 -25
- package/dist/types/utility-types/maybe.d.ts +26 -26
- package/dist/types/utility-types/optional.d.ts +20 -20
- package/dist/types/utility-types/reference.d.ts +41 -47
- package/dist/types/utility-types/refinement.d.ts +10 -10
- package/dist/types/utility-types/snapshotProcessor.d.ts +61 -61
- package/dist/types/utility-types/union.d.ts +55 -55
- package/dist/utils.d.ts +4 -4
- package/package.json +16 -12
|
@@ -1,79 +1,87 @@
|
|
|
1
|
-
import { IDisposer, IAnyStateTreeNode } from "../internal";
|
|
2
|
-
export interface ISerializedActionCall {
|
|
3
|
-
name: string;
|
|
4
|
-
path?: string;
|
|
5
|
-
args?: any[];
|
|
6
|
-
}
|
|
7
|
-
export interface IActionRecorder {
|
|
8
|
-
actions: ReadonlyArray<ISerializedActionCall>;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* //
|
|
31
|
-
*
|
|
32
|
-
* //
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* }
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* })
|
|
63
|
-
*
|
|
64
|
-
* const
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
|
|
79
|
-
|
|
1
|
+
import { IDisposer, IAnyStateTreeNode, IActionContext } from "../internal";
|
|
2
|
+
export interface ISerializedActionCall {
|
|
3
|
+
name: string;
|
|
4
|
+
path?: string;
|
|
5
|
+
args?: any[];
|
|
6
|
+
}
|
|
7
|
+
export interface IActionRecorder {
|
|
8
|
+
actions: ReadonlyArray<ISerializedActionCall>;
|
|
9
|
+
readonly recording: boolean;
|
|
10
|
+
stop(): void;
|
|
11
|
+
resume(): void;
|
|
12
|
+
replay(target: IAnyStateTreeNode): void;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Applies an action or a series of actions in a single MobX transaction.
|
|
16
|
+
* Does not return any value
|
|
17
|
+
* Takes an action description as produced by the `onAction` middleware.
|
|
18
|
+
*
|
|
19
|
+
* @param target
|
|
20
|
+
* @param actions
|
|
21
|
+
*/
|
|
22
|
+
export declare function applyAction(target: IAnyStateTreeNode, actions: ISerializedActionCall | ISerializedActionCall[]): void;
|
|
23
|
+
/**
|
|
24
|
+
* Small abstraction around `onAction` and `applyAction`, attaches an action listener to a tree and records all the actions emitted.
|
|
25
|
+
* Returns an recorder object with the following signature:
|
|
26
|
+
*
|
|
27
|
+
* Example:
|
|
28
|
+
* ```ts
|
|
29
|
+
* export interface IActionRecorder {
|
|
30
|
+
* // the recorded actions
|
|
31
|
+
* actions: ISerializedActionCall[]
|
|
32
|
+
* // true if currently recording
|
|
33
|
+
* recording: boolean
|
|
34
|
+
* // stop recording actions
|
|
35
|
+
* stop(): void
|
|
36
|
+
* // resume recording actions
|
|
37
|
+
* resume(): void
|
|
38
|
+
* // apply all the recorded actions on the given object
|
|
39
|
+
* replay(target: IAnyStateTreeNode): void
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* The optional filter function allows to skip recording certain actions.
|
|
44
|
+
*
|
|
45
|
+
* @param subject
|
|
46
|
+
* @returns
|
|
47
|
+
*/
|
|
48
|
+
export declare function recordActions(subject: IAnyStateTreeNode, filter?: (action: ISerializedActionCall, actionContext: IActionContext | undefined) => boolean): IActionRecorder;
|
|
49
|
+
/**
|
|
50
|
+
* Registers a function that will be invoked for each action that is called on the provided model instance, or to any of its children.
|
|
51
|
+
* See [actions](https://github.com/mobxjs/mobx-state-tree#actions) for more details. onAction events are emitted only for the outermost called action in the stack.
|
|
52
|
+
* Action can also be intercepted by middleware using addMiddleware to change the function call before it will be run.
|
|
53
|
+
*
|
|
54
|
+
* Not all action arguments might be serializable. For unserializable arguments, a struct like `{ $MST_UNSERIALIZABLE: true, type: "someType" }` will be generated.
|
|
55
|
+
* MST Nodes are considered non-serializable as well (they could be serialized as there snapshot, but it is uncertain whether an replaying party will be able to handle such a non-instantiated snapshot).
|
|
56
|
+
* Rather, when using `onAction` middleware, one should consider in passing arguments which are 1: an id, 2: a (relative) path, or 3: a snapshot. Instead of a real MST node.
|
|
57
|
+
*
|
|
58
|
+
* Example:
|
|
59
|
+
* ```ts
|
|
60
|
+
* const Todo = types.model({
|
|
61
|
+
* task: types.string
|
|
62
|
+
* })
|
|
63
|
+
*
|
|
64
|
+
* const TodoStore = types.model({
|
|
65
|
+
* todos: types.array(Todo)
|
|
66
|
+
* }).actions(self => ({
|
|
67
|
+
* add(todo) {
|
|
68
|
+
* self.todos.push(todo);
|
|
69
|
+
* }
|
|
70
|
+
* }))
|
|
71
|
+
*
|
|
72
|
+
* const s = TodoStore.create({ todos: [] })
|
|
73
|
+
*
|
|
74
|
+
* let disposer = onAction(s, (call) => {
|
|
75
|
+
* console.log(call);
|
|
76
|
+
* })
|
|
77
|
+
*
|
|
78
|
+
* s.add({ task: "Grab a coffee" })
|
|
79
|
+
* // Logs: { name: "add", path: "", args: [{ task: "Grab a coffee" }] }
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* @param target
|
|
83
|
+
* @param listener
|
|
84
|
+
* @param attachAfter (default false) fires the listener *after* the action has executed instead of before.
|
|
85
|
+
* @returns
|
|
86
|
+
*/
|
|
87
|
+
export declare function onAction(target: IAnyStateTreeNode, listener: (call: ISerializedActionCall) => void, attachAfter?: boolean): IDisposer;
|