react-obsidian 0.0.6 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. package/.eslintrc.json +3 -2
  2. package/README.md +7 -0
  3. package/dist/src/Obsidian.d.ts +2 -2
  4. package/dist/src/Obsidian.d.ts.map +1 -1
  5. package/dist/src/ProvidedPropertiesStore.d.ts +1 -1
  6. package/dist/src/ProvidedPropertiesStore.d.ts.map +1 -1
  7. package/dist/src/decorators/Graph.d.ts +2 -2
  8. package/dist/src/decorators/Graph.d.ts.map +1 -1
  9. package/dist/src/decorators/Graph.js +2 -1
  10. package/dist/src/decorators/Graph.js.map +1 -1
  11. package/dist/src/decorators/Memoize.d.ts +3 -0
  12. package/dist/src/decorators/Memoize.d.ts.map +1 -0
  13. package/dist/src/decorators/Memoize.js +21 -0
  14. package/dist/src/decorators/Memoize.js.map +1 -0
  15. package/dist/src/decorators/injectClass.d.ts +1 -1
  16. package/dist/src/decorators/injectClass.d.ts.map +1 -1
  17. package/dist/src/decorators/provides/MemoizeDescriptor.d.ts +2 -0
  18. package/dist/src/decorators/provides/MemoizeDescriptor.d.ts.map +1 -0
  19. package/dist/src/decorators/provides/MemoizeDescriptor.js +23 -0
  20. package/dist/src/decorators/provides/MemoizeDescriptor.js.map +1 -0
  21. package/dist/src/decorators/provides/Provides.d.ts +3 -3
  22. package/dist/src/decorators/provides/Provides.d.ts.map +1 -1
  23. package/dist/src/decorators/provides/Provides.js +4 -3
  24. package/dist/src/decorators/provides/Provides.js.map +1 -1
  25. package/dist/src/graph/Graph.d.ts +1 -2
  26. package/dist/src/graph/Graph.d.ts.map +1 -1
  27. package/dist/src/graph/ObjectGraph.d.ts +4 -4
  28. package/dist/src/graph/ObjectGraph.d.ts.map +1 -1
  29. package/dist/src/graph/ObjectGraph.js +23 -5
  30. package/dist/src/graph/ObjectGraph.js.map +1 -1
  31. package/dist/src/graph/PropertyRetriever.d.ts +1 -1
  32. package/dist/src/graph/PropertyRetriever.d.ts.map +1 -1
  33. package/dist/src/graph/registry/DefaultGraphResolver.d.ts +5 -4
  34. package/dist/src/graph/registry/DefaultGraphResolver.d.ts.map +1 -1
  35. package/dist/src/graph/registry/DefaultGraphResolver.js +2 -2
  36. package/dist/src/graph/registry/DefaultGraphResolver.js.map +1 -1
  37. package/dist/src/graph/registry/GraphMiddleware.d.ts +4 -10
  38. package/dist/src/graph/registry/GraphMiddleware.d.ts.map +1 -1
  39. package/dist/src/graph/registry/GraphMiddleware.js +20 -17
  40. package/dist/src/graph/registry/GraphMiddleware.js.map +1 -1
  41. package/dist/src/graph/registry/GraphMiddlewareChain.d.ts +6 -6
  42. package/dist/src/graph/registry/GraphMiddlewareChain.d.ts.map +1 -1
  43. package/dist/src/graph/registry/GraphMiddlewareChain.js.map +1 -1
  44. package/dist/src/graph/registry/GraphRegistry.d.ts +3 -3
  45. package/dist/src/graph/registry/GraphRegistry.d.ts.map +1 -1
  46. package/dist/src/graph/registry/GraphRegistry.js.map +1 -1
  47. package/dist/src/graph/registry/GraphResolveChain.d.ts +4 -0
  48. package/dist/src/graph/registry/GraphResolveChain.d.ts.map +1 -0
  49. package/dist/src/graph/registry/GraphResolveChain.js +3 -0
  50. package/dist/src/graph/registry/GraphResolveChain.js.map +1 -0
  51. package/dist/src/graph/registry/Middleware.d.ts +10 -0
  52. package/dist/src/graph/registry/Middleware.d.ts.map +1 -0
  53. package/dist/src/graph/registry/Middleware.js +25 -0
  54. package/dist/src/graph/registry/Middleware.js.map +1 -0
  55. package/dist/src/graph/registry/ResolveChain.d.ts +5 -0
  56. package/dist/src/graph/registry/ResolveChain.d.ts.map +1 -0
  57. package/dist/src/graph/registry/ResolveChain.js +3 -0
  58. package/dist/src/graph/registry/ResolveChain.js.map +1 -0
  59. package/dist/src/index.d.ts +13 -13
  60. package/dist/src/index.d.ts.map +1 -1
  61. package/dist/src/index.js +15 -12
  62. package/dist/src/index.js.map +1 -1
  63. package/dist/src/injectors/components/ComponentInjector.d.ts +1 -1
  64. package/dist/src/injectors/components/ComponentInjector.d.ts.map +1 -1
  65. package/dist/src/injectors/components/PropsInjector.d.ts +1 -1
  66. package/dist/src/injectors/components/PropsInjector.d.ts.map +1 -1
  67. package/dist/src/injectors/components/useGraph.d.ts +1 -1
  68. package/dist/src/injectors/components/useGraph.d.ts.map +1 -1
  69. package/dist/src/injectors/hooks/HookInjector.d.ts +1 -1
  70. package/dist/src/injectors/hooks/HookInjector.d.ts.map +1 -1
  71. package/dist/src/utils/autobind.d.ts +2 -0
  72. package/dist/src/utils/autobind.d.ts.map +1 -0
  73. package/dist/src/utils/autobind.js +19 -0
  74. package/dist/src/utils/autobind.js.map +1 -0
  75. package/dist/test/integration/fixtures/Subgraph.d.ts +1 -0
  76. package/dist/test/integration/fixtures/Subgraph.d.ts.map +1 -1
  77. package/dist/test/integration/fixtures/Subgraph.js +11 -1
  78. package/dist/test/integration/fixtures/Subgraph.js.map +1 -1
  79. package/dist/testkit/index.d.ts +1 -2
  80. package/dist/testkit/index.d.ts.map +1 -1
  81. package/dist/testkit/index.js +1 -2
  82. package/dist/testkit/index.js.map +1 -1
  83. package/package.json +1 -1
  84. package/src/Obsidian.ts +2 -2
  85. package/src/ProvidedPropertiesStore.ts +1 -1
  86. package/src/decorators/Graph.ts +2 -2
  87. package/src/decorators/Memoize.ts +18 -0
  88. package/src/decorators/injectClass.ts +1 -1
  89. package/src/decorators/provides/MemoizeDescriptor.ts +14 -0
  90. package/src/decorators/provides/Provides.ts +4 -5
  91. package/src/graph/Graph.ts +1 -3
  92. package/src/graph/ObjectGraph.ts +11 -5
  93. package/src/graph/PropertyRetriever.ts +1 -1
  94. package/src/graph/registry/DefaultGraphResolver.ts +5 -4
  95. package/src/graph/registry/GraphMiddleware.ts +4 -23
  96. package/src/graph/registry/GraphMiddlewareChain.ts +7 -7
  97. package/src/graph/registry/GraphRegistry.ts +4 -4
  98. package/src/graph/registry/GraphResolveChain.ts +4 -0
  99. package/src/graph/registry/Middleware.ts +21 -0
  100. package/src/graph/registry/ResolveChain.ts +5 -0
  101. package/src/index.ts +16 -16
  102. package/src/injectors/components/ComponentInjector.tsx +1 -1
  103. package/src/injectors/components/PropsInjector.ts +1 -1
  104. package/src/injectors/components/useGraph.ts +1 -1
  105. package/src/injectors/hooks/HookInjector.ts +2 -2
  106. package/src/utils/autobind.ts +12 -0
  107. package/testkit/index.ts +9 -5
  108. package/dist/src/decorators/provides/PropertyDescriptorToSingleton.d.ts +0 -2
  109. package/dist/src/decorators/provides/PropertyDescriptorToSingleton.d.ts.map +0 -1
  110. package/dist/src/decorators/provides/PropertyDescriptorToSingleton.js +0 -20
  111. package/dist/src/decorators/provides/PropertyDescriptorToSingleton.js.map +0 -1
  112. package/src/decorators/provides/PropertyDescriptorToSingleton.ts +0 -11
