react-obsidian 2.13.1 → 2.16.0-alpha.1
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/src/ReferenceCounter.js.map +1 -1
- package/dist/src/decorators/Graph.js +1 -2
- package/dist/src/decorators/Graph.js.map +1 -1
- package/dist/src/decorators/LifecycleBound.d.ts +1 -1
- package/dist/src/decorators/LifecycleBound.d.ts.map +1 -1
- package/dist/src/decorators/LifecycleBound.js +1 -2
- package/dist/src/decorators/LifecycleBound.js.map +1 -1
- package/dist/src/decorators/Singleton.d.ts.map +1 -1
- package/dist/src/decorators/Singleton.js +1 -2
- package/dist/src/decorators/Singleton.js.map +1 -1
- package/dist/src/decorators/inject/Inject.js +1 -2
- package/dist/src/decorators/inject/Inject.js.map +1 -1
- package/dist/src/decorators/inject/Injectable.js +1 -2
- package/dist/src/decorators/inject/Injectable.js.map +1 -1
- package/dist/src/decorators/inject/LateInject.js +1 -2
- package/dist/src/decorators/inject/LateInject.js.map +1 -1
- package/dist/src/decorators/provides/MemoizeDescriptor.js +1 -2
- package/dist/src/decorators/provides/MemoizeDescriptor.js.map +1 -1
- package/dist/src/decorators/provides/Provides.js +1 -2
- package/dist/src/decorators/provides/Provides.js.map +1 -1
- package/dist/src/graph/ObjectGraph.d.ts.map +1 -1
- package/dist/src/graph/ObjectGraph.js +2 -2
- package/dist/src/graph/ObjectGraph.js.map +1 -1
- package/dist/src/graph/PropertyRetriever.js.map +1 -1
- package/dist/src/graph/ProviderBinder.js +1 -2
- package/dist/src/graph/ProviderBinder.js.map +1 -1
- package/dist/src/graph/ServiceLocatorFactory.d.ts.map +1 -1
- package/dist/src/graph/VisitedNodes.js.map +1 -1
- package/dist/src/graph/registry/GraphMiddlewareChain.js.map +1 -1
- package/dist/src/graph/registry/GraphRegistry.d.ts +8 -0
- package/dist/src/graph/registry/GraphRegistry.d.ts.map +1 -1
- package/dist/src/graph/registry/GraphRegistry.js +66 -0
- package/dist/src/graph/registry/GraphRegistry.js.map +1 -1
- package/dist/src/injectors/class/ClassInjector.d.ts.map +1 -1
- package/dist/src/injectors/class/ClassInjector.js.map +1 -1
- package/dist/src/injectors/components/InjectComponent.d.ts +1 -1
- package/dist/src/injectors/components/InjectComponent.d.ts.map +1 -1
- package/dist/src/injectors/components/InjectComponent.js.map +1 -1
- package/dist/src/injectors/components/useGraph.d.ts +1 -1
- package/dist/src/injectors/components/useGraph.d.ts.map +1 -1
- package/dist/src/injectors/components/useInjectionToken.d.ts.map +1 -1
- package/dist/src/injectors/hooks/InjectHook.js +2 -3
- package/dist/src/injectors/hooks/InjectHook.js.map +1 -1
- package/dist/src/model/Model.js.map +1 -1
- package/dist/src/observable/Observable.js.map +1 -1
- package/dist/src/observable/cold/ColdMediatorObservable.js.map +1 -1
- package/dist/src/observable/cold/useColdObservers.js +1 -2
- package/dist/src/observable/cold/useColdObservers.js.map +1 -1
- package/dist/src/observable/mapObservablesToValues.js +1 -2
- package/dist/src/observable/mapObservablesToValues.js.map +1 -1
- package/dist/src/observable/mediator/MediatorObservable.js.map +1 -1
- package/dist/src/observable/useObserver.js +1 -2
- package/dist/src/observable/useObserver.js.map +1 -1
- package/dist/src/observable/useObservers.js +1 -2
- package/dist/src/observable/useObservers.js.map +1 -1
- package/dist/src/utils/React.d.ts.map +1 -1
- package/dist/src/utils/React.js +2 -3
- package/dist/src/utils/React.js.map +1 -1
- package/dist/src/utils/getGlobal.js +1 -2
- package/dist/src/utils/getGlobal.js.map +1 -1
- package/dist/src/utils/isDev.js +1 -2
- package/dist/src/utils/isDev.js.map +1 -1
- package/dist/src/utils/isNumber.js +1 -2
- package/dist/src/utils/isNumber.js.map +1 -1
- package/dist/src/utils/isString.js +1 -2
- package/dist/src/utils/isString.js.map +1 -1
- package/dist/src/utils/uniqueId.js +1 -2
- package/dist/src/utils/uniqueId.js.map +1 -1
- package/dist/test/fixtures/CircularDependencyFromSubgraph.js +2 -2
- package/dist/test/fixtures/CircularDependencyFromSubgraph.js.map +1 -1
- package/dist/test/fixtures/CircularDependencyGraph.js +2 -2
- package/dist/test/fixtures/CircularDependencyGraph.js.map +1 -1
- package/dist/test/fixtures/CircularDependencyGraph2.js +2 -2
- package/dist/test/fixtures/CircularDependencyGraph2.js.map +1 -1
- package/dist/test/fixtures/GraphWithMultipleDependencies.js +2 -2
- package/dist/test/fixtures/GraphWithMultipleDependencies.js.map +1 -1
- package/dist/test/fixtures/GraphWithOnBind.js +2 -2
- package/dist/test/fixtures/GraphWithOnBind.js.map +1 -1
- package/dist/test/fixtures/LifecycleBoundGraph.js +2 -2
- package/dist/test/fixtures/LifecycleBoundGraph.js.map +1 -1
- package/dist/test/fixtures/LifecycleBoundWithLifecycleBoundSubgraph.js +2 -2
- package/dist/test/fixtures/LifecycleBoundWithLifecycleBoundSubgraph.js.map +1 -1
- package/dist/test/fixtures/MainGraph.js.map +1 -1
- package/dist/test/fixtures/ScopedLifecycleBoundGraph.js +2 -2
- package/dist/test/fixtures/ScopedLifecycleBoundGraph.js.map +1 -1
- package/dist/test/fixtures/SingletonGraph.js.map +1 -1
- package/dist/test/fixtures/Subgraph.js.map +1 -1
- package/dist/test/fixtures/SubgraphWithCircularDependency.js +2 -2
- package/dist/test/fixtures/SubgraphWithCircularDependency.js.map +1 -1
- package/dist/test/fixtures/ThrowingMainGraph.js.map +1 -1
- package/dist/test/fixtures/UniqueNumberGraph.js +2 -2
- package/dist/test/fixtures/UniqueNumberGraph.js.map +1 -1
- package/dist/testkit/mockGraphs.js +1 -2
- package/dist/testkit/mockGraphs.js.map +1 -1
- package/dist/testkit/mockModel.js +1 -2
- package/dist/testkit/mockModel.js.map +1 -1
- package/dist/transformers/babel-plugin-obsidian/helpers/index.js +8 -9
- package/dist/transformers/babel-plugin-obsidian/helpers/index.js.map +1 -1
- package/dist/transformers/babel-plugin-obsidian/index.js +1 -1
- package/dist/transformers/babel-plugin-obsidian/index.js.map +1 -1
- package/dist/transformers/babel-plugin-obsidian/unmagler/method.js.map +1 -1
- package/dist/transformers/babel-plugin-obsidian/unmagler/property.js.map +1 -1
- package/package.json +6 -6
- package/src/decorators/LifecycleBound.ts +1 -1
- package/src/graph/registry/GraphRegistry.ts +75 -0
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.providerIsNotNamed = providerIsNotNamed;
|
|
4
|
+
exports.addNameToProviderArguments = addNameToProviderArguments;
|
|
5
|
+
exports.getDecoratorArgument = getDecoratorArgument;
|
|
6
|
+
exports.getMethodName = getMethodName;
|
|
7
|
+
exports.getDecoratorByName = getDecoratorByName;
|
|
8
|
+
exports.getDecoratorName = getDecoratorName;
|
|
9
|
+
exports.paramsToDestructuringAssignment = paramsToDestructuringAssignment;
|
|
10
|
+
exports.passParamNameAsInjectArgument = passParamNameAsInjectArgument;
|
|
4
11
|
/* eslint-disable no-param-reassign */
|
|
5
12
|
const core_1 = require("@babel/core");
|
|
6
13
|
const never = '';
|
|
@@ -16,41 +23,34 @@ function providerIsNotNamed(decorator) {
|
|
|
16
23
|
}
|
|
17
24
|
return true;
|
|
18
25
|
}
|
|
19
|
-
exports.providerIsNotNamed = providerIsNotNamed;
|
|
20
26
|
function addNameToProviderArguments(node, decorator) {
|
|
21
27
|
var _a;
|
|
22
28
|
const argument = (_a = getDecoratorArgument(decorator)) !== null && _a !== void 0 ? _a : core_1.types.objectExpression([]);
|
|
23
29
|
argument.properties.push(core_1.types.objectProperty(core_1.types.identifier('name'), core_1.types.stringLiteral(getMethodName(node))));
|
|
24
30
|
decorator.expression.arguments = [argument];
|
|
25
31
|
}
|
|
26
|
-
exports.addNameToProviderArguments = addNameToProviderArguments;
|
|
27
32
|
function getDecoratorArgument(decorator) {
|
|
28
33
|
if (core_1.types.isCallExpression(decorator.expression)) {
|
|
29
34
|
return decorator.expression.arguments.find((a) => core_1.types.isObjectExpression(a));
|
|
30
35
|
}
|
|
31
36
|
return undefined;
|
|
32
37
|
}
|
|
33
|
-
exports.getDecoratorArgument = getDecoratorArgument;
|
|
34
38
|
function getMethodName(node) {
|
|
35
39
|
if (core_1.types.isIdentifier(node.key))
|
|
36
40
|
return node.key.name;
|
|
37
41
|
throw new Error(`Tried to get class name but encountered unexpected key of type: ${node.key.type}`);
|
|
38
42
|
}
|
|
39
|
-
exports.getMethodName = getMethodName;
|
|
40
43
|
function getDecoratorByName(decorators, decoratorName) {
|
|
41
44
|
return decorators === null || decorators === void 0 ? void 0 : decorators.find((decorator) => get(decorator, 'expression.callee.name') === decoratorName);
|
|
42
45
|
}
|
|
43
|
-
exports.getDecoratorByName = getDecoratorByName;
|
|
44
46
|
function getDecoratorName(decorator) {
|
|
45
47
|
return get(decorator, 'expression.callee.name');
|
|
46
48
|
}
|
|
47
|
-
exports.getDecoratorName = getDecoratorName;
|
|
48
49
|
function paramsToDestructuringAssignment(params) {
|
|
49
50
|
return core_1.types.objectPattern(params
|
|
50
51
|
.filter((p) => core_1.types.isIdentifier(p))
|
|
51
52
|
.map((p) => core_1.types.objectProperty(core_1.types.identifier(p.name), core_1.types.identifier(p.name))));
|
|
52
53
|
}
|
|
53
|
-
exports.paramsToDestructuringAssignment = paramsToDestructuringAssignment;
|
|
54
54
|
function passParamNameAsInjectArgument(node, decorator) {
|
|
55
55
|
if (core_1.types.isCallExpression(decorator.expression)) {
|
|
56
56
|
decorator.expression.arguments = [
|
|
@@ -58,7 +58,6 @@ function passParamNameAsInjectArgument(node, decorator) {
|
|
|
58
58
|
];
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
-
exports.passParamNameAsInjectArgument = passParamNameAsInjectArgument;
|
|
62
61
|
function getNodeName(node) {
|
|
63
62
|
if (core_1.types.isTSParameterProperty(node)) {
|
|
64
63
|
if (core_1.types.isIdentifier(node.parameter)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../transformers/babel-plugin-obsidian/helpers/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../transformers/babel-plugin-obsidian/helpers/index.ts"],"names":[],"mappings":";;AAiBA,gDAWC;AAED,gEAOC;AAED,oDAKC;AAED,sCAGC;AAED,gDAKC;AAED,4CAEC;AAED,0EAIC;AAED,sEASC;AA7ED,sCAAsC;AACtC,sCAAyC;AAYzC,MAAM,KAAK,GAAG,EAAE,CAAC;AAIjB,SAAgB,kBAAkB,CAAC,SAAoB;IACrD,MAAM,QAAQ,GAAG,oBAAoB,CAAC,SAAS,CAAC,CAAC;IACjD,IAAI,YAAC,CAAC,kBAAkB,CAAC,QAAQ,CAAC,EAAE,CAAC;QACnC,OAAO,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;YACpC,IAAI,YAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC;gBAC1B,OAAO,YAAC,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,KAAK,MAAM,CAAC;YACxD,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC,CAAC,KAAK,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAgB,0BAA0B,CAAC,IAAiB,EAAE,SAAoB;;IAChF,MAAM,QAAQ,GAAG,MAAA,oBAAoB,CAAC,SAAS,CAAC,mCAAI,YAAC,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC;IAC3E,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,YAAC,CAAC,cAAc,CACvC,YAAC,CAAC,UAAU,CAAC,MAAM,CAAC,EACpB,YAAC,CAAC,aAAa,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CACrC,CAAC,CAAC;IACF,SAAS,CAAC,UAA6B,CAAC,SAAS,GAAG,CAAC,QAAQ,CAAC,CAAC;AAClE,CAAC;AAED,SAA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 var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = plugin;
|
|
6
7
|
const unmagler_1 = __importDefault(require("./unmagler"));
|
|
7
8
|
const providerArgumentsTransformer = {
|
|
8
9
|
visitor: {
|
|
@@ -37,5 +38,4 @@ const internalVisitor = {
|
|
|
37
38
|
function plugin() {
|
|
38
39
|
return providerArgumentsTransformer;
|
|
39
40
|
}
|
|
40
|
-
exports.default = plugin;
|
|
41
41
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../transformers/babel-plugin-obsidian/index.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../transformers/babel-plugin-obsidian/index.ts"],"names":[],"mappings":";;;;;AA2CA,yBAEC;AApCD,0DAAkC;AAElC,MAAM,4BAA4B,GAAc;IAC9C,OAAO,EAAE;QACP,OAAO,CAAC,IAAuB;YAC7B,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;QACjC,CAAC;KACF;CACF,CAAC;AAEF,MAAM,eAAe,GAAG;IACtB,WAAW,EAAE;QACX,KAAK,CAAC,EAAE,IAAI,EAAyB;YACnC,kBAAQ,CAAC,eAAe,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QAC7C,CAAC;KACF;IACD,aAAa,EAAE;QACb,KAAK,CAAC,EAAE,IAAI,EAA2B;YACrC,kBAAQ,CAAC,iBAAiB,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;YAC3C,kBAAQ,CAAC,iBAAiB,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;QACjD,CAAC;KACF;IACD,UAAU,EAAE;QACV,KAAK,CAAC,EAAE,IAAI,EAAwB;YAClC,kBAAQ,CAAC,cAAc,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAC1C,CAAC;KACF;IACD,mBAAmB,EAAE;QACnB,KAAK,CAAC,EAAE,IAAI,EAAiC;YAC3C,kBAAQ,CAAC,uBAAuB,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACnD,CAAC;KACF;CACF,CAAC;AAEF,SAAwB,MAAM;IAC5B,OAAO,4BAA4B,CAAC;AACtC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"method.js","sourceRoot":"","sources":["../../../../transformers/babel-plugin-obsidian/unmagler/method.ts"],"names":[],"mappings":";;AACA,wCAMoB;AAEpB,SAAS,UAAU,CAAC,IAAY,EAAE,IAAiB;IACjD,MAAM,SAAS,GAAG,IAAA,4BAAkB,EAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IAC5D,IAAI,IAAA,0BAAgB,EAAC,SAAS,CAAC,KAAK,IAAI,EAAE;
|
|
1
|
+
{"version":3,"file":"method.js","sourceRoot":"","sources":["../../../../transformers/babel-plugin-obsidian/unmagler/method.ts"],"names":[],"mappings":";;AACA,wCAMoB;AAEpB,SAAS,UAAU,CAAC,IAAY,EAAE,IAAiB;IACjD,MAAM,SAAS,GAAG,IAAA,4BAAkB,EAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IAC5D,IAAI,IAAA,0BAAgB,EAAC,SAAS,CAAC,KAAK,IAAI,EAAE,CAAC;QACzC,8CAA8C,CAAC,IAAI,CAAC,CAAC;QACrD,0CAA0C,CAAC,IAAI,EAAE,SAAU,CAAC,CAAC;IAC/D,CAAC;AACH,CAAC;AAED,SAAS,8CAA8C,CAAC,IAAiB;IACvE,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAAC,OAAO;IAAC,CAAC;IACzC,MAAM,kBAAkB,GAAG,IAAA,yCAA+B,EAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACxE,6CAA6C;IAC7C,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;IACvB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;AACvC,CAAC;AAED,SAAS,0CAA0C,CAAC,IAAiB,EAAE,SAAoB;IACzF,IAAI,IAAA,4BAAkB,EAAC,SAAS,CAAC,EAAE,CAAC;QAClC,IAAA,oCAA0B,EAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IAC9C,CAAC;AACH,CAAC;AACD,kBAAe,UAAU,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"property.js","sourceRoot":"","sources":["../../../../transformers/babel-plugin-obsidian/unmagler/property.ts"],"names":[],"mappings":";;AACA,wCAMoB;AAEpB,SAAS,gBAAgB,CAAC,IAAY,EAAE,IAAsB;IAC5D,MAAM,SAAS,GAAG,IAAA,4BAAkB,EAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IAC5D,IAAI,IAAA,0BAAgB,EAAC,SAAS,CAAC,KAAK,IAAI,IAAI,gBAAgB,CAAC,SAAU,CAAC,EAAE;
|
|
1
|
+
{"version":3,"file":"property.js","sourceRoot":"","sources":["../../../../transformers/babel-plugin-obsidian/unmagler/property.ts"],"names":[],"mappings":";;AACA,wCAMoB;AAEpB,SAAS,gBAAgB,CAAC,IAAY,EAAE,IAAsB;IAC5D,MAAM,SAAS,GAAG,IAAA,4BAAkB,EAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IAC5D,IAAI,IAAA,0BAAgB,EAAC,SAAS,CAAC,KAAK,IAAI,IAAI,gBAAgB,CAAC,SAAU,CAAC,EAAE,CAAC;QACzE,IAAA,uCAA6B,EAAC,IAAI,EAAE,SAAU,CAAC,CAAC;IAClD,CAAC;AACH,CAAC;AAED,SAAS,gBAAgB,CAAC,SAAoB;IAC5C,OAAO,IAAA,8BAAoB,EAAC,SAAS,CAAC,KAAK,SAAS,CAAC;AACvD,CAAC;AAED,kBAAe,gBAAgB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-obsidian",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.16.0-alpha.1",
|
|
4
4
|
"description": "Dependency injection framework for React and React Native applications",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"prepack": "npm run lint && tsc --project tsconfig.prod.json",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"@types/lodash": "^4.14.176",
|
|
39
39
|
"@types/react": "18.3.x",
|
|
40
40
|
"@types/react-dom": "18.3.x",
|
|
41
|
-
"@typescript-eslint/eslint-plugin": "
|
|
42
|
-
"@typescript-eslint/parser": "
|
|
41
|
+
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
|
42
|
+
"@typescript-eslint/parser": "^7.18.0",
|
|
43
43
|
"babel-plugin-parameter-decorator": "1.x.x",
|
|
44
44
|
"cross-env": "^7.0.3",
|
|
45
45
|
"eslint": "8.x.x",
|
|
@@ -47,10 +47,10 @@
|
|
|
47
47
|
"eslint-plugin-import": "^2.25.2",
|
|
48
48
|
"eslint-plugin-import-newlines": "^1.1.5",
|
|
49
49
|
"eslint-plugin-jest-formatting": "^3.1.0",
|
|
50
|
-
"eslint-plugin-obsidian": "
|
|
50
|
+
"eslint-plugin-obsidian": "workspace:*",
|
|
51
51
|
"eslint-plugin-react": "^7.26.1",
|
|
52
52
|
"eslint-plugin-react-hooks": "^4.2.0",
|
|
53
|
-
"eslint-plugin-unused-imports": "
|
|
53
|
+
"eslint-plugin-unused-imports": "^4.1.4",
|
|
54
54
|
"jest": "29.5.x",
|
|
55
55
|
"jest-environment-jsdom": "^29.5.0",
|
|
56
56
|
"jest-extended": "^4.0.0",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"react": "18.2.x",
|
|
61
61
|
"react-dom": "18.2.x",
|
|
62
62
|
"setimmediate": "^1.0.5",
|
|
63
|
-
"typescript": "^
|
|
63
|
+
"typescript": "^5.7.3"
|
|
64
64
|
},
|
|
65
65
|
"repository": {
|
|
66
66
|
"type": "git",
|
|
@@ -5,6 +5,7 @@ import GraphMiddlewareChain from './GraphMiddlewareChain';
|
|
|
5
5
|
import { ObtainLifecycleBoundGraphException } from './ObtainLifecycleBoundGraphException';
|
|
6
6
|
import { getGlobal } from '../../utils/getGlobal';
|
|
7
7
|
import { isString } from '../../utils/isString';
|
|
8
|
+
import referenceCounter from '../../ReferenceCounter';
|
|
8
9
|
|
|
9
10
|
export class GraphRegistry {
|
|
10
11
|
private readonly constructorToInstance = new Map<Constructable<Graph>, Set<Graph>>();
|
|
@@ -16,6 +17,7 @@ export class GraphRegistry {
|
|
|
16
17
|
private readonly graphMiddlewares = new GraphMiddlewareChain();
|
|
17
18
|
private readonly keyToGenerator = new Map<string,() => Constructable<Graph>>();
|
|
18
19
|
private readonly keyToGraph = new Map<string, Constructable<Graph>>();
|
|
20
|
+
private readonly onClearListeners = new Map<Graph, Set<() => void>>();
|
|
19
21
|
|
|
20
22
|
register(constructor: Constructable<Graph>, subgraphs: Constructable<Graph>[] = []) {
|
|
21
23
|
this.graphToSubgraphs.set(constructor, new Set(subgraphs));
|
|
@@ -33,6 +35,10 @@ export class GraphRegistry {
|
|
|
33
35
|
this.set(graph.constructor as any, graph);
|
|
34
36
|
}
|
|
35
37
|
|
|
38
|
+
public isInstantiated(G: Constructable<Graph>): boolean {
|
|
39
|
+
return (this.constructorToInstance.get(G)?.size ?? 0) > 0;
|
|
40
|
+
}
|
|
41
|
+
|
|
36
42
|
getSubgraphs(graph: Graph): Graph[] {
|
|
37
43
|
const Graph = this.instanceToConstructor.get(graph)!;
|
|
38
44
|
const subgraphs = this.graphToSubgraphs.get(Graph) ?? new Set();
|
|
@@ -62,9 +68,58 @@ export class GraphRegistry {
|
|
|
62
68
|
}
|
|
63
69
|
const graph = this.graphMiddlewares.resolve(Graph, props);
|
|
64
70
|
this.set(Graph, graph, injectionToken);
|
|
71
|
+
this.instantiateCustomScopedSubgraphs(graph, props);
|
|
65
72
|
return graph as T;
|
|
66
73
|
}
|
|
67
74
|
|
|
75
|
+
private instantiateCustomScopedSubgraphs(graph: Graph, props: any) {
|
|
76
|
+
this.assertInstantiatingCustomScopedSubgraphFromSameScope(graph);
|
|
77
|
+
if (!this.isCustomScopedLifecycleBound(this.instanceToConstructor.get(graph)!)) return;
|
|
78
|
+
const customScope = Reflect.getMetadata('lifecycleScope', this.instanceToConstructor.get(graph)!);
|
|
79
|
+
const subgraphs = this.getSubgraphsConstructors(graph);
|
|
80
|
+
const sameScopeSubgraphs = subgraphs.filter(
|
|
81
|
+
subgraph => Reflect.getMetadata('lifecycleScope', subgraph) === customScope,
|
|
82
|
+
);
|
|
83
|
+
const instantiatedSubgraphs = sameScopeSubgraphs.map(
|
|
84
|
+
subgraph => {
|
|
85
|
+
return this.resolve(subgraph, 'lifecycleOwner', props);
|
|
86
|
+
},
|
|
87
|
+
);
|
|
88
|
+
instantiatedSubgraphs.forEach((subgraph) => referenceCounter.retain(subgraph));
|
|
89
|
+
this.registerOnClearListener(graph, () => {
|
|
90
|
+
instantiatedSubgraphs.forEach((subgraph) => referenceCounter.release(subgraph, () => this.clear(subgraph)));
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
private assertInstantiatingCustomScopedSubgraphFromSameScope(graph: Graph) {
|
|
95
|
+
const graphScope = Reflect.getMetadata('lifecycleScope', this.instanceToConstructor.get(graph)!);
|
|
96
|
+
const subgraphs = this.getSubgraphsConstructors(graph);
|
|
97
|
+
subgraphs.forEach(subgraph => {
|
|
98
|
+
const subgraphScope = Reflect.getMetadata('lifecycleScope', subgraph);
|
|
99
|
+
if (
|
|
100
|
+
!this.isInstantiated(subgraph) &&
|
|
101
|
+
this.isCustomScopedLifecycleBound(subgraph) &&
|
|
102
|
+
graphScope !== subgraphScope
|
|
103
|
+
) {
|
|
104
|
+
throw new Error(`Cannot instantiate the scoped graph '${subgraph.name}' as a subgraph of '${graph.constructor.name}' because the scopes do not match. ${graphScope} !== ${subgraphScope}`);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
private getSubgraphsConstructors(graph: Graph | Constructable<Graph>): Constructable<Graph>[] {
|
|
110
|
+
const Graph = typeof graph === 'function' ? graph : this.instanceToConstructor.get(graph)!;
|
|
111
|
+
const directSubgraphs = Array.from(this.graphToSubgraphs.get(Graph) ?? new Set<Constructable<Graph>>());
|
|
112
|
+
if (directSubgraphs.length === 0) return [];
|
|
113
|
+
return [
|
|
114
|
+
...directSubgraphs,
|
|
115
|
+
...new Set(
|
|
116
|
+
directSubgraphs
|
|
117
|
+
.map(subgraph => this.getSubgraphsConstructors(subgraph))
|
|
118
|
+
.flat(),
|
|
119
|
+
),
|
|
120
|
+
];
|
|
121
|
+
}
|
|
122
|
+
|
|
68
123
|
private getGraphConstructorByKey<T extends Graph>(key: string): Constructable<T> {
|
|
69
124
|
if (this.keyToGraph.has(key)) return this.keyToGraph.get(key) as Constructable<T>;
|
|
70
125
|
const generator = this.keyToGenerator.get(key);
|
|
@@ -123,6 +178,11 @@ export class GraphRegistry {
|
|
|
123
178
|
return Reflect.getMetadata('lifecycleScope', Graph) === 'component';
|
|
124
179
|
}
|
|
125
180
|
|
|
181
|
+
private isCustomScopedLifecycleBound(Graph: Constructable<Graph>): boolean {
|
|
182
|
+
const scope = Reflect.getMetadata('lifecycleScope', Graph);
|
|
183
|
+
return typeof scope === 'string' && scope !== 'component' && scope !== 'feature';
|
|
184
|
+
}
|
|
185
|
+
|
|
126
186
|
clearGraphAfterItWasMockedInTests(graphName: string) {
|
|
127
187
|
const graphNames = this.nameToInstance.keys();
|
|
128
188
|
for (const name of graphNames) {
|
|
@@ -140,6 +200,7 @@ export class GraphRegistry {
|
|
|
140
200
|
this.injectionTokenToInstance.delete(token);
|
|
141
201
|
this.instanceToInjectionToken.delete(graph);
|
|
142
202
|
}
|
|
203
|
+
this.invokeOnClearListeners(graph);
|
|
143
204
|
}
|
|
144
205
|
}
|
|
145
206
|
}
|
|
@@ -157,6 +218,20 @@ export class GraphRegistry {
|
|
|
157
218
|
}
|
|
158
219
|
|
|
159
220
|
this.clearGraphsRegisteredByKey(Graph);
|
|
221
|
+
this.invokeOnClearListeners(graph);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
private registerOnClearListener(graph: Graph, callback: () => void) {
|
|
225
|
+
const listeners = this.onClearListeners.get(graph) ?? new Set();
|
|
226
|
+
listeners.add(callback);
|
|
227
|
+
this.onClearListeners.set(graph, listeners);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
private invokeOnClearListeners(graph: Graph) {
|
|
231
|
+
const listeners = this.onClearListeners.get(graph);
|
|
232
|
+
if (!listeners) return;
|
|
233
|
+
listeners.forEach((listener) => listener());
|
|
234
|
+
this.onClearListeners.delete(graph);
|
|
160
235
|
}
|
|
161
236
|
|
|
162
237
|
private clearGraphsRegisteredByKey(Graph: Constructable<Graph>) {
|