react-obsidian 0.0.30 → 0.0.31

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 CHANGED
@@ -18,23 +18,24 @@ React Obsidian is guided by the principles of the Dependency Injection pattern,
18
18
  > 📖 Read more about Dependency Injection and Obsidian in [Breaking complexity with Dependency Injection: Introducing Obsidian](https://guyca.medium.com/breaking-complexity-with-dependency-injection-introducing-obsidian-cd452802f076) on Medium.
19
19
 
20
20
 
21
- * [Installation](https://github.com/wix-incubator/react-obsidian#installation)
22
- * [Prerequisites](https://github.com/wix-incubator/react-obsidian#prerequisites)
23
- * [Usage](https://github.com/wix-incubator/react-obsidian#usage)
24
- * [Declare an object graph](https://github.com/wix-incubator/react-obsidian#declare-an-object-graph)
25
- * [Component injection](https://github.com/wix-incubator/react-obsidian#component-injection)
26
- * [Hooks injection](https://github.com/wix-incubator/react-obsidian#hooks-injection)
27
- * [Class injection](https://github.com/wix-incubator/react-obsidian#class-injection)
28
- * [Injecting properties](https://github.com/wix-incubator/react-obsidian#injecting-properties)
29
- * [Injecting constructor arguments](https://github.com/wix-incubator/react-obsidian#injecting-constructor-arguments)
30
- * [Obtaining dependencies from a graph](https://github.com/wix-incubator/react-obsidian#obtaining-dependencies-from-a-graph)
31
- * [Advance usage](https://github.com/wix-incubator/react-obsidian#advance-usage)
32
- * [Accessing props in graphs](https://github.com/wix-incubator/react-obsidian#accessing-props-in-graphs)
33
- * [Singleton graphs and providers](https://github.com/wix-incubator/react-obsidian#singleton-graphs-and-providers)
34
- * [Lazy property injection](https://github.com/wix-incubator/react-obsidian#lazy-property-injection)
35
- * [Typing graphs](https://github.com/wix-incubator/react-obsidian#typing-graphs)
36
- * [Graph middleware](https://github.com/wix-incubator/react-obsidian#graph-middleware)
37
- * [Clearing graphs](https://github.com/wix-incubator/react-obsidian#clearing-graphs)
21
+ * [Installation](https://github.com/wix-incubator/obsidian#installation)
22
+ * [Prerequisites](https://github.com/wix-incubator/obsidian#prerequisites)
23
+ * [Usage](https://github.com/wix-incubator/obsidian#usage)
24
+ * [Declare an object graph](https://github.com/wix-incubator/obsidian#declare-an-object-graph)
25
+ * [Component injection](https://github.com/wix-incubator/obsidian#component-injection)
26
+ * [Hooks injection](https://github.com/wix-incubator/obsidian#hooks-injection)
27
+ * [Class injection](https://github.com/wix-incubator/obsidian#class-injection)
28
+ * [Injecting properties](https://github.com/wix-incubator/obsidian#injecting-properties)
29
+ * [Injecting constructor arguments](https://github.com/wix-incubator/obsidian#injecting-constructor-arguments)
30
+ * [Obtaining dependencies from a graph](https://github.com/wix-incubator/obsidian#obtaining-dependencies-from-a-graph)
31
+ * [Advance usage](https://github.com/wix-incubator/obsidian#advance-usage)
32
+ * [Accessing props in graphs](https://github.com/wix-incubator/obsidian#accessing-props-in-graphs)
33
+ * [Singleton graphs and providers](https://github.com/wix-incubator/obsidian#singleton-graphs-and-providers)
34
+ * [React lifecycle-bound graphs](https://github.com/wix-incubator/obsidian#react-lifecycle-bound-graphs)
35
+ * [Lazy property injection](https://github.com/wix-incubator/obsidian#lazy-property-injection)
36
+ * [Typing graphs](https://github.com/wix-incubator/obsidian#typing-graphs)
37
+ * [Graph middleware](https://github.com/wix-incubator/obsidian#graph-middleware)
38
+ * [Clearing graphs](https://github.com/wix-incubator/obsidian#clearing-graphs)
38
39
 
39
40
 
40
41
 
@@ -223,6 +224,17 @@ class ApplicationGraph {
223
224
  }
224
225
  ```
225
226
 
227
+ ### React lifecycle-bound graphs
228
+ Graphs can be linked to the lifecycle of React components (and hooks) that require them. `@LifecycleBound` graphs are effectively singletons within the lifespan of the React components and hooks that were injected by the graph. Once all of the React component and hooks that were injected by the `@LifecycleBound` graph are unmounted - the graph is deallocated.
229
+
230
+ This is mostly useful when a graph is shared between multiple screens that either share the same root screen or are all part of the same flow.
231
+
232
+ ```typescript
233
+ @LifecycleBound() @Graph()
234
+ class HomeGraph {
235
+ }
236
+ ```
237
+
226
238
  ### Lazy property injection
227
239
  Class properties can be injected lazily by using the `@LazyInject()` decorator. This is useful when the injection should be done in a lifecycle method instead of in the class constructor.
228
240
 
@@ -0,0 +1,2 @@
1
+ export declare function LifecycleBound(): (constructor: any) => any;
2
+ //# sourceMappingURL=LifecycleBound.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LifecycleBound.d.ts","sourceRoot":"","sources":["../../../src/decorators/LifecycleBound.ts"],"names":[],"mappings":"AAAA,wBAAgB,cAAc,kBACP,GAAG,SAIzB"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LifecycleBound = void 0;
4
+ function LifecycleBound() {
5
+ return function (constructor) {
6
+ Reflect.defineMetadata('isLifecycleBound', true, constructor);
7
+ return constructor;
8
+ };
9
+ }
10
+ exports.LifecycleBound = LifecycleBound;
11
+ //# sourceMappingURL=LifecycleBound.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LifecycleBound.js","sourceRoot":"","sources":["../../../src/decorators/LifecycleBound.ts"],"names":[],"mappings":";;;AAAA,SAAgB,cAAc;IAC5B,OAAO,UAAC,WAAgB;QACtB,OAAO,CAAC,cAAc,CAAC,kBAAkB,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;QAC9D,OAAO,WAAW,CAAC;IACrB,CAAC,CAAC;AACJ,CAAC;AALD,wCAKC"}
@@ -16,6 +16,7 @@ export declare class GraphRegistry {
16
16
  private getFirst;
17
17
  private set;
18
18
  private isSingleton;
19
+ private isBoundToReactLifecycle;
19
20
  clear(graph: Graph): void;
20
21
  addGraphMiddleware(middleware: Middleware<Graph>): void;
21
22
  clearGraphMiddlewares(): void;
@@ -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,C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rF,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,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,GAAG,GAAG,CAAC;IASjE,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"}
@@ -33,7 +33,7 @@ var GraphRegistry = /** @class */ (function () {
33
33
  return this.nameToInstance.get(name);
34
34
  };
35
35
  GraphRegistry.prototype.resolve = function (Graph, props) {
36
- if (this.isSingleton(Graph) && this.has(Graph)) {
36
+ if ((this.isSingleton(Graph) || this.isBoundToReactLifecycle(Graph)) && this.has(Graph)) {
37
37
  return this.getFirst(Graph);
38
38
  }
39
39
  var graph = this.graphMiddlewares.resolve(Graph, props);
@@ -41,7 +41,8 @@ var GraphRegistry = /** @class */ (function () {
41
41
  return graph;
42
42
  };
43
43
  GraphRegistry.prototype.has = function (Graph) {
44
- return this.constructorToInstance.has(Graph);
44
+ var _a, _b;
45
+ return ((_b = (_a = this.constructorToInstance.get(Graph)) === null || _a === void 0 ? void 0 : _a.size) !== null && _b !== void 0 ? _b : 0) > 0;
45
46
  };
46
47
  GraphRegistry.prototype.getFirst = function (Graph) {
47
48
  return this.constructorToInstance.get(Graph).values().next().value;
@@ -58,6 +59,10 @@ var GraphRegistry = /** @class */ (function () {
58
59
  var _a;
59
60
  return (_a = Reflect.getMetadata('isSingleton', Graph)) !== null && _a !== void 0 ? _a : false;
60
61
  };
62
+ GraphRegistry.prototype.isBoundToReactLifecycle = function (Graph) {
63
+ var _a;
64
+ return (_a = Reflect.getMetadata('isLifecycleBound', Graph)) !== null && _a !== void 0 ? _a : false;
65
+ };
61
66
  GraphRegistry.prototype.clear = function (graph) {
62
67
  var Graph = this.instanceToConstructor.get(graph);
63
68
  if (this.isSingleton(Graph))
@@ -1 +1 @@
1
- {"version":3,"file":"GraphRegistry.js","sourceRoot":"","sources":["../../../../src/graph/registry/GraphRegistry.ts"],"names":[],"mappings":";;;;;;AAGA,gFAA0D;AAE1D;IAAA;QACmB,0BAAqB,GAAG,IAAI,GAAG,EAAoC,CAAC;QACpE,0BAAqB,GAAG,IAAI,GAAG,EAA+B,CAAC;QAC/D,mBAAc,GAAG,IAAI,GAAG,EAAiB,CAAC;QAC1C,qBAAgB,GAAG,IAAI,GAAG,EAAmD,CAAC;QAC9E,qBAAgB,GAAG,IAAI,8BAAoB,EAAE,CAAC;IAuEjE,CAAC;IArEC,gCAAQ,GAAR,UAAS,WAAiC,EAAE,SAAsC;QAAtC,0BAAA,EAAA,cAAsC;QAChF,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC;IAC7D,CAAC;IAED,wCAAgB,GAAhB,UAAiB,KAAY;QAC3B,IAAI,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,KAAK,CAAC;YAAE,OAAO;QAClD,IAAI,CAAC,GAAG,CA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K,EAAE,CAAC;QACnC,IAAI,CAAC,qBAAqB,CAAC,KAAK,EAAE,CAAC;QACnC,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC;IAC9B,CAAC;IACH,oBAAC;AAAD,CAAC,AAhFD,IAgFC;AAhFY,sCAAa;AAkF1B,kBAAe,IAAI,aAAa,EAAE,CAAC"}
@@ -0,0 +1,6 @@
1
+ import { ObjectGraph } from '../../src';
2
+ export declare class LifecycleBoundGraph extends ObjectGraph {
3
+ static timesCreated: number;
4
+ constructor();
5
+ }
6
+ //# sourceMappingURL=LifecycleBoundGraph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LifecycleBoundGraph.d.ts","sourceRoot":"","sources":["../../../test/fixtures/LifecycleBoundGraph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,WAAW,EAAE,MAAM,WAAW,CAAC;AAG/C,qBACa,mBAAoB,SAAQ,WAAW;IAClD,MAAM,CAAC,YAAY,SAAK;;CAMzB"}
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
18
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
19
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
20
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
21
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
22
+ };
23
+ var __metadata = (this && this.__metadata) || function (k, v) {
24
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
25
+ };
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.LifecycleBoundGraph = void 0;
28
+ var src_1 = require("../../src");
29
+ var LifecycleBound_1 = require("../../src/decorators/LifecycleBound");
30
+ var LifecycleBoundGraph = /** @class */ (function (_super) {
31
+ __extends(LifecycleBoundGraph, _super);
32
+ function LifecycleBoundGraph() {
33
+ var _this = _super.call(this) || this;
34
+ LifecycleBoundGraph_1.timesCreated++;
35
+ return _this;
36
+ }
37
+ LifecycleBoundGraph_1 = LifecycleBoundGraph;
38
+ var LifecycleBoundGraph_1;
39
+ LifecycleBoundGraph.timesCreated = 0;
40
+ LifecycleBoundGraph = LifecycleBoundGraph_1 = __decorate([
41
+ (0, LifecycleBound_1.LifecycleBound)(),
42
+ (0, src_1.Graph)(),
43
+ __metadata("design:paramtypes", [])
44
+ ], LifecycleBoundGraph);
45
+ return LifecycleBoundGraph;
46
+ }(src_1.ObjectGraph));
47
+ exports.LifecycleBoundGraph = LifecycleBoundGraph;
48
+ //# sourceMappingURL=LifecycleBoundGraph.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LifecycleBoundGraph.js","sourceRoot":"","sources":["../../../test/fixtures/LifecycleBoundGraph.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iCAA+C;AAC/C,sEAAqE;AAGrE;IAAyC,uCAAW;IAGlD;QAAA,YACE,iBAAO,SAER;QADC,qBAAmB,CAAC,YAAY,EAAE,CAAC;;IACrC,CAAC;4BANU,mBAAmB;;IACvB,gCAAY,GAAG,CAAC,CAAC;IADb,mBAAmB;QAD/B,IAAA,+BAAc,GAAE;QAAE,IAAA,WAAK,GAAE;;OACb,mBAAmB,CAO/B;IAAD,0BAAC;CAAA,AARD,CACyC,iBAAW,GAOnD;AAPY,kDAAmB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-obsidian",
3
- "version": "0.0.30",
3
+ "version": "0.0.31",
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",
@@ -0,0 +1,6 @@
1
+ export function LifecycleBound() {
2
+ return (constructor: any) => {
3
+ Reflect.defineMetadata('isLifecycleBound', true, constructor);
4
+ return constructor;
5
+ };
6
+ }
@@ -30,7 +30,7 @@ export class GraphRegistry {
30
30
  }
31
31
 
32
32
  resolve<T extends Graph>(Graph: Constructable<T>, props?: any): T {
33
- if (this.isSingleton(Graph) && this.has(Graph)) {
33
+ if ((this.isSingleton(Graph) || this.isBoundToReactLifecycle(Graph)) && this.has(Graph)) {
34
34
  return this.getFirst(Graph);
35
35
  }
36
36
  const graph = this.graphMiddlewares.resolve(Graph, props);
@@ -38,8 +38,8 @@ export class GraphRegistry {
38
38
  return graph as T;
39
39
  }
40
40
 
41
- private has(Graph: Constructable<Graph>) {
42
- return this.constructorToInstance.has(Graph);
41
+ private has(Graph: Constructable<Graph>): boolean {
42
+ return (this.constructorToInstance.get(Graph)?.size ?? 0) > 0;
43
43
  }
44
44
 
45
45
  private getFirst<T extends Graph>(Graph: Constructable<T>): T {
@@ -58,6 +58,10 @@ export class GraphRegistry {
58
58
  return Reflect.getMetadata('isSingleton', Graph) ?? false;
59
59
  }
60
60
 
61
+ private isBoundToReactLifecycle(Graph: Constructable<Graph>): boolean {
62
+ return Reflect.getMetadata('isLifecycleBound', Graph) ?? false;
63
+ }
64
+
61
65
  clear(graph: Graph) {
62
66
  const Graph = this.instanceToConstructor.get(graph)!;
63
67
  if (this.isSingleton(Graph)) return;