@jbrowse/mobx-state-tree 5.5.0 → 5.6.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/README.md +18 -0
- package/dist/core/action.d.ts +1 -1
- package/dist/core/action.js +228 -0
- package/dist/core/action.js.map +1 -1
- package/dist/core/actionContext.js +42 -0
- package/dist/core/actionContext.js.map +1 -1
- package/dist/core/flow.d.ts +1 -1
- package/dist/core/flow.js +180 -0
- package/dist/core/flow.js.map +1 -1
- package/dist/core/json-patch.js +133 -0
- package/dist/core/json-patch.js.map +1 -1
- package/dist/core/mst-operations.js +885 -0
- package/dist/core/mst-operations.js.map +1 -1
- package/dist/core/node/BaseNode.js +152 -0
- package/dist/core/node/BaseNode.js.map +1 -1
- package/dist/core/node/Hook.js +15 -0
- package/dist/core/node/Hook.js.map +1 -1
- package/dist/core/node/create-node.js +41 -0
- package/dist/core/node/create-node.js.map +1 -1
- package/dist/core/node/identifier-cache.js +115 -0
- package/dist/core/node/identifier-cache.js.map +1 -1
- package/dist/core/node/livelinessChecking.js +38 -0
- package/dist/core/node/livelinessChecking.js.map +1 -1
- package/dist/core/node/node-utils.js +165 -0
- package/dist/core/node/node-utils.js.map +1 -1
- package/dist/core/node/object-node.js +545 -0
- package/dist/core/node/object-node.js.map +1 -1
- package/dist/core/node/scalar-node.js +89 -0
- package/dist/core/node/scalar-node.js.map +1 -1
- package/dist/core/process.d.ts +1 -1
- package/dist/core/process.js +39 -0
- package/dist/core/process.js.map +1 -1
- package/dist/core/type/type-checker.js +154 -0
- package/dist/core/type/type-checker.js.map +1 -1
- package/dist/core/type/type.d.ts +1 -1
- package/dist/core/type/type.js +251 -0
- package/dist/core/type/type.js.map +1 -1
- package/dist/index.js +85 -0
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +1 -0
- package/dist/internal.js +60 -0
- package/dist/internal.js.map +1 -1
- package/dist/middlewares/create-action-tracking-middleware.js +81 -0
- package/dist/middlewares/create-action-tracking-middleware.js.map +1 -1
- package/dist/middlewares/createActionTrackingMiddleware2.js +133 -0
- package/dist/middlewares/createActionTrackingMiddleware2.js.map +1 -1
- package/dist/middlewares/on-action.js +215 -0
- package/dist/middlewares/on-action.js.map +1 -1
- package/dist/mobx-state-tree.js +83 -6750
- package/dist/mobx-state-tree.module.js +83 -6672
- package/dist/types/complex-types/array.d.ts +1 -1
- package/dist/types/complex-types/array.js +352 -0
- package/dist/types/complex-types/array.js.map +1 -1
- package/dist/types/complex-types/map.d.ts +1 -1
- package/dist/types/complex-types/map.js +361 -0
- package/dist/types/complex-types/map.js.map +1 -1
- package/dist/types/complex-types/model.js +477 -0
- package/dist/types/complex-types/model.js.map +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.js +38 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/primitives.js +182 -0
- package/dist/types/primitives.js.map +1 -1
- package/dist/types/utility-types/custom.js +110 -0
- package/dist/types/utility-types/custom.js.map +1 -1
- package/dist/types/utility-types/enumeration.js +34 -0
- package/dist/types/utility-types/enumeration.js.map +1 -1
- package/dist/types/utility-types/frozen.js +97 -0
- package/dist/types/utility-types/frozen.js.map +1 -1
- package/dist/types/utility-types/identifier.js +129 -0
- package/dist/types/utility-types/identifier.js.map +1 -1
- package/dist/types/utility-types/late.js +109 -0
- package/dist/types/utility-types/late.js.map +1 -1
- package/dist/types/utility-types/lazy.js +76 -0
- package/dist/types/utility-types/lazy.js.map +1 -1
- package/dist/types/utility-types/literal.js +63 -0
- package/dist/types/utility-types/literal.js.map +1 -1
- package/dist/types/utility-types/maybe.js +30 -0
- package/dist/types/utility-types/maybe.js.map +1 -1
- package/dist/types/utility-types/optional.js +140 -0
- package/dist/types/utility-types/optional.js.map +1 -1
- package/dist/types/utility-types/reference.d.ts +2 -2
- package/dist/types/utility-types/reference.js +392 -0
- package/dist/types/utility-types/reference.js.map +1 -1
- package/dist/types/utility-types/refinement.js +85 -0
- package/dist/types/utility-types/refinement.js.map +1 -1
- package/dist/types/utility-types/resilient.d.ts +18 -0
- package/dist/types/utility-types/resilient.js +120 -0
- package/dist/types/utility-types/resilient.js.map +1 -0
- package/dist/types/utility-types/snapshotProcessor.js +161 -0
- package/dist/types/utility-types/snapshotProcessor.js.map +1 -1
- package/dist/types/utility-types/union.d.ts +1 -0
- package/dist/types/utility-types/union.js +245 -0
- package/dist/types/utility-types/union.js.map +1 -1
- package/dist/utils.js +483 -0
- package/dist/utils.js.map +1 -1
- package/package.json +26 -24
- package/changelog.md +0 -677
- package/dist/mobx-state-tree.umd.js +0 -6756
package/dist/index.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isRefinementType = exports.isReferenceType = exports.isProtected = exports.isPrimitiveType = exports.isOptionalType = exports.isModelType = exports.isMapType = exports.isLiteralType = exports.isLateType = exports.isIdentifierType = exports.isFrozenType = exports.isArrayType = exports.isAlive = exports.isActionContextThisOrChildOf = exports.isActionContextChildOf = exports.hasParentOfType = exports.hasParent = exports.getType = exports.getSnapshot = exports.getRunningActionContext = exports.getRoot = exports.getRelativePath = exports.getPropertyMembers = exports.getPathParts = exports.getPath = exports.getParentOfType = exports.getParent = exports.getNodeId = exports.getMembers = exports.getLivelinessChecking = exports.getIdentifier = exports.getEnv = exports.getChildType = exports.flow = exports.escapeJsonPath = exports.detach = exports.destroy = exports.decorate = exports.createActionTrackingMiddleware = exports.createActionTrackingMiddleware2 = exports.clone = exports.castToSnapshot = exports.castToReferenceSnapshot = exports.castFlowReturn = exports.cast = exports.applySnapshot = exports.applyPatch = exports.applyAction = exports.addMiddleware = exports.addDisposer = void 0;
|
|
4
|
+
exports.setDevMode = exports.walk = exports.unprotect = exports.unescapeJsonPath = exports.t = exports.types = exports.typecheck = exports.tryResolve = exports.tryReference = exports.toGeneratorFunction = exports.toGenerator = exports.splitJsonPath = exports.setLivelynessChecking = exports.setLivelinessChecking = exports.resolvePath = exports.resolveIdentifier = exports.recordPatches = exports.recordActions = exports.protect = exports.process = exports.onSnapshot = exports.onPatch = exports.onAction = exports.joinJsonPath = exports.isValidReference = exports.isUnionType = exports.isType = exports.isStateTreeNode = exports.isRoot = void 0;
|
|
5
|
+
var internal_ts_1 = require("./internal.js");
|
|
6
|
+
Object.defineProperty(exports, "addDisposer", { enumerable: true, get: function () { return internal_ts_1.addDisposer; } });
|
|
7
|
+
Object.defineProperty(exports, "addMiddleware", { enumerable: true, get: function () { return internal_ts_1.addMiddleware; } });
|
|
8
|
+
Object.defineProperty(exports, "applyAction", { enumerable: true, get: function () { return internal_ts_1.applyAction; } });
|
|
9
|
+
Object.defineProperty(exports, "applyPatch", { enumerable: true, get: function () { return internal_ts_1.applyPatch; } });
|
|
10
|
+
Object.defineProperty(exports, "applySnapshot", { enumerable: true, get: function () { return internal_ts_1.applySnapshot; } });
|
|
11
|
+
Object.defineProperty(exports, "cast", { enumerable: true, get: function () { return internal_ts_1.cast; } });
|
|
12
|
+
Object.defineProperty(exports, "castFlowReturn", { enumerable: true, get: function () { return internal_ts_1.castFlowReturn; } });
|
|
13
|
+
Object.defineProperty(exports, "castToReferenceSnapshot", { enumerable: true, get: function () { return internal_ts_1.castToReferenceSnapshot; } });
|
|
14
|
+
Object.defineProperty(exports, "castToSnapshot", { enumerable: true, get: function () { return internal_ts_1.castToSnapshot; } });
|
|
15
|
+
Object.defineProperty(exports, "clone", { enumerable: true, get: function () { return internal_ts_1.clone; } });
|
|
16
|
+
Object.defineProperty(exports, "createActionTrackingMiddleware2", { enumerable: true, get: function () { return internal_ts_1.createActionTrackingMiddleware2; } });
|
|
17
|
+
Object.defineProperty(exports, "createActionTrackingMiddleware", { enumerable: true, get: function () { return internal_ts_1.createActionTrackingMiddleware; } });
|
|
18
|
+
Object.defineProperty(exports, "decorate", { enumerable: true, get: function () { return internal_ts_1.decorate; } });
|
|
19
|
+
Object.defineProperty(exports, "destroy", { enumerable: true, get: function () { return internal_ts_1.destroy; } });
|
|
20
|
+
Object.defineProperty(exports, "detach", { enumerable: true, get: function () { return internal_ts_1.detach; } });
|
|
21
|
+
Object.defineProperty(exports, "escapeJsonPath", { enumerable: true, get: function () { return internal_ts_1.escapeJsonPath; } });
|
|
22
|
+
Object.defineProperty(exports, "flow", { enumerable: true, get: function () { return internal_ts_1.flow; } });
|
|
23
|
+
Object.defineProperty(exports, "getChildType", { enumerable: true, get: function () { return internal_ts_1.getChildType; } });
|
|
24
|
+
Object.defineProperty(exports, "getEnv", { enumerable: true, get: function () { return internal_ts_1.getEnv; } });
|
|
25
|
+
Object.defineProperty(exports, "getIdentifier", { enumerable: true, get: function () { return internal_ts_1.getIdentifier; } });
|
|
26
|
+
Object.defineProperty(exports, "getLivelinessChecking", { enumerable: true, get: function () { return internal_ts_1.getLivelinessChecking; } });
|
|
27
|
+
Object.defineProperty(exports, "getMembers", { enumerable: true, get: function () { return internal_ts_1.getMembers; } });
|
|
28
|
+
Object.defineProperty(exports, "getNodeId", { enumerable: true, get: function () { return internal_ts_1.getNodeId; } });
|
|
29
|
+
Object.defineProperty(exports, "getParent", { enumerable: true, get: function () { return internal_ts_1.getParent; } });
|
|
30
|
+
Object.defineProperty(exports, "getParentOfType", { enumerable: true, get: function () { return internal_ts_1.getParentOfType; } });
|
|
31
|
+
Object.defineProperty(exports, "getPath", { enumerable: true, get: function () { return internal_ts_1.getPath; } });
|
|
32
|
+
Object.defineProperty(exports, "getPathParts", { enumerable: true, get: function () { return internal_ts_1.getPathParts; } });
|
|
33
|
+
Object.defineProperty(exports, "getPropertyMembers", { enumerable: true, get: function () { return internal_ts_1.getPropertyMembers; } });
|
|
34
|
+
Object.defineProperty(exports, "getRelativePath", { enumerable: true, get: function () { return internal_ts_1.getRelativePath; } });
|
|
35
|
+
Object.defineProperty(exports, "getRoot", { enumerable: true, get: function () { return internal_ts_1.getRoot; } });
|
|
36
|
+
Object.defineProperty(exports, "getRunningActionContext", { enumerable: true, get: function () { return internal_ts_1.getRunningActionContext; } });
|
|
37
|
+
Object.defineProperty(exports, "getSnapshot", { enumerable: true, get: function () { return internal_ts_1.getSnapshot; } });
|
|
38
|
+
Object.defineProperty(exports, "getType", { enumerable: true, get: function () { return internal_ts_1.getType; } });
|
|
39
|
+
Object.defineProperty(exports, "hasParent", { enumerable: true, get: function () { return internal_ts_1.hasParent; } });
|
|
40
|
+
Object.defineProperty(exports, "hasParentOfType", { enumerable: true, get: function () { return internal_ts_1.hasParentOfType; } });
|
|
41
|
+
Object.defineProperty(exports, "isActionContextChildOf", { enumerable: true, get: function () { return internal_ts_1.isActionContextChildOf; } });
|
|
42
|
+
Object.defineProperty(exports, "isActionContextThisOrChildOf", { enumerable: true, get: function () { return internal_ts_1.isActionContextThisOrChildOf; } });
|
|
43
|
+
Object.defineProperty(exports, "isAlive", { enumerable: true, get: function () { return internal_ts_1.isAlive; } });
|
|
44
|
+
Object.defineProperty(exports, "isArrayType", { enumerable: true, get: function () { return internal_ts_1.isArrayType; } });
|
|
45
|
+
Object.defineProperty(exports, "isFrozenType", { enumerable: true, get: function () { return internal_ts_1.isFrozenType; } });
|
|
46
|
+
Object.defineProperty(exports, "isIdentifierType", { enumerable: true, get: function () { return internal_ts_1.isIdentifierType; } });
|
|
47
|
+
Object.defineProperty(exports, "isLateType", { enumerable: true, get: function () { return internal_ts_1.isLateType; } });
|
|
48
|
+
Object.defineProperty(exports, "isLiteralType", { enumerable: true, get: function () { return internal_ts_1.isLiteralType; } });
|
|
49
|
+
Object.defineProperty(exports, "isMapType", { enumerable: true, get: function () { return internal_ts_1.isMapType; } });
|
|
50
|
+
Object.defineProperty(exports, "isModelType", { enumerable: true, get: function () { return internal_ts_1.isModelType; } });
|
|
51
|
+
Object.defineProperty(exports, "isOptionalType", { enumerable: true, get: function () { return internal_ts_1.isOptionalType; } });
|
|
52
|
+
Object.defineProperty(exports, "isPrimitiveType", { enumerable: true, get: function () { return internal_ts_1.isPrimitiveType; } });
|
|
53
|
+
Object.defineProperty(exports, "isProtected", { enumerable: true, get: function () { return internal_ts_1.isProtected; } });
|
|
54
|
+
Object.defineProperty(exports, "isReferenceType", { enumerable: true, get: function () { return internal_ts_1.isReferenceType; } });
|
|
55
|
+
Object.defineProperty(exports, "isRefinementType", { enumerable: true, get: function () { return internal_ts_1.isRefinementType; } });
|
|
56
|
+
Object.defineProperty(exports, "isRoot", { enumerable: true, get: function () { return internal_ts_1.isRoot; } });
|
|
57
|
+
Object.defineProperty(exports, "isStateTreeNode", { enumerable: true, get: function () { return internal_ts_1.isStateTreeNode; } });
|
|
58
|
+
Object.defineProperty(exports, "isType", { enumerable: true, get: function () { return internal_ts_1.isType; } });
|
|
59
|
+
Object.defineProperty(exports, "isUnionType", { enumerable: true, get: function () { return internal_ts_1.isUnionType; } });
|
|
60
|
+
Object.defineProperty(exports, "isValidReference", { enumerable: true, get: function () { return internal_ts_1.isValidReference; } });
|
|
61
|
+
Object.defineProperty(exports, "joinJsonPath", { enumerable: true, get: function () { return internal_ts_1.joinJsonPath; } });
|
|
62
|
+
Object.defineProperty(exports, "onAction", { enumerable: true, get: function () { return internal_ts_1.onAction; } });
|
|
63
|
+
Object.defineProperty(exports, "onPatch", { enumerable: true, get: function () { return internal_ts_1.onPatch; } });
|
|
64
|
+
Object.defineProperty(exports, "onSnapshot", { enumerable: true, get: function () { return internal_ts_1.onSnapshot; } });
|
|
65
|
+
Object.defineProperty(exports, "process", { enumerable: true, get: function () { return internal_ts_1.process; } });
|
|
66
|
+
Object.defineProperty(exports, "protect", { enumerable: true, get: function () { return internal_ts_1.protect; } });
|
|
67
|
+
Object.defineProperty(exports, "recordActions", { enumerable: true, get: function () { return internal_ts_1.recordActions; } });
|
|
68
|
+
Object.defineProperty(exports, "recordPatches", { enumerable: true, get: function () { return internal_ts_1.recordPatches; } });
|
|
69
|
+
Object.defineProperty(exports, "resolveIdentifier", { enumerable: true, get: function () { return internal_ts_1.resolveIdentifier; } });
|
|
70
|
+
Object.defineProperty(exports, "resolvePath", { enumerable: true, get: function () { return internal_ts_1.resolvePath; } });
|
|
71
|
+
Object.defineProperty(exports, "setLivelinessChecking", { enumerable: true, get: function () { return internal_ts_1.setLivelinessChecking; } });
|
|
72
|
+
Object.defineProperty(exports, "setLivelynessChecking", { enumerable: true, get: function () { return internal_ts_1.setLivelynessChecking; } });
|
|
73
|
+
Object.defineProperty(exports, "splitJsonPath", { enumerable: true, get: function () { return internal_ts_1.splitJsonPath; } });
|
|
74
|
+
Object.defineProperty(exports, "toGenerator", { enumerable: true, get: function () { return internal_ts_1.toGenerator; } });
|
|
75
|
+
Object.defineProperty(exports, "toGeneratorFunction", { enumerable: true, get: function () { return internal_ts_1.toGeneratorFunction; } });
|
|
76
|
+
Object.defineProperty(exports, "tryReference", { enumerable: true, get: function () { return internal_ts_1.tryReference; } });
|
|
77
|
+
Object.defineProperty(exports, "tryResolve", { enumerable: true, get: function () { return internal_ts_1.tryResolve; } });
|
|
78
|
+
Object.defineProperty(exports, "typecheck", { enumerable: true, get: function () { return internal_ts_1.typecheck; } });
|
|
79
|
+
Object.defineProperty(exports, "types", { enumerable: true, get: function () { return internal_ts_1.types; } });
|
|
80
|
+
Object.defineProperty(exports, "t", { enumerable: true, get: function () { return internal_ts_1.types; } });
|
|
81
|
+
Object.defineProperty(exports, "unescapeJsonPath", { enumerable: true, get: function () { return internal_ts_1.unescapeJsonPath; } });
|
|
82
|
+
Object.defineProperty(exports, "unprotect", { enumerable: true, get: function () { return internal_ts_1.unprotect; } });
|
|
83
|
+
Object.defineProperty(exports, "walk", { enumerable: true, get: function () { return internal_ts_1.walk; } });
|
|
84
|
+
Object.defineProperty(exports, "setDevMode", { enumerable: true, get: function () { return internal_ts_1.setDevMode; } });
|
|
85
|
+
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":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AA,WAAW,OAAA;AACX,8GAAA,eAAe,OAAA;AACf,+GAAA,gBAAgB,OAAA;AAChB,qGAAA,MAAM,OAAA;AACN,8GAAA,eAAe,OAAA;AACf,qGAAA,MAAM,OAAA;AACN,0GAAA,WAAW,OAAA;AACX,+GAAA,gBAAgB,OAAA;AAChB,2GAAA,YAAY,OAAA;AACZ,uGAAA,QAAQ,OAAA;AACR,sGAAA,OAAO,OAAA;AACP,yGAAA,UAAU,OAAA;AACV,sGAAA,OAAO,OAAA;AACP,sGAAA,OAAO,OAAA;AACP,4GAAA,aAAa,OAAA;AACb,4GAAA,aAAa,OAAA;AACb,gHAAA,iBAAiB,OAAA;AACjB,0GAAA,WAAW,OAAA;AACX,oHAAA,qBAAqB,OAAA;AACrB,oHAAA,qBAAqB,OAAA;AACrB,4GAAA,aAAa,OAAA;AACb,0GAAA,WAAW,OAAA;AACX,kHAAA,mBAAmB,OAAA;AACnB,2GAAA,YAAY,OAAA;AACZ,yGAAA,UAAU,OAAA;AACV,wGAAA,SAAS,OAAA;AACT,oGAAA,KAAK,OAAA;AACL,gGAAA,KAAK,OAAK;AACV,+GAAA,gBAAgB,OAAA;AAChB,wGAAA,SAAS,OAAA;AACT,mGAAA,IAAI,OAAA;AACJ,yGAAA,UAAU,OAAA"}
|
package/dist/internal.d.ts
CHANGED
|
@@ -35,4 +35,5 @@ export * from "./types/utility-types/frozen.ts";
|
|
|
35
35
|
export * from "./types/utility-types/reference.ts";
|
|
36
36
|
export * from "./types/utility-types/identifier.ts";
|
|
37
37
|
export * from "./types/utility-types/custom.ts";
|
|
38
|
+
export * from "./types/utility-types/resilient.ts";
|
|
38
39
|
export * from "./types/index.ts";
|
package/dist/internal.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* All imports / exports should be proxied through this file.
|
|
4
|
+
* Why? It gives us full control over the module load order, preventing circular dependency isses
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
18
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
19
|
+
};
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
__exportStar(require("./core/node/livelinessChecking.js"), exports);
|
|
22
|
+
__exportStar(require("./core/node/Hook.js"), exports);
|
|
23
|
+
__exportStar(require("./core/mst-operations.js"), exports);
|
|
24
|
+
__exportStar(require("./core/node/BaseNode.js"), exports);
|
|
25
|
+
__exportStar(require("./core/node/scalar-node.js"), exports);
|
|
26
|
+
__exportStar(require("./core/node/object-node.js"), exports);
|
|
27
|
+
__exportStar(require("./core/type/type.js"), exports);
|
|
28
|
+
__exportStar(require("./middlewares/create-action-tracking-middleware.js"), exports);
|
|
29
|
+
__exportStar(require("./middlewares/createActionTrackingMiddleware2.js"), exports);
|
|
30
|
+
__exportStar(require("./middlewares/on-action.js"), exports);
|
|
31
|
+
__exportStar(require("./core/action.js"), exports);
|
|
32
|
+
__exportStar(require("./core/actionContext.js"), exports);
|
|
33
|
+
__exportStar(require("./core/type/type-checker.js"), exports);
|
|
34
|
+
__exportStar(require("./core/node/identifier-cache.js"), exports);
|
|
35
|
+
__exportStar(require("./core/node/create-node.js"), exports);
|
|
36
|
+
__exportStar(require("./core/node/node-utils.js"), exports);
|
|
37
|
+
__exportStar(require("./core/process.js"), exports);
|
|
38
|
+
__exportStar(require("./core/flow.js"), exports);
|
|
39
|
+
__exportStar(require("./core/json-patch.js"), exports);
|
|
40
|
+
__exportStar(require("./utils.js"), exports);
|
|
41
|
+
__exportStar(require("./types/utility-types/snapshotProcessor.js"), exports);
|
|
42
|
+
__exportStar(require("./types/complex-types/map.js"), exports);
|
|
43
|
+
__exportStar(require("./types/complex-types/array.js"), exports);
|
|
44
|
+
__exportStar(require("./types/complex-types/model.js"), exports);
|
|
45
|
+
__exportStar(require("./types/primitives.js"), exports);
|
|
46
|
+
__exportStar(require("./types/utility-types/literal.js"), exports);
|
|
47
|
+
__exportStar(require("./types/utility-types/refinement.js"), exports);
|
|
48
|
+
__exportStar(require("./types/utility-types/enumeration.js"), exports);
|
|
49
|
+
__exportStar(require("./types/utility-types/union.js"), exports);
|
|
50
|
+
__exportStar(require("./types/utility-types/optional.js"), exports);
|
|
51
|
+
__exportStar(require("./types/utility-types/maybe.js"), exports);
|
|
52
|
+
__exportStar(require("./types/utility-types/late.js"), exports);
|
|
53
|
+
__exportStar(require("./types/utility-types/lazy.js"), exports);
|
|
54
|
+
__exportStar(require("./types/utility-types/frozen.js"), exports);
|
|
55
|
+
__exportStar(require("./types/utility-types/reference.js"), exports);
|
|
56
|
+
__exportStar(require("./types/utility-types/identifier.js"), exports);
|
|
57
|
+
__exportStar(require("./types/utility-types/custom.js"), exports);
|
|
58
|
+
__exportStar(require("./types/utility-types/resilient.js"), exports);
|
|
59
|
+
__exportStar(require("./types/index.js"), exports);
|
|
60
|
+
//# sourceMappingURL=internal.js.map
|
package/dist/internal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA;;;GAGG
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;AAEH,oEAAiD;AACjD,sDAAmC;AACnC,2DAAwC;AACxC,0DAAuC;AACvC,6DAA0C;AAC1C,6DAA0C;AAC1C,sDAAmC;AACnC,qFAAkE;AAClE,mFAAgE;AAChE,6DAA0C;AAC1C,mDAAgC;AAChC,0DAAuC;AACvC,8DAA2C;AAC3C,kEAA+C;AAC/C,6DAA0C;AAC1C,4DAAyC;AACzC,oDAAiC;AACjC,iDAA8B;AAC9B,uDAAoC;AACpC,6CAA0B;AAC1B,6EAA0D;AAC1D,+DAA4C;AAC5C,iEAA8C;AAC9C,iEAA8C;AAC9C,wDAAqC;AACrC,mEAAgD;AAChD,sEAAmD;AACnD,uEAAoD;AACpD,iEAA8C;AAC9C,oEAAiD;AACjD,iEAA8C;AAC9C,gEAA6C;AAC7C,gEAA6C;AAC7C,kEAA+C;AAC/C,qEAAkD;AAClD,sEAAmD;AACnD,kEAA+C;AAC/C,qEAAkD;AAClD,mDAAgC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createActionTrackingMiddleware = createActionTrackingMiddleware;
|
|
4
|
+
const runningActions = new Map();
|
|
5
|
+
/**
|
|
6
|
+
* Note: Consider migrating to `createActionTrackingMiddleware2`, it is easier to use.
|
|
7
|
+
*
|
|
8
|
+
* Convenience utility to create action based middleware that supports async processes more easily.
|
|
9
|
+
* All hooks are called for both synchronous and asynchronous actions. Except that either `onSuccess` or `onFail` is called
|
|
10
|
+
*
|
|
11
|
+
* The create middleware tracks the process of an action (assuming it passes the `filter`).
|
|
12
|
+
* `onResume` can return any value, which will be passed as second argument to any other hook. This makes it possible to keep state during a process.
|
|
13
|
+
*
|
|
14
|
+
* See the `atomic` middleware for an example
|
|
15
|
+
*
|
|
16
|
+
* @param hooks
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
function createActionTrackingMiddleware(hooks) {
|
|
20
|
+
return function actionTrackingMiddleware(call, next, _abort) {
|
|
21
|
+
switch (call.type) {
|
|
22
|
+
case "action": {
|
|
23
|
+
if (!hooks.filter || hooks.filter(call) === true) {
|
|
24
|
+
const context = hooks.onStart(call);
|
|
25
|
+
hooks.onResume(call, context);
|
|
26
|
+
runningActions.set(call.id, {
|
|
27
|
+
call,
|
|
28
|
+
context,
|
|
29
|
+
async: false
|
|
30
|
+
});
|
|
31
|
+
try {
|
|
32
|
+
const res = next(call);
|
|
33
|
+
hooks.onSuspend(call, context);
|
|
34
|
+
if (runningActions.get(call.id).async === false) {
|
|
35
|
+
runningActions.delete(call.id);
|
|
36
|
+
hooks.onSuccess(call, context, res);
|
|
37
|
+
}
|
|
38
|
+
return res;
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
runningActions.delete(call.id);
|
|
42
|
+
hooks.onFail(call, context, e);
|
|
43
|
+
throw e;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
return next(call);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
case "flow_spawn": {
|
|
51
|
+
const root = runningActions.get(call.rootId);
|
|
52
|
+
root.async = true;
|
|
53
|
+
return next(call);
|
|
54
|
+
}
|
|
55
|
+
case "flow_resume":
|
|
56
|
+
case "flow_resume_error": {
|
|
57
|
+
const root = runningActions.get(call.rootId);
|
|
58
|
+
hooks.onResume(call, root.context);
|
|
59
|
+
try {
|
|
60
|
+
return next(call);
|
|
61
|
+
}
|
|
62
|
+
finally {
|
|
63
|
+
hooks.onSuspend(call, root.context);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
case "flow_throw": {
|
|
67
|
+
const root = runningActions.get(call.rootId);
|
|
68
|
+
runningActions.delete(call.rootId);
|
|
69
|
+
hooks.onFail(call, root.context, call.args[0]);
|
|
70
|
+
return next(call);
|
|
71
|
+
}
|
|
72
|
+
case "flow_return": {
|
|
73
|
+
const root = runningActions.get(call.rootId);
|
|
74
|
+
runningActions.delete(call.rootId);
|
|
75
|
+
hooks.onSuccess(call, root.context, call.args[0]);
|
|
76
|
+
return next(call);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=create-action-tracking-middleware.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-action-tracking-middleware.js","sourceRoot":"","sources":["../../src/middlewares/create-action-tracking-middleware.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"create-action-tracking-middleware.js","sourceRoot":"","sources":["../../src/middlewares/create-action-tracking-middleware.ts"],"names":[],"mappings":";;AA8BA,wEAgEC;AA5FD,MAAM,cAAc,GAAG,IAAI,GAAG,EAG3B,CAAA;AAWH;;;;;;;;;;;;;GAaG;AACH,SAAgB,8BAA8B,CAC5C,KAAwC;IAExC,OAAO,SAAS,wBAAwB,CACtC,IAAsB,EACtB,IAA2C,EAC3C,MAA2B;QAE3B,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;YAClB,KAAK,QAAQ,CAAC,CAAC,CAAC;gBACd,IAAI,CAAC,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;oBACjD,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;oBACnC,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;oBAC7B,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE;wBAC1B,IAAI;wBACJ,OAAO;wBACP,KAAK,EAAE,KAAK;qBACb,CAAC,CAAA;oBACF,IAAI,CAAC;wBACH,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,CAAA;wBACtB,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;wBAC9B,IAAI,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAE,CA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,CAAE,CAAA;gBAC7C,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;gBAClC,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;gBAC9C,OAAO,IAAI,CAAC,IAAI,CAAC,CAAA;YACnB,CAAC;YACD,KAAK,aAAa,CAAC,CAAC,CAAC;gBACnB,MAAM,IAAI,GAAG,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAE,CAAA;gBAC7C,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;gBAClC,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;gBACjD,OAAO,IAAI,CAAC,IAAI,CAAC,CAAA;YACnB,CAAC;QACH,CAAC;IACH,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createActionTrackingMiddleware2 = createActionTrackingMiddleware2;
|
|
4
|
+
class RunningAction {
|
|
5
|
+
hooks;
|
|
6
|
+
call;
|
|
7
|
+
flowsPending = 0;
|
|
8
|
+
running = true;
|
|
9
|
+
constructor(hooks, call) {
|
|
10
|
+
this.hooks = hooks;
|
|
11
|
+
this.call = call;
|
|
12
|
+
if (hooks) {
|
|
13
|
+
hooks.onStart(call);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
finish(error) {
|
|
17
|
+
if (this.running) {
|
|
18
|
+
this.running = false;
|
|
19
|
+
if (this.hooks) {
|
|
20
|
+
this.hooks.onFinish(this.call, error);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
incFlowsPending() {
|
|
25
|
+
this.flowsPending++;
|
|
26
|
+
}
|
|
27
|
+
decFlowsPending() {
|
|
28
|
+
this.flowsPending--;
|
|
29
|
+
}
|
|
30
|
+
get hasFlowsPending() {
|
|
31
|
+
return this.flowsPending > 0;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Convenience utility to create action based middleware that supports async processes more easily.
|
|
36
|
+
* The flow is like this:
|
|
37
|
+
* - for each action: if filter passes -> `onStart` -> (inner actions recursively) -> `onFinish`
|
|
38
|
+
*
|
|
39
|
+
* Example: if we had an action `a` that called inside an action `b1`, then `b2` the flow would be:
|
|
40
|
+
* - `filter(a)`
|
|
41
|
+
* - `onStart(a)`
|
|
42
|
+
* - `filter(b1)`
|
|
43
|
+
* - `onStart(b1)`
|
|
44
|
+
* - `onFinish(b1)`
|
|
45
|
+
* - `filter(b2)`
|
|
46
|
+
* - `onStart(b2)`
|
|
47
|
+
* - `onFinish(b2)`
|
|
48
|
+
* - `onFinish(a)`
|
|
49
|
+
*
|
|
50
|
+
* The flow is the same no matter if the actions are sync or async.
|
|
51
|
+
*
|
|
52
|
+
* See the `atomic` middleware for an example
|
|
53
|
+
*
|
|
54
|
+
* @param hooks
|
|
55
|
+
* @returns
|
|
56
|
+
*/
|
|
57
|
+
function createActionTrackingMiddleware2(middlewareHooks) {
|
|
58
|
+
const runningActions = new Map();
|
|
59
|
+
return function actionTrackingMiddleware(call, next) {
|
|
60
|
+
// find parentRunningAction
|
|
61
|
+
const parentRunningAction = call.parentActionEvent
|
|
62
|
+
? runningActions.get(call.parentActionEvent.id)
|
|
63
|
+
: undefined;
|
|
64
|
+
if (call.type === "action") {
|
|
65
|
+
const newCall = {
|
|
66
|
+
...call,
|
|
67
|
+
// make a shallow copy of the parent action env
|
|
68
|
+
env: parentRunningAction && parentRunningAction.call.env,
|
|
69
|
+
parentCall: parentRunningAction && parentRunningAction.call
|
|
70
|
+
};
|
|
71
|
+
const passesFilter = !middlewareHooks.filter || middlewareHooks.filter(newCall);
|
|
72
|
+
const hooks = passesFilter ? middlewareHooks : undefined;
|
|
73
|
+
const runningAction = new RunningAction(hooks, newCall);
|
|
74
|
+
runningActions.set(call.id, runningAction);
|
|
75
|
+
let res;
|
|
76
|
+
try {
|
|
77
|
+
res = next(call);
|
|
78
|
+
}
|
|
79
|
+
catch (e) {
|
|
80
|
+
runningActions.delete(call.id);
|
|
81
|
+
runningAction.finish(e);
|
|
82
|
+
throw e;
|
|
83
|
+
}
|
|
84
|
+
// sync action finished
|
|
85
|
+
if (!runningAction.hasFlowsPending) {
|
|
86
|
+
runningActions.delete(call.id);
|
|
87
|
+
runningAction.finish();
|
|
88
|
+
}
|
|
89
|
+
return res;
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
if (!parentRunningAction) {
|
|
93
|
+
return next(call);
|
|
94
|
+
}
|
|
95
|
+
switch (call.type) {
|
|
96
|
+
case "flow_spawn": {
|
|
97
|
+
parentRunningAction.incFlowsPending();
|
|
98
|
+
return next(call);
|
|
99
|
+
}
|
|
100
|
+
case "flow_resume":
|
|
101
|
+
case "flow_resume_error": {
|
|
102
|
+
return next(call);
|
|
103
|
+
}
|
|
104
|
+
case "flow_throw": {
|
|
105
|
+
const error = call.args[0];
|
|
106
|
+
try {
|
|
107
|
+
return next(call);
|
|
108
|
+
}
|
|
109
|
+
finally {
|
|
110
|
+
parentRunningAction.decFlowsPending();
|
|
111
|
+
if (!parentRunningAction.hasFlowsPending) {
|
|
112
|
+
runningActions.delete(call.parentActionEvent.id);
|
|
113
|
+
parentRunningAction.finish(error);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
case "flow_return": {
|
|
118
|
+
try {
|
|
119
|
+
return next(call);
|
|
120
|
+
}
|
|
121
|
+
finally {
|
|
122
|
+
parentRunningAction.decFlowsPending();
|
|
123
|
+
if (!parentRunningAction.hasFlowsPending) {
|
|
124
|
+
runningActions.delete(call.parentActionEvent.id);
|
|
125
|
+
parentRunningAction.finish();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=createActionTrackingMiddleware2.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createActionTrackingMiddleware2.js","sourceRoot":"","sources":["../../src/middlewares/createActionTrackingMiddleware2.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createActionTrackingMiddleware2.js","sourceRoot":"","sources":["../../src/middlewares/createActionTrackingMiddleware2.ts"],"names":[],"mappings":";;AA6EA,0EAmFC;AA7ID,MAAM,aAAa;IAKC;IACP;IALH,YAAY,GAAG,CAAC,CAAA;IAChB,OAAO,GAAG,IAAI,CAAA;IAEtB,YACkB,KAAuD,EAC9D,IAAyC;QADlC,UAAK,GAAL,KAAK,CAAkD;QAC9D,SAAI,GAAJ,IAAI,CAAqC;QAElD,IAAI,KAAK,EAAE,CAAC;YACV,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QACrB,CAAC;IACH,CAAC;IAED,MAAM,CAAC,KAAW;QAChB,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,IAAI,CAAC,OAAO,GAAG,KAAK,CAAA;YACpB,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;gBACf,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;YACvC,CAAC;QACH,CAAC;IACH,CAAC;IAED,eAAe;QACb,IAAI,CAAC,YAAY,EAAE,CAAA;IACrB,CAAC;IAED,eAAe;QACb,IAAI,CAAC,YAAY,EAAE,CAAA;IACrB,CAAC;IAED,IAAI,eAAe;QACjB,OAAO,IAAI,CAAC,YAAY,GAAG,CAAC,CAAA;IAC9B,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,SAAgB,+BAA+B,CAC7C,eAAsD;IAEtD,MAAM,c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A;4BACjD,mBAAmB,CAAC,MAAM,EAAE,CAAA;wBAC9B,CAAC;oBACH,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.applyAction = applyAction;
|
|
4
|
+
exports.recordActions = recordActions;
|
|
5
|
+
exports.onAction = onAction;
|
|
6
|
+
const mobx_1 = require("mobx");
|
|
7
|
+
const internal_ts_1 = require("../internal.js");
|
|
8
|
+
function serializeArgument(node, actionName, index, arg) {
|
|
9
|
+
if (arg instanceof Date) {
|
|
10
|
+
return { $MST_DATE: arg.getTime() };
|
|
11
|
+
}
|
|
12
|
+
if ((0, internal_ts_1.isPrimitive)(arg)) {
|
|
13
|
+
return arg;
|
|
14
|
+
}
|
|
15
|
+
// We should not serialize MST nodes, even if we can, because we don't know if the receiving party can handle a raw snapshot instead of an
|
|
16
|
+
// MST type instance. So if one wants to serialize a MST node that was pass in, either explitly pass: 1: an id, 2: a (relative) path, 3: a snapshot
|
|
17
|
+
if ((0, internal_ts_1.isStateTreeNode)(arg)) {
|
|
18
|
+
return serializeTheUnserializable(`[MSTNode: ${(0, internal_ts_1.getType)(arg).name}]`);
|
|
19
|
+
}
|
|
20
|
+
if (typeof arg === "function") {
|
|
21
|
+
return serializeTheUnserializable(`[function]`);
|
|
22
|
+
}
|
|
23
|
+
if (typeof arg === "object" && !(0, internal_ts_1.isPlainObject)(arg) && !(0, internal_ts_1.isArray)(arg)) {
|
|
24
|
+
return serializeTheUnserializable(`[object ${(arg && arg.constructor && arg.constructor.name) ||
|
|
25
|
+
"Complex Object"}]`);
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
// Check if serializable, cycle free etc...
|
|
29
|
+
// MWE: there must be a better way....
|
|
30
|
+
JSON.stringify(arg); // or throws
|
|
31
|
+
return arg;
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
return serializeTheUnserializable("" + e);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function deserializeArgument(adm, value) {
|
|
38
|
+
if (value && typeof value === "object" && "$MST_DATE" in value) {
|
|
39
|
+
return new Date(value["$MST_DATE"]);
|
|
40
|
+
}
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
function serializeTheUnserializable(baseType) {
|
|
44
|
+
return {
|
|
45
|
+
$MST_UNSERIALIZABLE: true,
|
|
46
|
+
type: baseType
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Applies an action or a series of actions in a single MobX transaction.
|
|
51
|
+
* Does not return any value
|
|
52
|
+
* Takes an action description as produced by the `onAction` middleware.
|
|
53
|
+
*
|
|
54
|
+
* @param target
|
|
55
|
+
* @param actions
|
|
56
|
+
*/
|
|
57
|
+
function applyAction(target, actions) {
|
|
58
|
+
// check all arguments
|
|
59
|
+
(0, internal_ts_1.assertIsStateTreeNode)(target, 1);
|
|
60
|
+
(0, internal_ts_1.assertArg)(actions, a => typeof a === "object", "object or array", 2);
|
|
61
|
+
(0, mobx_1.runInAction)(() => {
|
|
62
|
+
(0, internal_ts_1.asArray)(actions).forEach(action => baseApplyAction(target, action));
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
function baseApplyAction(target, action) {
|
|
66
|
+
const resolvedTarget = (0, internal_ts_1.tryResolve)(target, action.path || "");
|
|
67
|
+
if (!resolvedTarget) {
|
|
68
|
+
throw (0, internal_ts_1.fail)(`Invalid action path: ${action.path || ""}`);
|
|
69
|
+
}
|
|
70
|
+
const node = (0, internal_ts_1.getStateTreeNode)(resolvedTarget);
|
|
71
|
+
// Reserved functions
|
|
72
|
+
if (action.name === "@APPLY_PATCHES") {
|
|
73
|
+
return internal_ts_1.applyPatch.call(null, resolvedTarget, action.args[0]);
|
|
74
|
+
}
|
|
75
|
+
if (action.name === "@APPLY_SNAPSHOT") {
|
|
76
|
+
return internal_ts_1.applySnapshot.call(null, resolvedTarget, action.args[0]);
|
|
77
|
+
}
|
|
78
|
+
if (!(typeof resolvedTarget[action.name] === "function")) {
|
|
79
|
+
throw (0, internal_ts_1.fail)(`Action '${action.name}' does not exist in '${node.path}'`);
|
|
80
|
+
}
|
|
81
|
+
return resolvedTarget[action.name](...(action.args ? action.args.map(v => deserializeArgument(node, v)) : []));
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Small abstraction around `onAction` and `applyAction`, attaches an action listener to a tree and records all the actions emitted.
|
|
85
|
+
* Returns an recorder object with the following signature:
|
|
86
|
+
*
|
|
87
|
+
* Example:
|
|
88
|
+
* ```ts
|
|
89
|
+
* export interface IActionRecorder {
|
|
90
|
+
* // the recorded actions
|
|
91
|
+
* actions: ISerializedActionCall[]
|
|
92
|
+
* // true if currently recording
|
|
93
|
+
* recording: boolean
|
|
94
|
+
* // stop recording actions
|
|
95
|
+
* stop(): void
|
|
96
|
+
* // resume recording actions
|
|
97
|
+
* resume(): void
|
|
98
|
+
* // apply all the recorded actions on the given object
|
|
99
|
+
* replay(target: IAnyStateTreeNode): void
|
|
100
|
+
* }
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* The optional filter function allows to skip recording certain actions.
|
|
104
|
+
*
|
|
105
|
+
* @param subject
|
|
106
|
+
* @returns
|
|
107
|
+
*/
|
|
108
|
+
function recordActions(subject, filter) {
|
|
109
|
+
// check all arguments
|
|
110
|
+
(0, internal_ts_1.assertIsStateTreeNode)(subject, 1);
|
|
111
|
+
const actions = [];
|
|
112
|
+
const listener = (call) => {
|
|
113
|
+
const recordThis = filter ? filter(call, (0, internal_ts_1.getRunningActionContext)()) : true;
|
|
114
|
+
if (recordThis) {
|
|
115
|
+
actions.push(call);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
let disposer;
|
|
119
|
+
const recorder = {
|
|
120
|
+
actions,
|
|
121
|
+
get recording() {
|
|
122
|
+
return !!disposer;
|
|
123
|
+
},
|
|
124
|
+
stop() {
|
|
125
|
+
if (disposer) {
|
|
126
|
+
disposer();
|
|
127
|
+
disposer = undefined;
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
resume() {
|
|
131
|
+
if (disposer) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
disposer = onAction(subject, listener);
|
|
135
|
+
},
|
|
136
|
+
replay(target) {
|
|
137
|
+
applyAction(target, actions);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
recorder.resume();
|
|
141
|
+
return recorder;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Registers a function that will be invoked for each action that is called on the provided model instance, or to any of its children.
|
|
145
|
+
* 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.
|
|
146
|
+
* Action can also be intercepted by middleware using addMiddleware to change the function call before it will be run.
|
|
147
|
+
*
|
|
148
|
+
* Not all action arguments might be serializable. For unserializable arguments, a struct like `{ $MST_UNSERIALIZABLE: true, type: "someType" }` will be generated.
|
|
149
|
+
* 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).
|
|
150
|
+
* 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.
|
|
151
|
+
*
|
|
152
|
+
* Example:
|
|
153
|
+
* ```ts
|
|
154
|
+
* const Todo = types.model({
|
|
155
|
+
* task: types.string
|
|
156
|
+
* })
|
|
157
|
+
*
|
|
158
|
+
* const TodoStore = types.model({
|
|
159
|
+
* todos: types.array(Todo)
|
|
160
|
+
* }).actions(self => ({
|
|
161
|
+
* add(todo) {
|
|
162
|
+
* self.todos.push(todo);
|
|
163
|
+
* }
|
|
164
|
+
* }))
|
|
165
|
+
*
|
|
166
|
+
* const s = TodoStore.create({ todos: [] })
|
|
167
|
+
*
|
|
168
|
+
* let disposer = onAction(s, (call) => {
|
|
169
|
+
* console.log(call);
|
|
170
|
+
* })
|
|
171
|
+
*
|
|
172
|
+
* s.add({ task: "Grab a coffee" })
|
|
173
|
+
* // Logs: { name: "add", path: "", args: [{ task: "Grab a coffee" }] }
|
|
174
|
+
* ```
|
|
175
|
+
*
|
|
176
|
+
* @param target
|
|
177
|
+
* @param listener
|
|
178
|
+
* @param attachAfter (default false) fires the listener *after* the action has executed instead of before.
|
|
179
|
+
* @returns
|
|
180
|
+
*/
|
|
181
|
+
function onAction(target, listener, attachAfter = false) {
|
|
182
|
+
// check all arguments
|
|
183
|
+
(0, internal_ts_1.assertIsStateTreeNode)(target, 1);
|
|
184
|
+
if ((0, internal_ts_1.devMode)()) {
|
|
185
|
+
if (!(0, internal_ts_1.isRoot)(target)) {
|
|
186
|
+
(0, internal_ts_1.warnError)("Warning: Attaching onAction listeners to non root nodes is dangerous: No events will be emitted for actions initiated higher up in the tree.");
|
|
187
|
+
}
|
|
188
|
+
if (!(0, internal_ts_1.isProtected)(target)) {
|
|
189
|
+
(0, internal_ts_1.warnError)("Warning: Attaching onAction listeners to non protected nodes is dangerous: No events will be emitted for direct modifications without action.");
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return (0, internal_ts_1.addMiddleware)(target, function handler(rawCall, next) {
|
|
193
|
+
if (rawCall.type === "action" && rawCall.id === rawCall.rootId) {
|
|
194
|
+
const sourceNode = (0, internal_ts_1.getStateTreeNode)(rawCall.context);
|
|
195
|
+
const info = {
|
|
196
|
+
name: rawCall.name,
|
|
197
|
+
path: (0, internal_ts_1.getRelativePathBetweenNodes)((0, internal_ts_1.getStateTreeNode)(target), sourceNode),
|
|
198
|
+
args: rawCall.args.map((arg, index) => serializeArgument(sourceNode, rawCall.name, index, arg))
|
|
199
|
+
};
|
|
200
|
+
if (attachAfter) {
|
|
201
|
+
const res = next(rawCall);
|
|
202
|
+
listener(info);
|
|
203
|
+
return res;
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
listener(info);
|
|
207
|
+
return next(rawCall);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
return next(rawCall);
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
//# sourceMappingURL=on-action.js.map
|