react-obsidian 1.4.0 → 2.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/.yarnrc +1 -0
- package/README.md +4 -0
- package/dist/src/graph/ServiceLocatorFactory.js +1 -1
- package/dist/src/graph/ServiceLocatorFactory.js.map +1 -1
- package/dist/src/graph/registry/GraphRegistry.d.ts +1 -2
- package/dist/src/graph/registry/GraphRegistry.d.ts.map +1 -1
- package/dist/src/graph/registry/GraphRegistry.js +6 -9
- package/dist/src/graph/registry/GraphRegistry.js.map +1 -1
- package/dist/src/graph/registry/ObtainLifecycleBoundGraphException.d.ts +7 -0
- package/dist/src/graph/registry/ObtainLifecycleBoundGraphException.d.ts.map +1 -0
- package/dist/src/graph/registry/ObtainLifecycleBoundGraphException.js +16 -0
- package/dist/src/graph/registry/ObtainLifecycleBoundGraphException.js.map +1 -0
- package/dist/src/injectors/class/ClassInjector.d.ts.map +1 -1
- package/dist/src/injectors/class/ClassInjector.js +8 -1
- package/dist/src/injectors/class/ClassInjector.js.map +1 -1
- package/dist/src/injectors/components/useGraph.js +3 -3
- package/dist/src/injectors/components/useGraph.js.map +1 -1
- package/dist/src/observable/Observable.d.ts +1 -1
- package/dist/src/observable/Observable.d.ts.map +1 -1
- package/dist/src/observable/Observable.js +1 -2
- package/dist/src/observable/Observable.js.map +1 -1
- package/dist/src/observable/useObservers.d.ts.map +1 -1
- package/dist/src/observable/useObservers.js +6 -3
- package/dist/src/observable/useObservers.js.map +1 -1
- package/dist/src/utils/isDev.js +1 -0
- package/dist/src/utils/isDev.js.map +1 -1
- package/dist/transformers/babel-plugin-obsidian/helpers/index.d.ts.map +1 -1
- package/dist/transformers/babel-plugin-obsidian/helpers/index.js +10 -3
- package/dist/transformers/babel-plugin-obsidian/helpers/index.js.map +1 -1
- package/package.json +1 -2
- package/src/graph/ServiceLocatorFactory.ts +1 -1
- package/src/graph/registry/GraphRegistry.ts +10 -10
- package/src/graph/registry/ObtainLifecycleBoundGraphException.ts +15 -0
- package/src/injectors/class/ClassInjector.ts +8 -1
- package/src/injectors/components/useGraph.ts +3 -3
- package/src/observable/Observable.ts +1 -2
- package/src/observable/useObservers.ts +9 -4
- package/src/utils/isDev.ts +1 -0
- package/transformers/babel-plugin-obsidian/helpers/index.ts +7 -1
- package/dist/src/graph/registry/NullProps.d.ts +0 -4
- package/dist/src/graph/registry/NullProps.d.ts.map +0 -1
- package/dist/src/graph/registry/NullProps.js +0 -25
- package/dist/src/graph/registry/NullProps.js.map +0 -1
- package/src/graph/registry/NullProps.ts +0 -23
package/.yarnrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
--registry "https://registry.npmjs.org/"
|
package/README.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
<p align="center">
|
|
4
4
|
</br><img width="300px" src=".github/logo.svg"></br>
|
|
5
|
+
<a href="https://npmjs.com/package/react-obsidian"><img src="https://img.shields.io/npm/v/react-obsidian.svg" alt="npm package"></a>
|
|
6
|
+
<a href="https://www.npmjs.com/package/react-obsidian"><img src="https://img.shields.io/npm/dm/react-obsidian.svg" alt="NPM downloads"></a>
|
|
7
|
+
<a href="https://github.com/wix-incubator/react-obsidian/actions/workflows/ci.yml"><img src="https://github.com/wix-incubator/react-obsidian/actions/workflows/ci.yml/badge.svg?branch=master" alt="build status"></a>
|
|
8
|
+
<a href="https://discord.gg/MDH2axwaPy"><img src="https://img.shields.io/badge/chat-discord-blue?style=flat&logo=discord" alt="discord chat"></a>
|
|
5
9
|
</p>
|
|
6
10
|
|
|
7
11
|
# React Obsidian
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const GraphRegistry_1 = __importDefault(require("./registry/GraphRegistry"));
|
|
7
7
|
class ServiceLocatorFactory {
|
|
8
8
|
static fromGraph(Graph, props) {
|
|
9
|
-
const resolved = GraphRegistry_1.default.resolve(Graph, props);
|
|
9
|
+
const resolved = GraphRegistry_1.default.resolve(Graph, 'serviceLocator', props);
|
|
10
10
|
const wrapped = new Proxy(resolved, {
|
|
11
11
|
get(_target, property, receiver) {
|
|
12
12
|
return () => resolved.retrieve(property, receiver);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServiceLocatorFactory.js","sourceRoot":"","sources":["../../../src/graph/ServiceLocatorFactory.ts"],"names":[],"mappings":";;;;;AAEA,6EAAqD;AAErD,MAAqB,qBAAqB;IACxC,MAAM,CAAC,SAAS,CAAoC,KAAuB,EAAE,KAAS;QACpF,MAAM,QAAQ,GAAG,uBAAa,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"ServiceLocatorFactory.js","sourceRoot":"","sources":["../../../src/graph/ServiceLocatorFactory.ts"],"names":[],"mappings":";;;;;AAEA,6EAAqD;AAErD,MAAqB,qBAAqB;IACxC,MAAM,CAAC,SAAS,CAAoC,KAAuB,EAAE,KAAS;QACpF,MAAM,QAAQ,GAAG,uBAAa,CAAC,OAAO,CAAC,KAAK,EAAE,gBAAgB,EAAE,KAAK,CAAC,CAAC;QACvE,MAAM,OAAO,GAAG,IAAI,KAAK,CAAC,QAAQ,EAAE;YAClC,GAAG,CAAC,OAAY,EAAE,QAAgB,EAAE,QAAa;gBAC/C,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;YACrD,CAAC;SACF,CAAC,CAAC;QACH,OAAO,OAA2C,CAAC;IACrD,CAAC;CACF;AAVD,wCAUC"}
|
|
@@ -11,8 +11,7 @@ export declare class GraphRegistry {
|
|
|
11
11
|
ensureRegistered(graph: Graph): void;
|
|
12
12
|
getSubgraphs(graph: Graph): Graph[];
|
|
13
13
|
getGraphInstance(name: string): Graph;
|
|
14
|
-
resolve<T extends Graph>(Graph: Constructable<T>, props?: any): T;
|
|
15
|
-
private ensurePropsIfLifecycleBoundGraph;
|
|
14
|
+
resolve<T extends Graph>(Graph: Constructable<T>, source?: 'lifecycleOwner' | 'serviceLocator', props?: any): T;
|
|
16
15
|
private has;
|
|
17
16
|
private getFirst;
|
|
18
17
|
private set;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GraphRegistry.d.ts","sourceRoot":"","sources":["../../../../src/graph/registry/GraphRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAI1C,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAA+C;IACrF,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAA0C;IAChF,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA4B;IAC3D,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAA8D;IAC/F,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAA8B;IAE/D,QAAQ,CAAC,WAAW,EAAE,aAAa,CAAC,KAAK,CAAC,EAAE,SAAS,GAAE,aAAa,CAAC,KAAK,CAAC,EAAO;IAIlF,gBAAgB,CAAC,KAAK,EAAE,KAAK;IAK7B,YAAY,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,EAAE;IAMnC,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK;IAIrC,OAAO,CAAC,CAAC,SAAS,KAAK,
|
|
1
|
+
{"version":3,"file":"GraphRegistry.d.ts","sourceRoot":"","sources":["../../../../src/graph/registry/GraphRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAI1C,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAA+C;IACrF,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAA0C;IAChF,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA4B;IAC3D,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAA8D;IAC/F,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAA8B;IAE/D,QAAQ,CAAC,WAAW,EAAE,aAAa,CAAC,KAAK,CAAC,EAAE,SAAS,GAAE,aAAa,CAAC,KAAK,CAAC,EAAO;IAIlF,gBAAgB,CAAC,KAAK,EAAE,KAAK;IAK7B,YAAY,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,EAAE;IAMnC,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK;IAIrC,OAAO,CAAC,CAAC,SAAS,KAAK,EACrB,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,EACvB,MAAM,GAAE,gBAAgB,GAAG,gBAAmC,EAC9D,KAAK,GAAE,GAAe,GACrB,CAAC;IAYJ,OAAO,CAAC,GAAG;IAIX,OAAO,CAAC,QAAQ;IAIhB,OAAO,CAAC,GAAG;IAQX,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,uBAAuB;IAI/B,KAAK,CAAC,KAAK,EAAE,KAAK;IAQlB,kBAAkB,CAAC,UAAU,EAAE,UAAU,CAAC,KAAK,CAAC;IAIhD,qBAAqB;IAIrB,QAAQ;CAKT;;AAED,wBAAmC"}
|
|
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.GraphRegistry = void 0;
|
|
7
7
|
const GraphMiddlewareChain_1 = __importDefault(require("./GraphMiddlewareChain"));
|
|
8
|
-
const
|
|
8
|
+
const ObtainLifecycleBoundGraphException_1 = require("./ObtainLifecycleBoundGraphException");
|
|
9
9
|
class GraphRegistry {
|
|
10
10
|
constructor() {
|
|
11
11
|
this.constructorToInstance = new Map();
|
|
@@ -31,20 +31,17 @@ class GraphRegistry {
|
|
|
31
31
|
getGraphInstance(name) {
|
|
32
32
|
return this.nameToInstance.get(name);
|
|
33
33
|
}
|
|
34
|
-
resolve(Graph, props) {
|
|
34
|
+
resolve(Graph, source = 'lifecycleOwner', props = undefined) {
|
|
35
35
|
if ((this.isSingleton(Graph) || this.isBoundToReactLifecycle(Graph)) && this.has(Graph)) {
|
|
36
36
|
return this.getFirst(Graph);
|
|
37
37
|
}
|
|
38
|
-
|
|
38
|
+
if (this.isBoundToReactLifecycle(Graph) && source === 'serviceLocator') {
|
|
39
|
+
throw new ObtainLifecycleBoundGraphException_1.ObtainLifecycleBoundGraphException(Graph);
|
|
40
|
+
}
|
|
41
|
+
const graph = this.graphMiddlewares.resolve(Graph, props);
|
|
39
42
|
this.set(Graph, graph);
|
|
40
43
|
return graph;
|
|
41
44
|
}
|
|
42
|
-
ensurePropsIfLifecycleBoundGraph(Graph, props) {
|
|
43
|
-
if (this.isBoundToReactLifecycle(Graph)) {
|
|
44
|
-
return props !== null && props !== void 0 ? props : (0, NullProps_1.NullProps)(Graph);
|
|
45
|
-
}
|
|
46
|
-
return props;
|
|
47
|
-
}
|
|
48
45
|
has(Graph) {
|
|
49
46
|
var _a, _b;
|
|
50
47
|
return ((_b = (_a = this.constructorToInstance.get(Graph)) === null || _a === void 0 ? void 0 : _a.size) !== null && _b !== void 0 ? _b : 0) > 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GraphRegistry.js","sourceRoot":"","sources":["../../../../src/graph/registry/GraphRegistry.ts"],"names":[],"mappings":";;;;;;AAGA,kFAA0D;AAC1D,
|
|
1
|
+
{"version":3,"file":"GraphRegistry.js","sourceRoot":"","sources":["../../../../src/graph/registry/GraphRegistry.ts"],"names":[],"mappings":";;;;;;AAGA,kFAA0D;AAC1D,6FAA0F;AAE1F,MAAa,aAAa;IAA1B;QACmB,0BAAqB,GAAG,IAAI,GAAG,EAAoC,CAAC;QACpE,0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CAAC,aAAa,EAAE,KAAK,CAAC,mCAAI,KAAK,CAAC;IAC5D,CAAC;IAEO,uBAAuB,CAAC,KAA2B;;QACzD,OAAO,MAAA,OAAO,CAAC,WAAW,CAAC,kBAAkB,EAAE,KAAK,CAAC,mCAAI,KAAK,CAAC;IACjE,CAAC;IAED,KAAK,CAAC,KAAY;QAChB,MAAM,KAAK,GAAG,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACpD,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC;YAAE,OAAO;QAC9C,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACzC,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,KAAK,CAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACrD,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACzC,CAAC;IAED,kBAAkB,CAAC,UAA6B;QAC9C,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;IACxC,CAAC;IAED,qBAAqB;QACnB,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC;IAChC,CAAC;IAED,QAAQ;QACN,IAAI,CAAC,qBAAqB,CAAC,KAAK,EAAE,CAAC;QACnC,IAAI,CAAC,qBAAqB,CAAC,KAAK,EAAE,CAAC;QACnC,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC;IAC9B,CAAC;CACF;AAvFD,sCAuFC;AAED,kBAAe,IAAI,aAAa,EAAE,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Constructable } from '../../types';
|
|
2
|
+
import { Graph } from '../Graph';
|
|
3
|
+
export declare class ObtainLifecycleBoundGraphException extends Error {
|
|
4
|
+
constructor(graph: Constructable<Graph>);
|
|
5
|
+
private static createMessage;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=ObtainLifecycleBoundGraphException.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ObtainLifecycleBoundGraphException.d.ts","sourceRoot":"","sources":["../../../../src/graph/registry/ObtainLifecycleBoundGraphException.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjC,qBAAa,kCAAmC,SAAQ,KAAK;gBAC/C,KAAK,EAAE,aAAa,CAAC,KAAK,CAAC;IAIvC,OAAO,CAAC,MAAM,CAAC,aAAa;CAK7B"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ObtainLifecycleBoundGraphException = void 0;
|
|
4
|
+
const isDev_1 = require("../../utils/isDev");
|
|
5
|
+
class ObtainLifecycleBoundGraphException extends Error {
|
|
6
|
+
constructor(graph) {
|
|
7
|
+
super(ObtainLifecycleBoundGraphException.createMessage(graph));
|
|
8
|
+
}
|
|
9
|
+
static createMessage(graph) {
|
|
10
|
+
const graphName = (0, isDev_1.isDev)() ? ` ${graph.name}` : '';
|
|
11
|
+
return `Tried to obtain a @LifecycleBound graph${graphName}, but it was not created yet. `
|
|
12
|
+
+ '@LifecycleBound graphs can only be obtained after they were created by a React component or hook.';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.ObtainLifecycleBoundGraphException = ObtainLifecycleBoundGraphException;
|
|
16
|
+
//# sourceMappingURL=ObtainLifecycleBoundGraphException.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ObtainLifecycleBoundGraphException.js","sourceRoot":"","sources":["../../../../src/graph/registry/ObtainLifecycleBoundGraphException.ts"],"names":[],"mappings":";;;AAAA,6CAA0C;AAI1C,MAAa,kCAAmC,SAAQ,KAAK;IAC3D,YAAY,KAA2B;QACrC,KAAK,CAAC,kCAAkC,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC;IACjE,CAAC;IAEO,MAAM,CAAC,aAAa,CAAC,KAA2B;QACtD,MAAM,SAAS,GAAG,IAAA,aAAK,GAAE,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAClD,OAAO,0CAA0C,SAAS,gCAAgC;cACxF,mGAAmG,CAAC;IACxG,CAAC;CACF;AAVD,gFAUC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClassInjector.d.ts","sourceRoot":"","sources":["../../../../src/injectors/class/ClassInjector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AACnE,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,iBAAiB,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"ClassInjector.d.ts","sourceRoot":"","sources":["../../../../src/injectors/class/ClassInjector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AACnE,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,iBAAiB,MAAM,qBAAqB,CAAC;AAIpD,MAAM,CAAC,OAAO,OAAO,aAAa;IAE9B,OAAO,CAAC,aAAa;IACrB,OAAO,CAAC,iBAAiB;gBADjB,aAAa,EAAE,aAAa,EAC5B,iBAAiB,GAAE,iBAA2C;IAGxE,MAAM,CAAC,KAAK,EAAE,aAAa,CAAC,KAAK,CAAC,YAChB,cAAc,GAAG,CAAC;IAKpC,OAAO,CAAC,kBAAkB;CAqC3B"}
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const InjectionMetadata_1 = __importDefault(require("./InjectionMetadata"));
|
|
7
7
|
const LateInjector_1 = require("./LateInjector");
|
|
8
|
+
const ReferenceCounter_1 = __importDefault(require("../../ReferenceCounter"));
|
|
8
9
|
class ClassInjector {
|
|
9
10
|
constructor(graphRegistry, injectionMetadata = new InjectionMetadata_1.default()) {
|
|
10
11
|
this.graphRegistry = graphRegistry;
|
|
@@ -18,12 +19,18 @@ class ClassInjector {
|
|
|
18
19
|
createProxyHandler(Graph, graphRegistry, injectionMetadata) {
|
|
19
20
|
return new class Handler {
|
|
20
21
|
construct(target, args, newTarget) {
|
|
21
|
-
const graph = graphRegistry.resolve(Graph, args.length > 0 ? args[0] : undefined);
|
|
22
|
+
const graph = graphRegistry.resolve(Graph, 'lifecycleOwner', args.length > 0 ? args[0] : undefined);
|
|
23
|
+
ReferenceCounter_1.default.retain(graph);
|
|
22
24
|
Reflect.defineMetadata(LateInjector_1.GRAPH_INSTANCE_NAME_KEY, graph.name, target);
|
|
23
25
|
const argsToInject = this.injectConstructorArgs(args, graph, target);
|
|
24
26
|
graph.onBind(target);
|
|
25
27
|
const createdObject = Reflect.construct(target, argsToInject, newTarget);
|
|
26
28
|
this.injectProperties(target, createdObject, graph);
|
|
29
|
+
const originalComponentWillUnmount = createdObject.componentWillUnmount;
|
|
30
|
+
createdObject.componentWillUnmount = () => {
|
|
31
|
+
originalComponentWillUnmount === null || originalComponentWillUnmount === void 0 ? void 0 : originalComponentWillUnmount();
|
|
32
|
+
ReferenceCounter_1.default.release(graph, (g) => graphRegistry.clear(g));
|
|
33
|
+
};
|
|
27
34
|
return createdObject;
|
|
28
35
|
}
|
|
29
36
|
injectConstructorArgs(args, graph, target) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClassInjector.js","sourceRoot":"","sources":["../../../../src/injectors/class/ClassInjector.ts"],"names":[],"mappings":";;;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G,CAAC,CAAC,CAAC;gBACvD,CAAC,CAAC,CAAC;YACL,CAAC;SACF,EAAE,CAAC;IACN,CAAC;CACF;AAjDD,gCAiDC"}
|
|
@@ -8,9 +8,9 @@ const GraphRegistry_1 = __importDefault(require("../../graph/registry/GraphRegis
|
|
|
8
8
|
const ReferenceCounter_1 = __importDefault(require("../../ReferenceCounter"));
|
|
9
9
|
exports.default = (Graph, target, props) => {
|
|
10
10
|
const [graph] = (0, react_1.useState)(() => {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
return
|
|
11
|
+
const resolvedGraph = GraphRegistry_1.default.resolve(Graph, 'lifecycleOwner', props);
|
|
12
|
+
resolvedGraph.onBind(target);
|
|
13
|
+
return resolvedGraph;
|
|
14
14
|
});
|
|
15
15
|
(0, react_1.useEffect)(() => {
|
|
16
16
|
ReferenceCounter_1.default.retain(graph);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGraph.js","sourceRoot":"","sources":["../../../../src/injectors/components/useGraph.ts"],"names":[],"mappings":";;;;;AAAA,iCAA4C;AAG5C,uFAA+D;AAC/D,8EAAsD;AAEtD,kBAAe,CAAI,KAAiC,EAAE,MAAW,EAAE,KAAkB,EAAE,EAAE;IACvF,MAAM,CAAC,KAAK,CAAC,GAAG,IAAA,gBAAQ,EAAC,GAAG,EAAE;QAC5B,MAAM,
|
|
1
|
+
{"version":3,"file":"useGraph.js","sourceRoot":"","sources":["../../../../src/injectors/components/useGraph.ts"],"names":[],"mappings":";;;;;AAAA,iCAA4C;AAG5C,uFAA+D;AAC/D,8EAAsD;AAEtD,kBAAe,CAAI,KAAiC,EAAE,MAAW,EAAE,KAAkB,EAAE,EAAE;IACvF,MAAM,CAAC,KAAK,CAAC,GAAG,IAAA,gBAAQ,EAAC,GAAG,EAAE;QAC5B,MAAM,aAAa,GAAG,uBAAa,CAAC,OAAO,CAAC,KAAK,EAAE,gBAAgB,EAAE,KAAK,CAAC,CAAC;QAC5E,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAC7B,OAAO,aAAa,CAAC;IACvB,CAAC,CAAC,CAAC;IACH,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,0BAAgB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC/B,OAAO,GAAG,EAAE,CAAC,0BAAgB,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,uBAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9E,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IACZ,OAAO,KAAK,CAAC;AACf,CAAC,CAAC"}
|
|
@@ -6,7 +6,7 @@ export declare class Observable<T> implements IObservable<T> {
|
|
|
6
6
|
get value(): T;
|
|
7
7
|
set value(value: T);
|
|
8
8
|
first(): Promise<T>;
|
|
9
|
-
subscribe(onNext
|
|
9
|
+
subscribe(onNext: OnNext<T>): Unsubscribe;
|
|
10
10
|
unsubscribe(onNext: OnNext<T>): void;
|
|
11
11
|
}
|
|
12
12
|
//# sourceMappingURL=Observable.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Observable.d.ts","sourceRoot":"","sources":["../../../src/observable/Observable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,IAAI,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"Observable.d.ts","sourceRoot":"","sources":["../../../src/observable/Observable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,IAAI,WAAW,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEzE,qBAAa,UAAU,CAAC,CAAC,CAAE,YAAW,WAAW,CAAC,CAAC,CAAC;IAClD,OAAO,CAAC,WAAW,CAA6B;IAChD,OAAO,CAAC,YAAY,CAAgB;gBAExB,YAAY,CAAC,EAAE,CAAC;IAI5B,IAAW,KAAK,IAAI,CAAC,CAEpB;IAED,IAAW,KAAK,CAAC,KAAK,EAAE,CAAC,EAGxB;IAEK,KAAK,IAAI,OAAO,CAAC,CAAC,CAAC;IAUlB,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,WAAW;IAQzC,WAAW,CAAC,MAAM,EAAC,MAAM,CAAC,CAAC,CAAC;CAMpC"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Observable = void 0;
|
|
4
|
-
const NOOP = () => { };
|
|
5
4
|
class Observable {
|
|
6
5
|
constructor(initialValue) {
|
|
7
6
|
this.subscribers = new Set();
|
|
@@ -24,7 +23,7 @@ class Observable {
|
|
|
24
23
|
});
|
|
25
24
|
});
|
|
26
25
|
}
|
|
27
|
-
subscribe(onNext
|
|
26
|
+
subscribe(onNext) {
|
|
28
27
|
if (this.subscribers.has(onNext)) {
|
|
29
28
|
throw new Error('Subscriber already subscribed');
|
|
30
29
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Observable.js","sourceRoot":"","sources":["../../../src/observable/Observable.ts"],"names":[],"mappings":";;;AAEA,
|
|
1
|
+
{"version":3,"file":"Observable.js","sourceRoot":"","sources":["../../../src/observable/Observable.ts"],"names":[],"mappings":";;;AAEA,MAAa,UAAU;IAIrB,YAAY,YAAgB;QAHpB,gBAAW,GAAmB,IAAI,GAAG,EAAE,CAAC;QAI9C,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;IAED,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,YAAiB,CAAC;IAChC,CAAC;IAED,IAAW,KAAK,CAAC,KAAQ;QACvB,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;QAC1B,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;IAC9D,CAAC;IAED,KAAK,CAAC,KAAK;QACT,IAAI,IAAI,CAAC,YAAY;YAAE,OAAO,IAAI,CAAC,YAAY,CAAC;QAChD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC7B,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE;gBAC3C,WAAW,EAAE,CAAC;gBACd,OAAO,CAAC,KAAK,CAAC,CAAC;YACjB,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAEM,SAAS,CAAC,MAAiB;QAChC,IAAI,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE;YAChC,MAAM,IAAI,KAAK,CAAC,+BAA+B,CAAC,CAAC;SAClD;QACD,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAC7B,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC/C,CAAC;IAEM,WAAW,CAAC,MAAgB;QACjC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE;YACjC,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;SAChE;QACD,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC;CACF;AAzCD,gCAyCC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useObservers.d.ts","sourceRoot":"","sources":["../../../src/observable/useObservers.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,
|
|
1
|
+
{"version":3,"file":"useObservers.d.ts","sourceRoot":"","sources":["../../../src/observable/useObservers.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAe,MAAM,SAAS,CAAC;AAGtD,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,WAAW,EAAE,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAoB7F"}
|
|
@@ -8,12 +8,15 @@ function useObservers(observables) {
|
|
|
8
8
|
const [values, setValues] = (0, react_1.useState)(() => (0, mapObservablesToValues_1.mapObservablesToValues)(observables));
|
|
9
9
|
(0, react_1.useEffect)(() => {
|
|
10
10
|
const mediator = new MediatorObservable_1.MediatorObservable();
|
|
11
|
+
const unsubscribers = [];
|
|
11
12
|
Object.keys(observables).forEach((key) => {
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
const onNext = (value) => setValues({ ...values, [key]: value });
|
|
14
|
+
mediator.addSource(observables[key], onNext);
|
|
15
|
+
unsubscribers.push(() => {
|
|
16
|
+
observables[key].unsubscribe(onNext);
|
|
14
17
|
});
|
|
15
18
|
});
|
|
16
|
-
return
|
|
19
|
+
return () => unsubscribers.forEach((unsubscribe) => unsubscribe());
|
|
17
20
|
}, []);
|
|
18
21
|
return values;
|
|
19
22
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useObservers.js","sourceRoot":"","sources":["../../../src/observable/useObservers.ts"],"names":[],"mappings":";;;AAAA,iCAA4C;AAC5C,sEAAmE;AAEnE,qEAAkE;AAElE,SAAgB,YAAY,CAAgC,WAAc;IACxE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,IAAA,gBAAQ,EAAC,GAAG,EAAE,CAAC,IAAA,+CAAsB,EAAC,WAAW,CAAC,CAAC,CAAC;IAEhF,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,MAAM,QAAQ,GAAG,IAAI,uCAAkB,EAAE,CAAC;QAC1C,MAAM,CAAC,IAAI,CAAC,WAAiB,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YAC7C,
|
|
1
|
+
{"version":3,"file":"useObservers.js","sourceRoot":"","sources":["../../../src/observable/useObservers.ts"],"names":[],"mappings":";;;AAAA,iCAA4C;AAC5C,sEAAmE;AAEnE,qEAAkE;AAElE,SAAgB,YAAY,CAAgC,WAAc;IACxE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,IAAA,gBAAQ,EAAC,GAAG,EAAE,CAAC,IAAA,+CAAsB,EAAC,WAAW,CAAC,CAAC,CAAC;IAEhF,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,MAAM,QAAQ,GAAG,IAAI,uCAAkB,EAAE,CAAC;QAC1C,MAAM,aAAa,GAAkB,EAAE,CAAC;QAExC,MAAM,CAAC,IAAI,CAAC,WAAiB,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;YAC7C,MAAM,MAAM,GAAG,CAAC,KAAU,EAAE,EAAE,CAAC,SAAS,CAAC,EAAE,GAAG,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;YACtE,QAAQ,CAAC,SAAS,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CAAC;YAE7C,aAAa,CAAC,IAAI,CAAC,GAAG,EAAE;gBACtB,WAAW,CAAC,GAAG,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;YACvC,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,OAAO,GAAG,EAAE,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;IACrE,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,MAAM,CAAC;AAChB,CAAC;AApBD,oCAoBC"}
|
package/dist/src/utils/isDev.js
CHANGED
|
@@ -7,6 +7,7 @@ function isDev() {
|
|
|
7
7
|
exports.isDev = isDev;
|
|
8
8
|
function isNodeDev() {
|
|
9
9
|
var _a;
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/dot-notation
|
|
10
11
|
return ['test', 'development'].includes((_a = process.env['NODE_ENV']) !== null && _a !== void 0 ? _a : '');
|
|
11
12
|
}
|
|
12
13
|
function isReactNativeDev() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isDev.js","sourceRoot":"","sources":["../../../src/utils/isDev.ts"],"names":[],"mappings":";;;AAAA,SAAgB,KAAK;IACnB,OAAO,SAAS,EAAE,IAAI,gBAAgB,EAAE,CAAC;AAC3C,CAAC;AAFD,sBAEC;AAED,SAAS,SAAS;;IAChB,OAAO,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,QAAQ,CAAC,MAAA,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,mCAAI,EAAE,CAAC,CAAC;AACzE,CAAC;AAED,SAAS,gBAAgB;;IACvB,aAAa;IACb,OAAO,MAAA,OAAkB,mCAAI,KAAK,CAAC;AACrC,CAAC"}
|
|
1
|
+
{"version":3,"file":"isDev.js","sourceRoot":"","sources":["../../../src/utils/isDev.ts"],"names":[],"mappings":";;;AAAA,SAAgB,KAAK;IACnB,OAAO,SAAS,EAAE,IAAI,gBAAgB,EAAE,CAAC;AAC3C,CAAC;AAFD,sBAEC;AAED,SAAS,SAAS;;IAChB,2DAA2D;IAC3D,OAAO,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,QAAQ,CAAC,MAAA,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,mCAAI,EAAE,CAAC,CAAC;AACzE,CAAC;AAED,SAAS,gBAAgB;;IACvB,aAAa;IACb,OAAO,MAAA,OAAkB,mCAAI,KAAK,CAAC;AACrC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../transformers/babel-plugin-obsidian/helpers/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,WAAW,EACX,aAAa,EACb,SAAS,EACT,UAAU,EACV,gBAAgB,EAChB,aAAa,EACb,mBAAmB,EACpB,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../transformers/babel-plugin-obsidian/helpers/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,WAAW,EACX,aAAa,EACb,SAAS,EACT,UAAU,EACV,gBAAgB,EAChB,aAAa,EACb,mBAAmB,EACpB,MAAM,cAAc,CAAC;AAItB,MAAM,MAAM,gBAAgB,GAAG,UAAU,GAAG,mBAAmB,GAAG,aAAa,CAAC;AAEhF,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAWhE;AAED,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,QAOjF;AAED,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,SAAS,GAAG,gBAAgB,GAAG,SAAS,CAKvF;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,WAAW,GAAG,MAAM,CAGvD;AAED,wBAAgB,kBAAkB,CAChC,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC,GAAG,SAAS,GAAG,IAAI,EAC/C,aAAa,EAAE,MAAM,GACpB,SAAS,GAAG,SAAS,CAEvB;AAED,wBAAgB,gBAAgB,CAAC,SAAS,CAAC,EAAE,SAAS,GAAG,MAAM,GAAG,SAAS,CAE1E;AAED,wBAAgB,+BAA+B,CAAC,MAAM,EAAE,CAAC,UAAU,GAAG,GAAG,CAAC,EAAE,GAAG,aAAa,CAI3F;AAED,wBAAgB,6BAA6B,CAC3C,IAAI,EAAE,gBAAgB,EACtB,SAAS,EAAE,SAAS,QAOrB"}
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.passParamNameAsInjectArgument = exports.paramsToDestructuringAssignment = exports.getDecoratorName = exports.getDecoratorByName = exports.getMethodName = exports.getDecoratorArgument = exports.addNameToProviderArguments = exports.providerIsNotNamed = void 0;
|
|
4
4
|
/* eslint-disable no-param-reassign */
|
|
5
5
|
const core_1 = require("@babel/core");
|
|
6
|
-
const lodash_1 = require("lodash");
|
|
7
6
|
const never = '';
|
|
8
7
|
function providerIsNotNamed(decorator) {
|
|
9
8
|
const argument = getDecoratorArgument(decorator);
|
|
@@ -39,11 +38,11 @@ function getMethodName(node) {
|
|
|
39
38
|
}
|
|
40
39
|
exports.getMethodName = getMethodName;
|
|
41
40
|
function getDecoratorByName(decorators, decoratorName) {
|
|
42
|
-
return decorators === null || decorators === void 0 ? void 0 : decorators.find((decorator) =>
|
|
41
|
+
return decorators === null || decorators === void 0 ? void 0 : decorators.find((decorator) => get(decorator, 'expression.callee.name') === decoratorName);
|
|
43
42
|
}
|
|
44
43
|
exports.getDecoratorByName = getDecoratorByName;
|
|
45
44
|
function getDecoratorName(decorator) {
|
|
46
|
-
return
|
|
45
|
+
return get(decorator, 'expression.callee.name');
|
|
47
46
|
}
|
|
48
47
|
exports.getDecoratorName = getDecoratorName;
|
|
49
48
|
function paramsToDestructuringAssignment(params) {
|
|
@@ -75,4 +74,12 @@ function getNodeName(node) {
|
|
|
75
74
|
}
|
|
76
75
|
return node.name;
|
|
77
76
|
}
|
|
77
|
+
function get(node, path) {
|
|
78
|
+
if (node === undefined || node === null)
|
|
79
|
+
return undefined;
|
|
80
|
+
const [key, ...rest] = path.split('.');
|
|
81
|
+
if (rest.length === 0)
|
|
82
|
+
return node[key];
|
|
83
|
+
return get(node[key], rest.join('.'));
|
|
84
|
+
}
|
|
78
85
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../transformers/babel-plugin-obsidian/helpers/index.ts"],"names":[],"mappings":";;;AAAA,sCAAsC;AACtC,sCAAyC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../transformers/babel-plugin-obsidian/helpers/index.ts"],"names":[],"mappings":";;;AAAA,sCAAsC;AACtC,sCAAyC;AAYzC,MAAM,KAAK,GAAG,EAAE,CAAC;AAIjB,SAAgB,kBAAkB,CAAC,SAAoB;IACrD,MAAM,QAAQ,GAAG,oBAAoB,CAAC,SAAS,CAA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BAAqB,CAAC,IAAI,CAAC,EAAE;QACjC,IAAI,YAAC,CAAC,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE;YAClC,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;SAC5B;QACD,OAAO,KAAK,CAAC;KACd;IACD,IAAI,YAAC,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE;QAC3B,IAAI,YAAC,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;YAC5B,OAAO,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC;SACtB;QACD,OAAO,KAAK,CAAC;KACd;IACD,OAAO,IAAI,CAAC,IAAI,CAAC;AACnB,CAAC;AAED,SAAS,GAAG,CAAC,IAAS,EAAE,IAAY;IAClC,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,IAAI;QAAE,OAAO,SAAS,CAAC;IAC1D,MAAM,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACvC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;IACxC,OAAO,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AACxC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-obsidian",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
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",
|
|
@@ -29,7 +29,6 @@
|
|
|
29
29
|
"@babel/types": "7.22.x",
|
|
30
30
|
"@johanblumenberg/ts-mockito": "1.x.x",
|
|
31
31
|
"@testing-library/react": "14.x.x",
|
|
32
|
-
"@testing-library/react-hooks": "^7.0.2",
|
|
33
32
|
"@types/hoist-non-react-statics": "^3.3.1",
|
|
34
33
|
"@types/jest": "29.5.x",
|
|
35
34
|
"@types/lodash": "^4.14.176",
|
|
@@ -4,7 +4,7 @@ import graphRegistry from './registry/GraphRegistry';
|
|
|
4
4
|
|
|
5
5
|
export default class ServiceLocatorFactory {
|
|
6
6
|
static fromGraph<T extends ObjectGraph<P>, P = any>(Graph: Constructable<T>, props?: P) {
|
|
7
|
-
const resolved = graphRegistry.resolve(Graph, props);
|
|
7
|
+
const resolved = graphRegistry.resolve(Graph, 'serviceLocator', props);
|
|
8
8
|
const wrapped = new Proxy(resolved, {
|
|
9
9
|
get(_target: any, property: string, receiver: any) {
|
|
10
10
|
return () => resolved.retrieve(property, receiver);
|
|
@@ -2,7 +2,7 @@ import { Constructable } from '../../types';
|
|
|
2
2
|
import { Graph } from '../Graph';
|
|
3
3
|
import { Middleware } from './Middleware';
|
|
4
4
|
import GraphMiddlewareChain from './GraphMiddlewareChain';
|
|
5
|
-
import {
|
|
5
|
+
import { ObtainLifecycleBoundGraphException } from './ObtainLifecycleBoundGraphException';
|
|
6
6
|
|
|
7
7
|
export class GraphRegistry {
|
|
8
8
|
private readonly constructorToInstance = new Map<Constructable<Graph>, Set<Graph>>();
|
|
@@ -30,22 +30,22 @@ export class GraphRegistry {
|
|
|
30
30
|
return this.nameToInstance.get(name)!;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
resolve<T extends Graph>(
|
|
33
|
+
resolve<T extends Graph>(
|
|
34
|
+
Graph: Constructable<T>,
|
|
35
|
+
source: 'lifecycleOwner' | 'serviceLocator' = 'lifecycleOwner',
|
|
36
|
+
props: any = undefined,
|
|
37
|
+
): T {
|
|
34
38
|
if ((this.isSingleton(Graph) || this.isBoundToReactLifecycle(Graph)) && this.has(Graph)) {
|
|
35
39
|
return this.getFirst(Graph);
|
|
36
40
|
}
|
|
37
|
-
|
|
41
|
+
if (this.isBoundToReactLifecycle(Graph) && source === 'serviceLocator') {
|
|
42
|
+
throw new ObtainLifecycleBoundGraphException(Graph);
|
|
43
|
+
}
|
|
44
|
+
const graph = this.graphMiddlewares.resolve(Graph, props);
|
|
38
45
|
this.set(Graph, graph);
|
|
39
46
|
return graph as T;
|
|
40
47
|
}
|
|
41
48
|
|
|
42
|
-
private ensurePropsIfLifecycleBoundGraph<T extends Graph>(Graph: Constructable<T>, props?: any): any {
|
|
43
|
-
if (this.isBoundToReactLifecycle(Graph)) {
|
|
44
|
-
return props ?? createNullProps(Graph);
|
|
45
|
-
}
|
|
46
|
-
return props;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
49
|
private has(Graph: Constructable<Graph>): boolean {
|
|
50
50
|
return (this.constructorToInstance.get(Graph)?.size ?? 0) > 0;
|
|
51
51
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { isDev } from '../../utils/isDev';
|
|
2
|
+
import { Constructable } from '../../types';
|
|
3
|
+
import { Graph } from '../Graph';
|
|
4
|
+
|
|
5
|
+
export class ObtainLifecycleBoundGraphException extends Error {
|
|
6
|
+
constructor(graph: Constructable<Graph>) {
|
|
7
|
+
super(ObtainLifecycleBoundGraphException.createMessage(graph));
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
private static createMessage(graph: Constructable<Graph>): string {
|
|
11
|
+
const graphName = isDev() ? ` ${graph.name}` : '';
|
|
12
|
+
return `Tried to obtain a @LifecycleBound graph${graphName}, but it was not created yet. `
|
|
13
|
+
+ '@LifecycleBound graphs can only be obtained after they were created by a React component or hook.';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -3,6 +3,7 @@ import { GraphRegistry } from '../../graph/registry/GraphRegistry';
|
|
|
3
3
|
import { Graph } from '../../graph/Graph';
|
|
4
4
|
import InjectionMetadata from './InjectionMetadata';
|
|
5
5
|
import { GRAPH_INSTANCE_NAME_KEY } from './LateInjector';
|
|
6
|
+
import referenceCounter from '../../ReferenceCounter';
|
|
6
7
|
|
|
7
8
|
export default class ClassInjector {
|
|
8
9
|
constructor(
|
|
@@ -23,12 +24,18 @@ export default class ClassInjector {
|
|
|
23
24
|
): ProxyHandler<any> {
|
|
24
25
|
return new class Handler implements ProxyHandler<any> {
|
|
25
26
|
construct(target: any, args: any[], newTarget: Function): any {
|
|
26
|
-
const graph = graphRegistry.resolve(Graph, args.length > 0 ? args[0] : undefined);
|
|
27
|
+
const graph = graphRegistry.resolve(Graph, 'lifecycleOwner', args.length > 0 ? args[0] : undefined);
|
|
28
|
+
referenceCounter.retain(graph);
|
|
27
29
|
Reflect.defineMetadata(GRAPH_INSTANCE_NAME_KEY, graph.name, target);
|
|
28
30
|
const argsToInject = this.injectConstructorArgs(args, graph, target);
|
|
29
31
|
graph.onBind(target);
|
|
30
32
|
const createdObject = Reflect.construct(target, argsToInject, newTarget);
|
|
31
33
|
this.injectProperties(target, createdObject, graph);
|
|
34
|
+
const originalComponentWillUnmount = createdObject.componentWillUnmount;
|
|
35
|
+
createdObject.componentWillUnmount = () => {
|
|
36
|
+
originalComponentWillUnmount?.();
|
|
37
|
+
referenceCounter.release(graph, (g) => graphRegistry.clear(g));
|
|
38
|
+
};
|
|
32
39
|
return createdObject;
|
|
33
40
|
}
|
|
34
41
|
|
|
@@ -6,9 +6,9 @@ import referenceCounter from '../../ReferenceCounter';
|
|
|
6
6
|
|
|
7
7
|
export default <P>(Graph: Constructable<ObjectGraph>, target: any, props?: Partial<P>) => {
|
|
8
8
|
const [graph] = useState(() => {
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
return
|
|
9
|
+
const resolvedGraph = graphRegistry.resolve(Graph, 'lifecycleOwner', props);
|
|
10
|
+
resolvedGraph.onBind(target);
|
|
11
|
+
return resolvedGraph;
|
|
12
12
|
});
|
|
13
13
|
useEffect(() => {
|
|
14
14
|
referenceCounter.retain(graph);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Observable as IObservable, OnNext, Unsubscribe } from './types';
|
|
2
2
|
|
|
3
|
-
const NOOP = () => {};
|
|
4
3
|
export class Observable<T> implements IObservable<T> {
|
|
5
4
|
private subscribers: Set<OnNext<T>> = new Set();
|
|
6
5
|
private currentValue: T | undefined;
|
|
@@ -28,7 +27,7 @@ export class Observable<T> implements IObservable<T> {
|
|
|
28
27
|
});
|
|
29
28
|
}
|
|
30
29
|
|
|
31
|
-
public subscribe(onNext: OnNext<T>
|
|
30
|
+
public subscribe(onNext: OnNext<T>): Unsubscribe {
|
|
32
31
|
if (this.subscribers.has(onNext)) {
|
|
33
32
|
throw new Error('Subscriber already subscribed');
|
|
34
33
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
2
|
import { MediatorObservable } from './mediator/MediatorObservable';
|
|
3
|
-
import { ObservedValues } from './types';
|
|
3
|
+
import { ObservedValues, Unsubscribe } from './types';
|
|
4
4
|
import { mapObservablesToValues } from './mapObservablesToValues';
|
|
5
5
|
|
|
6
6
|
export function useObservers<T extends Record<string, any>>(observables: T): ObservedValues<T> {
|
|
@@ -8,13 +8,18 @@ export function useObservers<T extends Record<string, any>>(observables: T): Obs
|
|
|
8
8
|
|
|
9
9
|
useEffect(() => {
|
|
10
10
|
const mediator = new MediatorObservable();
|
|
11
|
+
const unsubscribers: Unsubscribe[] = [];
|
|
12
|
+
|
|
11
13
|
Object.keys(observables as {}).forEach((key) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
+
const onNext = (value: any) => setValues({ ...values, [key]: value });
|
|
15
|
+
mediator.addSource(observables[key], onNext);
|
|
16
|
+
|
|
17
|
+
unsubscribers.push(() => {
|
|
18
|
+
observables[key].unsubscribe(onNext);
|
|
14
19
|
});
|
|
15
20
|
});
|
|
16
21
|
|
|
17
|
-
return
|
|
22
|
+
return () => unsubscribers.forEach((unsubscribe) => unsubscribe());
|
|
18
23
|
}, []);
|
|
19
24
|
|
|
20
25
|
return values;
|
package/src/utils/isDev.ts
CHANGED
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
ObjectPattern,
|
|
11
11
|
TSParameterProperty,
|
|
12
12
|
} from '@babel/types';
|
|
13
|
-
import { get } from 'lodash';
|
|
14
13
|
|
|
15
14
|
const never = '';
|
|
16
15
|
|
|
@@ -93,3 +92,10 @@ function getNodeName(node: AcceptedNodeType): string {
|
|
|
93
92
|
}
|
|
94
93
|
return node.name;
|
|
95
94
|
}
|
|
95
|
+
|
|
96
|
+
function get(node: any, path: string): any {
|
|
97
|
+
if (node === undefined || node === null) return undefined;
|
|
98
|
+
const [key, ...rest] = path.split('.');
|
|
99
|
+
if (rest.length === 0) return node[key];
|
|
100
|
+
return get(node[key], rest.join('.'));
|
|
101
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NullProps.d.ts","sourceRoot":"","sources":["../../../../src/graph/registry/NullProps.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEtC,wBAAgB,SAAS,CAAC,KAAK,EAAE,aAAa,CAAC,KAAK,CAAC,MAEpD"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NullProps = void 0;
|
|
4
|
-
const isDev_1 = require("../../utils/isDev");
|
|
5
|
-
function NullProps(Graph) {
|
|
6
|
-
return new Proxy({}, new NullPropsProxyHandler(Graph));
|
|
7
|
-
}
|
|
8
|
-
exports.NullProps = NullProps;
|
|
9
|
-
class NullPropsProxyHandler {
|
|
10
|
-
constructor(graph) {
|
|
11
|
-
this.graph = graph;
|
|
12
|
-
}
|
|
13
|
-
get(target, property, receiver) {
|
|
14
|
-
if (property in target)
|
|
15
|
-
return Reflect.get(target, property, receiver);
|
|
16
|
-
throw new Error(this.createErrorMessage(this.graph, property));
|
|
17
|
-
}
|
|
18
|
-
createErrorMessage(graph, property) {
|
|
19
|
-
const graphName = (0, isDev_1.isDev)() ? graph.name : '';
|
|
20
|
-
return `Tried to get prop ${property} in a @LifecycleBound graph ${graphName}, but props were undefined. `
|
|
21
|
-
+ `If you're using Obsidian.obtain(${graphName}) - then you should pass props to it explicitly: `
|
|
22
|
-
+ `Obsidian.obtain(${graphName}, { ${property}: 'value' });`;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
//# sourceMappingURL=NullProps.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NullProps.js","sourceRoot":"","sources":["../../../../src/graph/registry/NullProps.ts"],"names":[],"mappings":";;;AACA,6CAA0C;AAG1C,SAAgB,SAAS,CAAC,KAA2B;IACnD,OAAO,IAAI,KAAK,CAAC,EAAE,EAAE,IAAI,qBAAqB,CAAC,KAAK,CAAC,CAAC,CAAC;AACzD,CAAC;AAFD,8BAEC;AAED,MAAM,qBAAqB;IACzB,YAAoB,KAA2B;QAA3B,UAAK,GAAL,KAAK,CAAsB;IAAG,CAAC;IAEnD,GAAG,CAAC,MAAc,EAAE,QAAgB,EAAE,QAAa;QACjD,IAAI,QAAQ,IAAI,MAAM;YAAE,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;QACvE,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC;IACjE,CAAC;IAEO,kBAAkB,CAAC,KAA2B,EAAE,QAAgB;QACtE,MAAM,SAAS,GAAG,IAAA,aAAK,GAAE,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5C,OAAO,qBAAqB,QAAQ,+BAA+B,SAAS,8BAA8B;cACxG,mCAAmC,SAAS,mDAAmD;cAC/F,mBAAmB,SAAS,OAAO,QAAQ,eAAe,CAAC;IAC/D,CAAC;CACF"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { Constructable } from '../../types';
|
|
2
|
-
import { isDev } from '../../utils/isDev';
|
|
3
|
-
import type { Graph } from '../Graph';
|
|
4
|
-
|
|
5
|
-
export function NullProps(Graph: Constructable<Graph>) {
|
|
6
|
-
return new Proxy({}, new NullPropsProxyHandler(Graph));
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
class NullPropsProxyHandler implements ProxyHandler<{}> {
|
|
10
|
-
constructor(private graph: Constructable<Graph>) {}
|
|
11
|
-
|
|
12
|
-
get(target: object, property: string, receiver: any) {
|
|
13
|
-
if (property in target) return Reflect.get(target, property, receiver);
|
|
14
|
-
throw new Error(this.createErrorMessage(this.graph, property));
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
private createErrorMessage(graph: Constructable<Graph>, property: string) {
|
|
18
|
-
const graphName = isDev() ? graph.name : '';
|
|
19
|
-
return `Tried to get prop ${property} in a @LifecycleBound graph ${graphName}, but props were undefined. `
|
|
20
|
-
+ `If you're using Obsidian.obtain(${graphName}) - then you should pass props to it explicitly: `
|
|
21
|
-
+ `Obsidian.obtain(${graphName}, { ${property}: 'value' });`;
|
|
22
|
-
}
|
|
23
|
-
}
|