@@ -0,0 +1,21 @@
1
+ import { Constructable } from '../../types';
2
+ import { Graph } from '../Graph';
3
+ import { ResolveChain } from './ResolveChain';
4
+
5
+ export abstract class Middleware<T = Graph, RC = ResolveChain<T>> {
6
+ private next!: Middleware<T, ResolveChain<T>>;
7
+
8
+ public setNext(next: Middleware<T, ResolveChain<T>>) {
9
+ this.next = next;
10
+ }
11
+
12
+ public get resolveChain(): ResolveChain<T> {
13
+ return {
14
+ proceed: <Props>(Graph: Constructable<T>, props?: Props): T => {
15
+ return this.next.resolve(this.next.resolveChain, Graph, props);
16
+ },
17
+ };
18
+ }
19
+
20
+ abstract resolve<Props = any>(resolveChain: RC, Graph: Constructable<T>, props?: Props): T;
21
+ }
@@ -0,0 +1,5 @@
1
+ import { Constructable } from '../../types';
2
+
3
+ export interface ResolveChain<T> {
4
+ proceed<Props = any>(Graph: Constructable<T>, props?: Props): T;
5
+ }
package/src/index.ts CHANGED
@@ -1,30 +1,30 @@
1
1
  import React from 'react';
2
- import _Graph from './decorators/Graph';
3
- import _ObjectGraph from './graph/ObjectGraph';
2
+ import { ObjectGraph as _ObjectGraph } from './graph/ObjectGraph';
4
3
  import ComponentInjector from './injectors/components/ComponentInjector';
