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