react-obsidian 0.0.5 → 0.0.10
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 -1
- package/dist/src/Obsidian.d.ts.map +1 -1
- package/dist/src/Obsidian.js.map +1 -1
- package/dist/src/ProvidedPropertiesStore.d.ts +1 -1
- package/dist/src/ProvidedPropertiesStore.d.ts.map +1 -1
- package/dist/src/ScopedValuesRegistry.d.ts +1 -0
- package/dist/src/ScopedValuesRegistry.d.ts.map +1 -1
- package/dist/src/ScopedValuesRegistry.js.map +1 -1
- package/dist/src/decorators/Graph.d.ts +3 -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 +2 -1
- package/dist/src/decorators/injectClass.d.ts.map +1 -1
- package/dist/src/decorators/injectClass.js.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 +4 -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 +5 -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/autobind.d.ts +2 -0
- package/dist/src/graph/autobind.d.ts.map +1 -0
- package/dist/src/graph/autobind.js +12 -0
- package/dist/src/graph/autobind.js.map +1 -0
- package/dist/src/graph/registry/DefaultGraphResolver.d.ts +6 -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 -9
- 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 +7 -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 +4 -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 +15 -13
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +26 -12
- package/dist/src/index.js.map +1 -1
- package/dist/src/injectors/components/ComponentInjector.d.ts +2 -1
- package/dist/src/injectors/components/ComponentInjector.d.ts.map +1 -1
- package/dist/src/injectors/components/ComponentInjector.js.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 +2 -1
- package/dist/src/injectors/components/useGraph.d.ts.map +1 -1
- package/dist/src/injectors/components/useGraph.js.map +1 -1
- package/dist/src/injectors/hooks/HookInjector.d.ts +2 -1
- package/dist/src/injectors/hooks/HookInjector.d.ts.map +1 -1
- package/dist/src/injectors/hooks/HookInjector.js.map +1 -1
- package/dist/src/types/index.d.ts +12 -0
- package/dist/src/types/index.d.ts.map +1 -0
- package/dist/src/types/index.js +3 -0
- package/dist/src/types/index.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 -1
- 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/example/tsconfig.json +0 -3
- package/package.json +1 -1
- package/src/Obsidian.ts +2 -1
- package/src/ProvidedPropertiesStore.ts +1 -1
- package/src/ScopedValuesRegistry.ts +2 -0
- package/src/decorators/Graph.ts +3 -2
- package/src/decorators/Memoize.ts +18 -0
- package/src/decorators/injectClass.ts +2 -1
- package/src/decorators/provides/MemoizeDescriptor.ts +14 -0
- package/src/decorators/provides/Provides.ts +5 -5
- package/src/graph/Graph.ts +1 -3
- package/src/graph/ObjectGraph.ts +12 -5
- package/src/graph/PropertyRetriever.ts +1 -1
- package/src/graph/autobind.ts +7 -0
- package/src/graph/registry/DefaultGraphResolver.ts +6 -4
- package/src/graph/registry/GraphMiddleware.ts +4 -22
- package/src/graph/registry/GraphMiddlewareChain.ts +8 -7
- package/src/graph/registry/GraphRegistry.ts +5 -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 +19 -16
- package/src/injectors/components/ComponentInjector.tsx +2 -1
- package/src/injectors/components/PropsInjector.ts +1 -1
- package/src/injectors/components/useGraph.ts +2 -1
- package/src/injectors/hooks/HookInjector.ts +3 -2
- package/src/types/index.ts +13 -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/@types/index.d.ts +0 -13
- package/src/decorators/provides/PropertyDescriptorToSingleton.ts +0 -11
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { Constructable } from '../../types';
|
|
2
|
+
import { Graph } from '../Graph';
|
|
3
|
+
import { Middleware } from './Middleware';
|
|
4
|
+
import { ResolveChain } from './ResolveChain';
|
|
3
5
|
|
|
4
|
-
export default class DefaultGraphMiddleware extends
|
|
5
|
-
resolve
|
|
6
|
+
export default class DefaultGraphMiddleware<T extends Graph> extends Middleware<T> {
|
|
7
|
+
resolve(_resolveChain: ResolveChain<T>, Graph: Constructable<T>, props?: any): T {
|
|
6
8
|
return new Graph(props);
|
|
7
9
|
}
|
|
8
10
|
}
|
|
@@ -1,23 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ObjectGraph } from '../ObjectGraph';
|
|
2
|
+
import { GraphResolveChain } from './GraphResolveChain';
|
|
3
|
+
import { Middleware } from './Middleware';
|
|
2
4
|
|
|
3
|
-
export abstract class GraphMiddleware {
|
|
4
|
-
private next!: GraphMiddleware;
|
|
5
|
-
|
|
6
|
-
public setNext(next: GraphMiddleware) {
|
|
7
|
-
this.next = next;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
public get resolveChain(): ResolveChain {
|
|
11
|
-
return {
|
|
12
|
-
proceed: <T extends Graph, Props>(Graph: Constructable<T>, props?: Props): T => {
|
|
13
|
-
return this.next.resolve(this.next.resolveChain, Graph, props);
|
|
14
|
-
},
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
abstract resolve<T extends Graph, Props>(resolveChain: ResolveChain, Graph: Constructable<T>, props?: Props): T;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface ResolveChain {
|
|
22
|
-
proceed<T extends Graph, Props>(Graph: Constructable<T>, props?: Props): T;
|
|
23
|
-
}
|
|
5
|
+
export abstract class GraphMiddleware extends Middleware<ObjectGraph, GraphResolveChain> { }
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Constructable } from '../../types';
|
|
2
|
+
import { Graph } from '../Graph';
|
|
2
3
|
import DefaultGraphMiddleware from './DefaultGraphResolver';
|
|
3
|
-
import {
|
|
4
|
+
import { Middleware } from './Middleware';
|
|
4
5
|
|
|
5
|
-
export default class GraphMiddlewareChain {
|
|
6
|
-
private middlewares:
|
|
6
|
+
export default class GraphMiddlewareChain<T extends Graph> {
|
|
7
|
+
private middlewares: Middleware<T>[];
|
|
7
8
|
|
|
8
|
-
constructor(defaultMiddleware:
|
|
9
|
+
constructor(defaultMiddleware: Middleware<T> = new DefaultGraphMiddleware()) {
|
|
9
10
|
this.middlewares = [defaultMiddleware];
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
resolve
|
|
13
|
+
resolve(Graph: Constructable<T>, props?: any): T {
|
|
13
14
|
return this.middlewares[0].resolve(this.middlewares[0].resolveChain, Graph, props);
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
add(middleware:
|
|
17
|
+
add(middleware: Middleware<T>) {
|
|
17
18
|
this.middlewares.unshift(middleware);
|
|
18
19
|
this.updateResolveChain();
|
|
19
20
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { Constructable, Scope } from '../../types';
|
|
2
|
+
import { Graph } from '../Graph';
|
|
3
|
+
import { Middleware } from './Middleware';
|
|
3
4
|
import GraphMiddlewareChain from './GraphMiddlewareChain';
|
|
4
5
|
|
|
5
6
|
class GraphRegistry {
|
|
@@ -48,7 +49,7 @@ class GraphRegistry {
|
|
|
48
49
|
}
|
|
49
50
|
const graph = this.graphMiddlewares.resolve(Graph, props);
|
|
50
51
|
this.set(Graph, graph);
|
|
51
|
-
return graph;
|
|
52
|
+
return graph as T;
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
clear(graph: Graph) {
|
|
@@ -57,7 +58,7 @@ class GraphRegistry {
|
|
|
57
58
|
this.constructorToInstance.delete(Graph);
|
|
58
59
|
}
|
|
59
60
|
|
|
60
|
-
addGraphMiddleware(middleware:
|
|
61
|
+
addGraphMiddleware(middleware: Middleware<Graph>) {
|
|
61
62
|
this.graphMiddlewares.add(middleware);
|
|
62
63
|
}
|
|
63
64
|
|
|
@@ -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,27 +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';
|
|
6
|
+
import { Constructable } from './types';
|
|
9
7
|
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
export
|
|
13
|
-
export
|
|
14
|
-
export
|
|
15
|
-
export
|
|
8
|
+
export * from './types';
|
|
9
|
+
|
|
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();
|
|
16
19
|
|
|
17
20
|
const componentInjector = new ComponentInjector();
|
|
18
21
|
export const injectComponent = <P> (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
) => componentInjector.inject(
|
|
22
|
+
Target: React.FunctionComponent<P>,
|
|
23
|
+
Graph: Constructable<_ObjectGraph>,
|
|
24
|
+
) => componentInjector.inject(Target, Graph);
|
|
22
25
|
|
|
23
26
|
const hookInjector = new HookInjector();
|
|
24
27
|
export const injectHook = <Args, Result> (
|
|
25
28
|
hook: (args: Args) => Result,
|
|
26
|
-
|
|
27
|
-
) => hookInjector.inject(hook,
|
|
29
|
+
Graph: Constructable<_ObjectGraph>,
|
|
30
|
+
) => hookInjector.inject(hook, Graph);
|
|
@@ -1,9 +1,10 @@
|
|
|
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
|
+
import { Constructable } from '../../types';
|
|
7
8
|
|
|
8
9
|
export default class ComponentInjector {
|
|
9
10
|
inject<P>(
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
|
-
import
|
|
2
|
+
import { Constructable } from '../../types';
|
|
3
|
+
import { ObjectGraph } from '../../graph/ObjectGraph';
|
|
3
4
|
import graphRegistry from '../../graph/registry/GraphRegistry';
|
|
4
5
|
import referenceCounter from '../../ReferenceCounter';
|
|
5
6
|
|
|
@@ -1,6 +1,7 @@
|
|
|
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
|
+
import { Constructable } from '../../types';
|
|
4
5
|
|
|
5
6
|
export default class HookInjector {
|
|
6
7
|
inject<Args, Result>(
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type Constructable<T> = {
|
|
2
|
+
new(...args: any): T;
|
|
3
|
+
};
|
|
4
|
+
|
|
5
|
+
export type Scope = string | number | symbol;
|
|
6
|
+
|
|
7
|
+
export type Constructor = { new(...args: any[]): any };
|
|
8
|
+
|
|
9
|
+
export type ServiceLocator<Clazz> = {
|
|
10
|
+
[Key in keyof Clazz]: Function
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type GraphInternals = 'retrieve' | 'name' | 'scope';
|
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"}
|
package/src/@types/index.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
declare type Constructable<T> = {
|
|
2
|
-
new(...args: any): T;
|
|
3
|
-
};
|
|
4
|
-
|
|
5
|
-
declare type Scope = string | number | symbol;
|
|
6
|
-
|
|
7
|
-
declare type Constructor = { new(...args: any[]): any };
|
|
8
|
-
|
|
9
|
-
declare type ServiceLocator<Clazz> = {
|
|
10
|
-
[Key in keyof Clazz]: Function
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
declare type GraphInternals = 'retrieve' | 'name' | 'scope';
|
|
@@ -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
|
-
}
|