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.
- package/.eslintrc.json +3 -2
- package/README.md +7 -0
- package/dist/src/Obsidian.d.ts +2 -2
- package/dist/src/Obsidian.d.ts.map +1 -1
- package/dist/src/ProvidedPropertiesStore.d.ts +1 -1
- package/dist/src/ProvidedPropertiesStore.d.ts.map +1 -1
- package/dist/src/decorators/Graph.d.ts +2 -2
- package/dist/src/decorators/Graph.d.ts.map +1 -1
- package/dist/src/decorators/Graph.js +2 -1
- package/dist/src/decorators/Graph.js.map +1 -1
- package/dist/src/decorators/Memoize.d.ts +3 -0
- package/dist/src/decorators/Memoize.d.ts.map +1 -0
- package/dist/src/decorators/Memoize.js +21 -0
- package/dist/src/decorators/Memoize.js.map +1 -0
- package/dist/src/decorators/injectClass.d.ts +1 -1
- package/dist/src/decorators/injectClass.d.ts.map +1 -1
- package/dist/src/decorators/provides/MemoizeDescriptor.d.ts +2 -0
- package/dist/src/decorators/provides/MemoizeDescriptor.d.ts.map +1 -0
- package/dist/src/decorators/provides/MemoizeDescriptor.js +23 -0
- package/dist/src/decorators/provides/MemoizeDescriptor.js.map +1 -0
- package/dist/src/decorators/provides/Provides.d.ts +3 -3
- package/dist/src/decorators/provides/Provides.d.ts.map +1 -1
- package/dist/src/decorators/provides/Provides.js +4 -3
- package/dist/src/decorators/provides/Provides.js.map +1 -1
- package/dist/src/graph/Graph.d.ts +1 -2
- package/dist/src/graph/Graph.d.ts.map +1 -1
- package/dist/src/graph/ObjectGraph.d.ts +4 -4
- package/dist/src/graph/ObjectGraph.d.ts.map +1 -1
- package/dist/src/graph/ObjectGraph.js +23 -5
- package/dist/src/graph/ObjectGraph.js.map +1 -1
- package/dist/src/graph/PropertyRetriever.d.ts +1 -1
- package/dist/src/graph/PropertyRetriever.d.ts.map +1 -1
- package/dist/src/graph/registry/DefaultGraphResolver.d.ts +5 -4
- package/dist/src/graph/registry/DefaultGraphResolver.d.ts.map +1 -1
- package/dist/src/graph/registry/DefaultGraphResolver.js +2 -2
- package/dist/src/graph/registry/DefaultGraphResolver.js.map +1 -1
- package/dist/src/graph/registry/GraphMiddleware.d.ts +4 -10
- package/dist/src/graph/registry/GraphMiddleware.d.ts.map +1 -1
- package/dist/src/graph/registry/GraphMiddleware.js +20 -17
- package/dist/src/graph/registry/GraphMiddleware.js.map +1 -1
- package/dist/src/graph/registry/GraphMiddlewareChain.d.ts +6 -6
- package/dist/src/graph/registry/GraphMiddlewareChain.d.ts.map +1 -1
- package/dist/src/graph/registry/GraphMiddlewareChain.js.map +1 -1
- package/dist/src/graph/registry/GraphRegistry.d.ts +3 -3
- package/dist/src/graph/registry/GraphRegistry.d.ts.map +1 -1
- package/dist/src/graph/registry/GraphRegistry.js.map +1 -1
- package/dist/src/graph/registry/GraphResolveChain.d.ts +4 -0
- package/dist/src/graph/registry/GraphResolveChain.d.ts.map +1 -0
- package/dist/src/graph/registry/GraphResolveChain.js +3 -0
- package/dist/src/graph/registry/GraphResolveChain.js.map +1 -0
- package/dist/src/graph/registry/Middleware.d.ts +10 -0
- package/dist/src/graph/registry/Middleware.d.ts.map +1 -0
- package/dist/src/graph/registry/Middleware.js +25 -0
- package/dist/src/graph/registry/Middleware.js.map +1 -0
- package/dist/src/graph/registry/ResolveChain.d.ts +5 -0
- package/dist/src/graph/registry/ResolveChain.d.ts.map +1 -0
- package/dist/src/graph/registry/ResolveChain.js +3 -0
- package/dist/src/graph/registry/ResolveChain.js.map +1 -0
- package/dist/src/index.d.ts +13 -13
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +15 -12
- package/dist/src/index.js.map +1 -1
- package/dist/src/injectors/components/ComponentInjector.d.ts +1 -1
- package/dist/src/injectors/components/ComponentInjector.d.ts.map +1 -1
- package/dist/src/injectors/components/PropsInjector.d.ts +1 -1
- package/dist/src/injectors/components/PropsInjector.d.ts.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/hooks/HookInjector.d.ts +1 -1
- package/dist/src/injectors/hooks/HookInjector.d.ts.map +1 -1
- package/dist/src/utils/autobind.d.ts +2 -0
- package/dist/src/utils/autobind.d.ts.map +1 -0
- package/dist/src/utils/autobind.js +19 -0
- package/dist/src/utils/autobind.js.map +1 -0
- package/dist/test/integration/fixtures/Subgraph.d.ts +1 -0
- package/dist/test/integration/fixtures/Subgraph.d.ts.map +1 -1
- package/dist/test/integration/fixtures/Subgraph.js +11 -1
- package/dist/test/integration/fixtures/Subgraph.js.map +1 -1
- package/dist/testkit/index.d.ts +1 -2
- package/dist/testkit/index.d.ts.map +1 -1
- package/dist/testkit/index.js +1 -2
- package/dist/testkit/index.js.map +1 -1
- package/package.json +1 -1
- package/src/Obsidian.ts +2 -2
- package/src/ProvidedPropertiesStore.ts +1 -1
- package/src/decorators/Graph.ts +2 -2
- package/src/decorators/Memoize.ts +18 -0
- package/src/decorators/injectClass.ts +1 -1
- package/src/decorators/provides/MemoizeDescriptor.ts +14 -0
- package/src/decorators/provides/Provides.ts +4 -5
- package/src/graph/Graph.ts +1 -3
- package/src/graph/ObjectGraph.ts +11 -5
- package/src/graph/PropertyRetriever.ts +1 -1
- package/src/graph/registry/DefaultGraphResolver.ts +5 -4
- package/src/graph/registry/GraphMiddleware.ts +4 -23
- package/src/graph/registry/GraphMiddlewareChain.ts +7 -7
- package/src/graph/registry/GraphRegistry.ts +4 -4
- package/src/graph/registry/GraphResolveChain.ts +4 -0
- package/src/graph/registry/Middleware.ts +21 -0
- package/src/graph/registry/ResolveChain.ts +5 -0
- package/src/index.ts +16 -16
- package/src/injectors/components/ComponentInjector.tsx +1 -1
- package/src/injectors/components/PropsInjector.ts +1 -1
- package/src/injectors/components/useGraph.ts +1 -1
- package/src/injectors/hooks/HookInjector.ts +2 -2
- package/src/utils/autobind.ts +12 -0
- package/testkit/index.ts +9 -5
- package/dist/src/decorators/provides/PropertyDescriptorToSingleton.d.ts +0 -2
- package/dist/src/decorators/provides/PropertyDescriptorToSingleton.d.ts.map +0 -1
- package/dist/src/decorators/provides/PropertyDescriptorToSingleton.js +0 -20
- package/dist/src/decorators/provides/PropertyDescriptorToSingleton.js.map +0 -1
- 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
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
3
|
-
import _ObjectGraph from './graph/ObjectGraph';
|
|
2
|
+
import { ObjectGraph as _ObjectGraph } from './graph/ObjectGraph';
|
|
4
3
|
import ComponentInjector from './injectors/components/ComponentInjector';
|
|
5
|
-
import
|
|
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
|
|
14
|
-
export
|
|
15
|
-
export
|
|
16
|
-
export
|
|
17
|
-
export
|
|
18
|
-
export
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
) => componentInjector.inject(
|
|
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
|
-
|
|
30
|
-
) => hookInjector.inject(hook,
|
|
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,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 {
|
|
2
|
-
import
|
|
3
|
-
|
|
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<
|
|
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)
|
|
19
|
+
return new TheGraph(props);
|
|
16
20
|
}
|
|
17
21
|
return resolveChain.proceed(Graph, props);
|
|
18
22
|
}
|
|
@@ -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
|
-
}
|