react-obsidian 0.0.20 → 0.0.21
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 +8 -1
- package/dist/src/Obsidian.d.ts.map +1 -1
- package/dist/src/Obsidian.js +2 -1
- package/dist/src/Obsidian.js.map +1 -1
- package/dist/src/graph/ServiceLocatorFactory.d.ts +6 -0
- package/dist/src/graph/ServiceLocatorFactory.d.ts.map +1 -0
- package/dist/src/graph/ServiceLocatorFactory.js +22 -0
- package/dist/src/graph/ServiceLocatorFactory.js.map +1 -0
- package/package.json +1 -1
- package/src/Obsidian.ts +2 -1
- package/src/graph/ServiceLocatorFactory.ts +15 -0
package/README.md
CHANGED
|
@@ -26,6 +26,7 @@ React Obsidian is guided by the principles of the Dependency Injection pattern,
|
|
|
26
26
|
* [Accessing props in graphs](https://github.com/wix-incubator/react-obsidian#accessing-props-in-graphs)
|
|
27
27
|
* [Singleton graphs and providers](https://github.com/wix-incubator/react-obsidian#singleton-graphs-and-providers)
|
|
28
28
|
* [Graph middleware](https://github.com/wix-incubator/react-obsidian#graph-middleware)
|
|
29
|
+
* [Clear graphs](https://github.com/wix-incubator/react-obsidian#clear-graphs)
|
|
29
30
|
|
|
30
31
|
|
|
31
32
|
|
|
@@ -241,9 +242,15 @@ const loggingMiddleware = new class extends GraphMiddleware {
|
|
|
241
242
|
Obsidian.addGraphMiddleware(loggingMiddleware);
|
|
242
243
|
```
|
|
243
244
|
|
|
244
|
-
|
|
245
|
+
### Clear graphs
|
|
245
246
|
Graphs can be cleared by invoking `Obsidian.clearGraphs()`. This is useful in tests or when you need to reset the system to it's original state, for example when a user logs out.
|
|
246
247
|
|
|
248
|
+
#### Clearing graphs automatically during execution of Jest tests
|
|
249
|
+
Create a `jest.setup.js` file and add it to [setupFilesAfterEnv](https://jestjs.io/docs/configuration#setupfilesafterenv-array). Then, import the following file when ensures graphs are cleared before each test.
|
|
250
|
+
```javascript
|
|
251
|
+
import 'react-obsidian/clearGraphs';
|
|
252
|
+
```
|
|
253
|
+
|
|
247
254
|
## Prerequisites
|
|
248
255
|
Obsidian is highly opinionated and is developed with a specific environment in mind. Therefore, it has a few prerequisites for projects that want to integrate it.
|
|
249
256
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Obsidian.d.ts","sourceRoot":"","sources":["../../src/Obsidian.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;
|
|
1
|
+
{"version":3,"file":"Obsidian.d.ts","sourceRoot":"","sources":["../../src/Obsidian.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAInE,MAAM,CAAC,OAAO,OAAO,QAAQ;IAC3B,MAAM,CAAC,CAAC,SAAS,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,GAAG,EACtC,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,EACvB,KAAK,CAAC,EAAE,CAAC,GACR,cAAc,CAAC,IAAI,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC;IAI1C,MAAM,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE,WAAW;IAIvD,kBAAkB,CAAC,UAAU,EAAE,eAAe;IAI9C,qBAAqB;IAIrB,WAAW;CAIZ"}
|
package/dist/src/Obsidian.js
CHANGED
|
@@ -5,11 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
var GraphRegistry_1 = __importDefault(require("./graph/registry/GraphRegistry"));
|
|
7
7
|
var LazyInjector_1 = __importDefault(require("./injectors/class/LazyInjector"));
|
|
8
|
+
var ServiceLocatorFactory_1 = __importDefault(require("./graph/ServiceLocatorFactory"));
|
|
8
9
|
var Obsidian = /** @class */ (function () {
|
|
9
10
|
function Obsidian() {
|
|
10
11
|
}
|
|
11
12
|
Obsidian.prototype.obtain = function (Graph, props) {
|
|
12
|
-
return
|
|
13
|
+
return ServiceLocatorFactory_1.default.fromGraph(Graph, props);
|
|
13
14
|
};
|
|
14
15
|
Obsidian.prototype.inject = function (target, graph) {
|
|
15
16
|
return LazyInjector_1.default.inject(target, graph);
|
package/dist/src/Obsidian.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Obsidian.js","sourceRoot":"","sources":["../../src/Obsidian.ts"],"names":[],"mappings":";;;;;AAAA,iFAA2D;AAI3D,gFAA0D;
|
|
1
|
+
{"version":3,"file":"Obsidian.js","sourceRoot":"","sources":["../../src/Obsidian.ts"],"names":[],"mappings":";;;;;AAAA,iFAA2D;AAI3D,gFAA0D;AAC1D,wFAAkE;AAElE;IAAA;IAwBA,CAAC;IAvBC,yBAAM,GAAN,UACE,KAAuB,EACvB,KAAS;QAET,OAAO,+BAAqB,CAAC,SAAS,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACvD,CAAC;IAED,yBAAM,GAAN,UAAyB,MAAS,EAAE,KAAmB;QACrD,OAAO,sBAAY,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAC5C,CAAC;IAED,qCAAkB,GAAlB,UAAmB,UAA2B;QAC5C,uBAAa,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAC;IAC/C,CAAC;IAED,wCAAqB,GAArB;QACE,uBAAa,CAAC,qBAAqB,EAAE,CAAC;IACxC,CAAC;IAED,8BAAW,GAAX;QACE,uBAAa,CAAC,qBAAqB,EAAE,CAAC;QACtC,uBAAa,CAAC,QAAQ,EAAE,CAAC;IAC3B,CAAC;IACH,eAAC;AAAD,CAAC,AAxBD,IAwBC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ObjectGraph } from './ObjectGraph';
|
|
2
|
+
import { Constructable, ServiceLocator as ServiceLocatorType } from '../types';
|
|
3
|
+
export default class ServiceLocatorFactory {
|
|
4
|
+
static fromGraph<T extends ObjectGraph<P>, P = any>(Graph: Constructable<T>, props?: P): ServiceLocatorType<T>;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=ServiceLocatorFactory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ServiceLocatorFactory.d.ts","sourceRoot":"","sources":["../../../src/graph/ServiceLocatorFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,cAAc,IAAI,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAG/E,MAAM,CAAC,OAAO,OAAO,qBAAqB;IACxC,MAAM,CAAC,SAAS,CAAC,CAAC,SAAS,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC;CASvF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
var GraphRegistry_1 = __importDefault(require("./registry/GraphRegistry"));
|
|
7
|
+
var ServiceLocatorFactory = /** @class */ (function () {
|
|
8
|
+
function ServiceLocatorFactory() {
|
|
9
|
+
}
|
|
10
|
+
ServiceLocatorFactory.fromGraph = function (Graph, props) {
|
|
11
|
+
var resolved = GraphRegistry_1.default.resolve(Graph, props);
|
|
12
|
+
var wrapped = new Proxy(resolved, {
|
|
13
|
+
get: function (_target, property, receiver) {
|
|
14
|
+
return function () { return resolved.retrieve(property, receiver); };
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
return wrapped;
|
|
18
|
+
};
|
|
19
|
+
return ServiceLocatorFactory;
|
|
20
|
+
}());
|
|
21
|
+
exports.default = ServiceLocatorFactory;
|
|
22
|
+
//# sourceMappingURL=ServiceLocatorFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ServiceLocatorFactory.js","sourceRoot":"","sources":["../../../src/graph/ServiceLocatorFactory.ts"],"names":[],"mappings":";;;;;AAEA,2EAAqD;AAErD;IAAA;IAUA,CAAC;IATQ,+BAAS,GAAhB,UAAoD,KAAuB,EAAE,KAAS;QACpF,IAAM,QAAQ,GAAG,uBAAa,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;QACrD,IAAM,OAAO,GAAG,IAAI,KAAK,CAAC,QAAQ,EAAE;YAClC,GAAG,EAAH,UAAI,OAAY,EAAE,QAAgB,EAAE,QAAa;gBAC/C,OAAO,cAAM,OAAA,QAAQ,CAAC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAArC,CAAqC,CAAC;YACrD,CAAC;SACF,CAAC,CAAC;QACH,OAAO,OAA2C,CAAC;IACrD,CAAC;IACH,4BAAC;AAAD,CAAC,AAVD,IAUC"}
|
package/package.json
CHANGED
package/src/Obsidian.ts
CHANGED
|
@@ -3,13 +3,14 @@ import { ObjectGraph } from './graph/ObjectGraph';
|
|
|
3
3
|
import { Constructable, GraphInternals, ServiceLocator } from './types';
|
|
4
4
|
import { GraphMiddleware } from './graph/registry/GraphMiddleware';
|
|
5
5
|
import lazyInjector from './injectors/class/LazyInjector';
|
|
6
|
+
import serviceLocatorFactory from './graph/ServiceLocatorFactory';
|
|
6
7
|
|
|
7
8
|
export default class Obsidian {
|
|
8
9
|
obtain<T extends ObjectGraph<P>, P = any>(
|
|
9
10
|
Graph: Constructable<T>,
|
|
10
11
|
props?: P,
|
|
11
12
|
): ServiceLocator<Omit<T, GraphInternals>> {
|
|
12
|
-
return
|
|
13
|
+
return serviceLocatorFactory.fromGraph(Graph, props);
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
inject<T extends object>(target: T, graph?: ObjectGraph) {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ObjectGraph } from './ObjectGraph';
|
|
2
|
+
import { Constructable, ServiceLocator as ServiceLocatorType } from '../types';
|
|
3
|
+
import graphRegistry from './registry/GraphRegistry';
|
|
4
|
+
|
|
5
|
+
export default class ServiceLocatorFactory {
|
|
6
|
+
static fromGraph<T extends ObjectGraph<P>, P = any>(Graph: Constructable<T>, props?: P) {
|
|
7
|
+
const resolved = graphRegistry.resolve(Graph, props);
|
|
8
|
+
const wrapped = new Proxy(resolved, {
|
|
9
|
+
get(_target: any, property: string, receiver: any) {
|
|
10
|
+
return () => resolved.retrieve(property, receiver);
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
return wrapped as unknown as ServiceLocatorType<T>;
|
|
14
|
+
}
|
|
15
|
+
}
|