5
- import _Provides from './decorators/provides/Provides';
6
- import { Inject as _Inject, Injectable as _Injectable } from './decorators/injectClass';
7
- import _obsidian from './Obsidian';
4
+ import _Obsidian from './Obsidian';
8
5
  import HookInjector from './injectors/hooks/HookInjector';
9
6
  import { Constructable } from './types';
10
7
 
11
8
  export * from './types';
12
9
 
13
- export const Graph = _Graph;
14
- export const ObjectGraph = _ObjectGraph;
15
- export const Provides = _Provides;
16
- export const Injectable = _Injectable;
17
- export const Inject = _Inject;
18
- export const Obsidian = new _obsidian();
10
+ export { Graph } from './decorators/Graph';
11
+ export { ObjectGraph } from './graph/ObjectGraph';
12
+ export { Graph as IGraph } from './graph/Graph';
13
+ export { Provides } from './decorators/provides/Provides';
14
+ export { Injectable } from './decorators/injectClass';
15
+ export { Inject } from './decorators/injectClass';
16
+ export { GraphMiddleware } from './graph/registry/GraphMiddleware';
17
+ export { GraphResolveChain as ResolveChain } from './graph/registry/GraphResolveChain';
18
+ export const Obsidian = new _Obsidian();
19
19
 
20
20
  const componentInjector = new ComponentInjector();
21
21
  export const injectComponent = <P> (
22
- __Target: React.FunctionComponent<P>,
23
- __Graph: Constructable<_ObjectGraph>,
24
- ) => componentInjector.inject(__Target, __Graph);
22
+ Target: React.FunctionComponent<P>,
23
+ Graph: Constructable<_ObjectGraph>,
24
+ ) => componentInjector.inject(Target, Graph);
25
25
 
26
26
  const hookInjector = new HookInjector();
27
27
  export const injectHook = <Args, Result> (
28
28
  hook: (args: Args) => Result,
29
- __Graph: Constructable<_ObjectGraph>,
30
- ) => hookInjector.inject(hook, __Graph);
29
+ Graph: Constructable<_ObjectGraph>,
30
+ ) => hookInjector.inject(hook, Graph);
@@ -1,7 +1,7 @@
1
1
  import React, { useState } from 'react';
2
2
  import hoistNonReactStatics from 'hoist-non-react-statics';
3
3
  import 'reflect-metadata';
4
- import ObjectGraph from '../../graph/ObjectGraph';
4
+ import { ObjectGraph } from '../../graph/ObjectGraph';
5
5
  import PropsInjector from './PropsInjector';
6
6
  import useGraph from './useGraph';
7
7
  import { Constructable } from '../../types';
@@ -1,4 +1,4 @@
1
- import ObjectGraph from '../../graph/ObjectGraph';
1
+ import { ObjectGraph } from '../../graph/ObjectGraph';
2
2
 
