@joist/di 3.2.0 → 3.2.1
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 +2 -2
- package/package.json +1 -1
- package/src/lib/injector.ts +4 -4
package/README.md
CHANGED
|
@@ -150,7 +150,7 @@ customElements.define('my-element', MyElement);
|
|
|
150
150
|
When using @joist/di with custom elements a default root injector is created dubbed 'environment'. This is the injector that all other injectors will eventually stop at.
|
|
151
151
|
If you need to define something in this environment you can do so with the `defineEnvironment` method.
|
|
152
152
|
|
|
153
|
-
|
|
153
|
+
```ts
|
|
154
154
|
import { defineEnvironment } from '@joist/di';
|
|
155
155
|
|
|
156
156
|
defineEnvironment([{ provide: MyService, use: SomeOtherService }]);
|
|
@@ -183,4 +183,4 @@ const car = app.get(Car);
|
|
|
183
183
|
|
|
184
184
|
// gas, 16
|
|
185
185
|
console.log(car.engine(), car.tires());
|
|
186
|
-
|
|
186
|
+
```
|
package/package.json
CHANGED
package/src/lib/injector.ts
CHANGED
|
@@ -27,7 +27,7 @@ export class Injector {
|
|
|
27
27
|
// ke track of isntances. One Token can have one instance
|
|
28
28
|
#instances = new WeakMap<ProviderToken<any>, any>();
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
parent: Injector | undefined = undefined;
|
|
31
31
|
|
|
32
32
|
constructor(
|
|
33
33
|
public providers: Provider<any>[] = [],
|
|
@@ -63,15 +63,15 @@ export class Injector {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
// check for a parent and attempt to get there
|
|
66
|
-
if (this
|
|
67
|
-
return this
|
|
66
|
+
if (this.parent) {
|
|
67
|
+
return this.parent.get(token);
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
return this.#createAndCache(token, () => new token());
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
setParent(parent: Injector | undefined) {
|
|
74
|
-
this
|
|
74
|
+
this.parent = parent;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
clear() {
|