3
3
  export default class PropsInjector<Props> {
4
4
  constructor(private graph: ObjectGraph) {}
@@ -1,6 +1,6 @@
1
1
  import { useEffect, useState } from 'react';
2
2
  import { Constructable } from '../../types';
3
- import ObjectGraph from '../../graph/ObjectGraph';
3
+ import { ObjectGraph } from '../../graph/ObjectGraph';
4
4
  import graphRegistry from '../../graph/registry/GraphRegistry';
5
5
  import referenceCounter from '../../ReferenceCounter';
6
6
 
@@ -1,5 +1,5 @@
1
- import ObjectGraph from '../../graph/ObjectGraph';
2
- import Graph from '../../graph/Graph';
1
+ import { ObjectGraph } from '../../graph/ObjectGraph';
2
+ import { Graph } from '../../graph/Graph';
3
3
  import useGraph from '../components/useGraph';
4
4
  import { Constructable } from '../../types';
5
5
 
@@ -0,0 +1,12 @@
1
+ import _ from 'lodash';
2
+
3
+ /* eslint-disable no-param-reassign */
4
+ export function autobind(target: Record<string, any>) {
5
+ const methods = Object.getOwnPropertyNames(Object.getPrototypeOf(target));
6
+ methods
7
+ .filter((method) => (method !== 'constructor'))
8
+ .filter((method) => _.isFunction(target[method]))
9
+ .forEach((method) => {
10
+ target[method] = target[method].bind(target);
11
+ });
12
+ }
package/testkit/index.ts CHANGED
@@ -1,6 +1,10 @@
1
- import { GraphMiddleware, ResolveChain } from '../src/graph/registry/GraphMiddleware';
2
- import ObjectGraph from '../src/graph/Graph';
3
- import { Constructable, Obsidian } from '../src';
1
+ import { GraphResolveChain } from 'src/graph/registry/GraphResolveChain';
2
+ import {
3
+ ObjectGraph,
4
+ Constructable,
5
+ GraphMiddleware,
6
+ Obsidian,
7
+ } from '../src';
4
8
 
5
9
  beforeEach(() => {
6
10
  Obsidian.clearGraphMiddlewares();
@@ -9,10 +13,10 @@ beforeEach(() => {
9
13
  class Index {
10
14
  mockGraphs(graphNameToGraph: Record<string, Constructable<ObjectGraph>>) {
11
15
  const graphMiddleware = new class extends GraphMiddleware {
12
- resolve<T extends ObjectGraph, Props>(resolveChain: ResolveChain, Graph: Constructable<T>, props?: Props) {
16
+ resolve<Props>(resolveChain: GraphResolveChain, Graph: Constructable<ObjectGraph>, props?: Props) {
13
17
  if (graphNameToGraph[Graph.name]) {
14
18
  const TheGraph = graphNameToGraph[Graph.name];
15
- return new TheGraph(props) as unknown as T;
19
+ return new TheGraph(props);
16
20
  }
17
21
  return resolveChain.proceed(Graph, props);
18
22
  }
@@ -1,2 +0,0 @@
1
- export default function makeSingleton(descriptor: PropertyDescriptor): PropertyDescriptor;
2
- //# sourceMappingURL=PropertyDescriptorToSingleton.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PropertyDescriptorToSingleton.d.ts","sourceRoot":"","sources":["../../../../src/decorators/provides/PropertyDescriptorToSingleton.ts"],"names":[],"mappings":"AACA,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,UAAU,EAAE,kBAAkB,GAAG,kBAAkB,CASxF"}
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /* eslint-disable no-param-reassign */
4
- function makeSingleton(descriptor) {
5
- var originalValue = descriptor.value;
6
- var createdDependency;
7
- descriptor.value = function value() {
8
- var args = [];
9
- for (var _i = 0; _i < arguments.length; _i++) {
10
- args[_i] = arguments[_i];
11
- }
12
- if (createdDependency)
13
- return createdDependency;
14
- createdDependency = originalValue.apply(this, args);
15
- return createdDependency;
16
- };
17
- return descriptor;
18
- }
19
- exports.default = makeSingleton;
20
- //# sourceMappingURL=PropertyDescriptorToSingleton.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PropertyDescriptorToSingleton.js","sourceRoot":"","sources":["../../../../src/decorators/provides/PropertyDescriptorToSingleton.ts"],"names":[],"mappings":";;AAAA,sCAAsC;AACtC,SAAwB,aAAa,CAAC,UAA8B;IAClE,IAAM,aAAa,GAAG,UAAU,CAAC,KAAK,CAAC;IACvC,IAAI,iBAAsB,CAAC;IAC3B,UAAU,CAAC,KAAK,GAAG,SAAS,KAAK;QAAC,cAAc;aAAd,UAAc,EAAd,qBAAc,EAAd,IAAc;YAAd,yBAAc;;QAC9C,IAAI,iBAAiB;YAAE,OAAO,iBAAiB,CAAC;QAChD,iBAAiB,GAAG,aAAa,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QACpD,OAAO,iBAAiB,CAAC;IAC3B,CAAC,CAAC;IACF,OAAO,UAAU,CAAC;AACpB,CAAC;AATD,gCASC"}
@@ -1,11 +0,0 @@
1
- /* eslint-disable no-param-reassign */
2
- export default function makeSingleton(descriptor: PropertyDescriptor): PropertyDescriptor {
3
- const originalValue = descriptor.value;
4
- let createdDependency: any;
5
- descriptor.value = function value(...args: any[]) {
6
- if (createdDependency) return createdDependency;
7
- createdDependency = originalValue.apply(this, args);
8
- return createdDependency;
9
- };
10
- return descriptor;
11
- }