@joist/di 2.0.0-alpha.2 → 2.0.0-alpha.20
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 +92 -37
- package/dom/package.json +4 -0
- package/package.json +9 -4
- package/target/build/lib/dom/environment.d.ts +3 -0
- package/target/build/lib/dom/environment.js +9 -0
- package/target/build/lib/dom/injectable.d.ts +317 -0
- package/target/build/lib/dom/injectable.js +49 -0
- package/target/build/lib/dom.d.ts +2 -0
- package/target/build/lib/dom.js +2 -0
- package/target/build/lib/injector.d.ts +6 -23
- package/target/build/lib/injector.js +36 -52
- package/target/build/lib/provider.d.ts +2 -1
- package/target/build/lib/provider.js +0 -1
- package/target/build/lib/service.js +7 -2
- package/target/build/lib/utils.d.ts +1 -1
- package/target/build/lib/utils.js +1 -2
- package/target/build/lib.d.ts +2 -4
- package/target/build/lib.js +0 -3
- package/target/build/lib/environment.d.ts +0 -5
- package/target/build/lib/environment.js +0 -16
- package/target/build/lib/environment.js.map +0 -1
- package/target/build/lib/injectable.d.ts +0 -13
- package/target/build/lib/injectable.js +0 -17
- package/target/build/lib/injectable.js.map +0 -1
- package/target/build/lib/injector.js.map +0 -1
- package/target/build/lib/provider.js.map +0 -1
- package/target/build/lib/service.js.map +0 -1
- package/target/build/lib/utils.js.map +0 -1
- package/target/build/lib.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
# Di
|
|
2
2
|
|
|
3
|
-
Dependency Injection in ~800 bytes.
|
|
3
|
+
Dependency Injection in ~800 bytes. The Joist Dependency Injector is a small inversion of control (IOC) container that resolves dependencies lazyily.
|
|
4
|
+
This means that it passes functions around and that dependencies are not initialized untill they are called.
|
|
4
5
|
|
|
5
6
|
#### Installation:
|
|
6
7
|
|
|
7
8
|
```BASH
|
|
8
|
-
npm i @joist/di@
|
|
9
|
+
npm i @joist/di@canary
|
|
9
10
|
```
|
|
10
11
|
|
|
11
12
|
#### Example:
|
|
12
13
|
|
|
13
14
|
```TS
|
|
14
|
-
import { Injector } from '@joist/di';
|
|
15
|
+
import { Injector, Injected } from '@joist/di';
|
|
15
16
|
|
|
16
17
|
class FooService {
|
|
17
18
|
sayHello() {
|
|
@@ -20,12 +21,12 @@ class FooService {
|
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
class BarService {
|
|
23
|
-
static
|
|
24
|
+
static inject = [FooService];
|
|
24
25
|
|
|
25
|
-
constructor(private foo: FooService) {}
|
|
26
|
+
constructor(private foo: Injected<FooService>) {}
|
|
26
27
|
|
|
27
28
|
sayHello() {
|
|
28
|
-
return this.foo.sayHello();
|
|
29
|
+
return this.foo().sayHello();
|
|
29
30
|
}
|
|
30
31
|
}
|
|
31
32
|
|
|
@@ -37,7 +38,7 @@ app.get(BarService).sayHello(); // Hello from BarService and Hello from FooServi
|
|
|
37
38
|
#### Override A Service:
|
|
38
39
|
|
|
39
40
|
```TS
|
|
40
|
-
import { Injector, inject } from '@joist/di';
|
|
41
|
+
import { Injector, inject, Injected } from '@joist/di';
|
|
41
42
|
|
|
42
43
|
class FooService {
|
|
43
44
|
sayHello() {
|
|
@@ -46,28 +47,26 @@ class FooService {
|
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
class BarService {
|
|
49
|
-
static
|
|
50
|
+
static inject = [FooService];
|
|
50
51
|
|
|
51
|
-
constructor(private foo: FooService) {}
|
|
52
|
+
constructor(private foo: Injected<FooService>) {}
|
|
52
53
|
|
|
53
54
|
sayHello() {
|
|
54
|
-
return 'Hello From BarService and ' + this.foo.sayHello();
|
|
55
|
+
return 'Hello From BarService and ' + this.foo().sayHello();
|
|
55
56
|
}
|
|
56
57
|
}
|
|
57
58
|
|
|
58
59
|
// Override FooService with an alternate implementation
|
|
59
|
-
const app = new Injector(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return 'IT HAS BEEN OVERRIDEN'
|
|
66
|
-
}
|
|
60
|
+
const app = new Injector([
|
|
61
|
+
{
|
|
62
|
+
provide: FooService,
|
|
63
|
+
use: class extends FooService {
|
|
64
|
+
sayHello() {
|
|
65
|
+
return 'IT HAS BEEN OVERRIDEN'
|
|
67
66
|
}
|
|
68
67
|
}
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
}
|
|
69
|
+
]);
|
|
71
70
|
|
|
72
71
|
app.get(BarService).sayHello(); // Hello from BarService and IT HAS BEEN OVERRIDEN
|
|
73
72
|
```
|
|
@@ -95,54 +94,110 @@ Since the browser will be what initializes your custom elements we need to be ab
|
|
|
95
94
|
|
|
96
95
|
The `@injectable` decorator allows the Joist Dependency Injector to pass arguments to your custom element when instances of your element is created.
|
|
97
96
|
|
|
98
|
-
`@injectable`
|
|
97
|
+
`@injectable` also injects your services in a lazy way. Instead of passing direct instances of your services it passes a function that be called when you need your service instance. This allows the injector to look for parent injectors which are only availabel after connectedCallback.
|
|
99
98
|
|
|
100
99
|
#### Inject dependency into your custom element constructor
|
|
101
100
|
|
|
102
101
|
```TS
|
|
103
|
-
import {
|
|
102
|
+
import { injectable, Injected } from '@joist/di/dom';
|
|
104
103
|
|
|
105
|
-
@service
|
|
106
104
|
class MyService {}
|
|
107
105
|
|
|
108
106
|
@injectable
|
|
109
107
|
class MyElement extends HTMLElement {
|
|
110
|
-
static
|
|
108
|
+
static inject = [MyService];
|
|
111
109
|
|
|
112
|
-
constructor(public myService: MyService) {}
|
|
110
|
+
constructor(public myService: Injected<MyService>) {}
|
|
113
111
|
}
|
|
114
112
|
|
|
115
113
|
customElements.define('my-element', MyElement);
|
|
116
114
|
```
|
|
117
115
|
|
|
118
|
-
#### Define providers and overrides
|
|
116
|
+
#### Define global providers and overrides
|
|
119
117
|
|
|
120
118
|
This allows your to override services for different environments or scenarios
|
|
121
119
|
|
|
122
120
|
```TS
|
|
123
|
-
import {
|
|
121
|
+
import { environment, injectable, Injected } from '@joist/di/dom';
|
|
124
122
|
|
|
125
123
|
class Config {
|
|
126
124
|
apiUrl = 'http://localhost:4000/api/'
|
|
127
125
|
}
|
|
128
126
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
apiUrl = 'http://real-api/api/'
|
|
134
|
-
}
|
|
127
|
+
environment().providers.push({
|
|
128
|
+
provide: Config,
|
|
129
|
+
use: class {
|
|
130
|
+
apiUrl = 'http://real-api/api/'
|
|
135
131
|
}
|
|
136
|
-
|
|
132
|
+
});
|
|
137
133
|
|
|
138
134
|
@injectable
|
|
139
135
|
class MyElement extends HTMLElement {
|
|
140
|
-
static
|
|
136
|
+
static inject = [Config];
|
|
141
137
|
|
|
142
|
-
constructor(config: Config) {
|
|
143
|
-
console.log(config.apiUrl); // http://real-api/api/
|
|
138
|
+
constructor(config: Injected<Config>) {
|
|
139
|
+
console.log(config().apiUrl); // http://real-api/api/
|
|
144
140
|
}
|
|
145
141
|
}
|
|
146
142
|
|
|
147
143
|
customElements.define('my-element', MyElement);
|
|
148
144
|
```
|
|
145
|
+
|
|
146
|
+
## Context
|
|
147
|
+
|
|
148
|
+
The Joist injector is hierarchical meaning that you can define context for just one part of the DOM tree.
|
|
149
|
+
|
|
150
|
+
### NOTE:
|
|
151
|
+
|
|
152
|
+
When using context elements it is important that they are registered BEFORE your other elements.
|
|
153
|
+
If child elements are upgraded before the context element they won't be able to find the context scope.
|
|
154
|
+
|
|
155
|
+
```TS
|
|
156
|
+
import { injectable, Injected } from '@joist/di/dom';
|
|
157
|
+
|
|
158
|
+
class Colors {
|
|
159
|
+
primary = 'red';
|
|
160
|
+
secodnary = 'green';
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
@injectable
|
|
164
|
+
class ColorCtx extends HTMLElement {
|
|
165
|
+
static providers = [
|
|
166
|
+
{
|
|
167
|
+
provide: Colors,
|
|
168
|
+
use: class implements Colors {
|
|
169
|
+
primary = 'orange';
|
|
170
|
+
secondary = 'purple';
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
];
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
@injectable
|
|
177
|
+
class MyElement extends HTMLElement {
|
|
178
|
+
static inject = [Colors];
|
|
179
|
+
|
|
180
|
+
constructor(public colors: Injected<Colors>) {
|
|
181
|
+
super();
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
connectedCallback() {
|
|
185
|
+
const { primary } = this.colors();
|
|
186
|
+
|
|
187
|
+
this.style.background = primary;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
customElements.define('color-ctx', ColorCtx);
|
|
192
|
+
customElements.define('my-element', MyElement);
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
```HTML
|
|
196
|
+
<!-- Default Colors -->
|
|
197
|
+
<my-element></my-element>
|
|
198
|
+
|
|
199
|
+
<!-- Special color ctx -->
|
|
200
|
+
<color-ctx>
|
|
201
|
+
<my-element></my-element>
|
|
202
|
+
</color-ctx>
|
|
203
|
+
```
|
package/dom/package.json
ADDED
package/package.json
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@joist/di",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.20",
|
|
4
4
|
"main": "./target/build/lib.js",
|
|
5
5
|
"module": "./target/build/lib.js",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
8
8
|
"import": "./target/build/lib.js"
|
|
9
|
+
},
|
|
10
|
+
"./dom": {
|
|
11
|
+
"import": "./target/build/lib/dom.js"
|
|
9
12
|
}
|
|
10
13
|
},
|
|
11
14
|
"files": [
|
|
15
|
+
"dom",
|
|
12
16
|
"target/build"
|
|
13
17
|
],
|
|
14
18
|
"sideEffects": false,
|
|
15
|
-
"description": "Dependency Injection
|
|
19
|
+
"description": "Dependency Injection for Vanilla JS classes",
|
|
16
20
|
"repository": {
|
|
17
21
|
"type": "git",
|
|
18
22
|
"url": "git+https://github.com/deebloo/joist.git"
|
|
@@ -20,7 +24,8 @@
|
|
|
20
24
|
"keywords": [
|
|
21
25
|
"TypeScript",
|
|
22
26
|
"DI",
|
|
23
|
-
"Dependency Injection"
|
|
27
|
+
"Dependency Injection",
|
|
28
|
+
"WebComponents"
|
|
24
29
|
],
|
|
25
30
|
"author": "deebloo",
|
|
26
31
|
"license": "MIT",
|
|
@@ -34,5 +39,5 @@
|
|
|
34
39
|
"test": "tsc -p tsconfig.test.json && wtr --config ../../wtr.config.mjs --port 8001",
|
|
35
40
|
"build": "tsc -p tsconfig.build.json"
|
|
36
41
|
},
|
|
37
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "9b62852b4fdfea6eebbf128d55537adbd368faf2"
|
|
38
43
|
}
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import { Provider, ProviderToken } from '../provider';
|
|
2
|
+
import { Injector } from '../injector';
|
|
3
|
+
export interface Injectable {
|
|
4
|
+
inject?: ProviderToken<any>[];
|
|
5
|
+
providers?: Provider<any>[];
|
|
6
|
+
new (...args: any[]): HTMLElement;
|
|
7
|
+
}
|
|
8
|
+
export declare function injectable<T extends Injectable>(CustomElement: T): {
|
|
9
|
+
new (...args: any[]): {
|
|
10
|
+
injector: Injector;
|
|
11
|
+
connectedCallback(): void;
|
|
12
|
+
disconnectedCallback(): void;
|
|
13
|
+
accessKey: string;
|
|
14
|
+
readonly accessKeyLabel: string;
|
|
15
|
+
autocapitalize: string;
|
|
16
|
+
dir: string;
|
|
17
|
+
draggable: boolean;
|
|
18
|
+
hidden: boolean;
|
|
19
|
+
innerText: string;
|
|
20
|
+
lang: string;
|
|
21
|
+
readonly offsetHeight: number;
|
|
22
|
+
readonly offsetLeft: number;
|
|
23
|
+
readonly offsetParent: Element | null;
|
|
24
|
+
readonly offsetTop: number;
|
|
25
|
+
readonly offsetWidth: number;
|
|
26
|
+
outerText: string;
|
|
27
|
+
spellcheck: boolean;
|
|
28
|
+
title: string;
|
|
29
|
+
translate: boolean;
|
|
30
|
+
attachInternals(): ElementInternals;
|
|
31
|
+
click(): void;
|
|
32
|
+
addEventListener<K extends keyof HTMLElementEventMap>(type: K, listener: (this: HTMLElement, ev: HTMLElementEventMap[K]) => any, options?: boolean | AddEventListenerOptions | undefined): void;
|
|
33
|
+
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions | undefined): void;
|
|
34
|
+
removeEventListener<K_1 extends keyof HTMLElementEventMap>(type: K_1, listener: (this: HTMLElement, ev: HTMLElementEventMap[K_1]) => any, options?: boolean | EventListenerOptions | undefined): void;
|
|
35
|
+
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions | undefined): void;
|
|
36
|
+
readonly attributes: NamedNodeMap;
|
|
37
|
+
readonly classList: DOMTokenList;
|
|
38
|
+
className: string;
|
|
39
|
+
readonly clientHeight: number;
|
|
40
|
+
readonly clientLeft: number;
|
|
41
|
+
readonly clientTop: number;
|
|
42
|
+
readonly clientWidth: number;
|
|
43
|
+
id: string;
|
|
44
|
+
readonly localName: string;
|
|
45
|
+
readonly namespaceURI: string | null;
|
|
46
|
+
onfullscreenchange: ((this: Element, ev: Event) => any) | null;
|
|
47
|
+
onfullscreenerror: ((this: Element, ev: Event) => any) | null;
|
|
48
|
+
outerHTML: string;
|
|
49
|
+
readonly ownerDocument: Document;
|
|
50
|
+
readonly part: DOMTokenList;
|
|
51
|
+
readonly prefix: string | null;
|
|
52
|
+
readonly scrollHeight: number;
|
|
53
|
+
scrollLeft: number;
|
|
54
|
+
scrollTop: number;
|
|
55
|
+
readonly scrollWidth: number;
|
|
56
|
+
readonly shadowRoot: ShadowRoot | null;
|
|
57
|
+
slot: string;
|
|
58
|
+
readonly tagName: string;
|
|
59
|
+
attachShadow(init: ShadowRootInit): ShadowRoot;
|
|
60
|
+
closest<K_2 extends keyof HTMLElementTagNameMap>(selector: K_2): HTMLElementTagNameMap[K_2] | null;
|
|
61
|
+
closest<K_3 extends keyof SVGElementTagNameMap>(selector: K_3): SVGElementTagNameMap[K_3] | null;
|
|
62
|
+
closest<E extends Element = Element>(selectors: string): E | null;
|
|
63
|
+
getAttribute(qualifiedName: string): string | null;
|
|
64
|
+
getAttributeNS(namespace: string | null, localName: string): string | null;
|
|
65
|
+
getAttributeNames(): string[];
|
|
66
|
+
getAttributeNode(qualifiedName: string): Attr | null;
|
|
67
|
+
getAttributeNodeNS(namespace: string | null, localName: string): Attr | null;
|
|
68
|
+
getBoundingClientRect(): DOMRect;
|
|
69
|
+
getClientRects(): DOMRectList;
|
|
70
|
+
getElementsByClassName(classNames: string): HTMLCollectionOf<Element>;
|
|
71
|
+
getElementsByTagName<K_4 extends keyof HTMLElementTagNameMap>(qualifiedName: K_4): HTMLCollectionOf<HTMLElementTagNameMap[K_4]>;
|
|
72
|
+
getElementsByTagName<K_5 extends keyof SVGElementTagNameMap>(qualifiedName: K_5): HTMLCollectionOf<SVGElementTagNameMap[K_5]>;
|
|
73
|
+
getElementsByTagName(qualifiedName: string): HTMLCollectionOf<Element>;
|
|
74
|
+
getElementsByTagNameNS(namespaceURI: "http://www.w3.org/1999/xhtml", localName: string): HTMLCollectionOf<HTMLElement>;
|
|
75
|
+
getElementsByTagNameNS(namespaceURI: "http://www.w3.org/2000/svg", localName: string): HTMLCollectionOf<SVGElement>;
|
|
76
|
+
getElementsByTagNameNS(namespace: string | null, localName: string): HTMLCollectionOf<Element>;
|
|
77
|
+
hasAttribute(qualifiedName: string): boolean;
|
|
78
|
+
hasAttributeNS(namespace: string | null, localName: string): boolean;
|
|
79
|
+
hasAttributes(): boolean;
|
|
80
|
+
hasPointerCapture(pointerId: number): boolean;
|
|
81
|
+
insertAdjacentElement(where: InsertPosition, element: Element): Element | null;
|
|
82
|
+
insertAdjacentHTML(position: InsertPosition, text: string): void;
|
|
83
|
+
insertAdjacentText(where: InsertPosition, data: string): void;
|
|
84
|
+
matches(selectors: string): boolean;
|
|
85
|
+
releasePointerCapture(pointerId: number): void;
|
|
86
|
+
removeAttribute(qualifiedName: string): void;
|
|
87
|
+
removeAttributeNS(namespace: string | null, localName: string): void;
|
|
88
|
+
removeAttributeNode(attr: Attr): Attr;
|
|
89
|
+
requestFullscreen(options?: FullscreenOptions | undefined): Promise<void>;
|
|
90
|
+
requestPointerLock(): void;
|
|
91
|
+
scroll(options?: ScrollToOptions | undefined): void;
|
|
92
|
+
scroll(x: number, y: number): void;
|
|
93
|
+
scrollBy(options?: ScrollToOptions | undefined): void;
|
|
94
|
+
scrollBy(x: number, y: number): void;
|
|
95
|
+
scrollIntoView(arg?: boolean | ScrollIntoViewOptions | undefined): void;
|
|
96
|
+
scrollTo(options?: ScrollToOptions | undefined): void;
|
|
97
|
+
scrollTo(x: number, y: number): void;
|
|
98
|
+
setAttribute(qualifiedName: string, value: string): void;
|
|
99
|
+
setAttributeNS(namespace: string | null, qualifiedName: string, value: string): void;
|
|
100
|
+
setAttributeNode(attr: Attr): Attr | null;
|
|
101
|
+
setAttributeNodeNS(attr: Attr): Attr | null;
|
|
102
|
+
setPointerCapture(pointerId: number): void;
|
|
103
|
+
toggleAttribute(qualifiedName: string, force?: boolean | undefined): boolean;
|
|
104
|
+
webkitMatchesSelector(selectors: string): boolean;
|
|
105
|
+
readonly baseURI: string;
|
|
106
|
+
readonly childNodes: NodeListOf<ChildNode>;
|
|
107
|
+
readonly firstChild: ChildNode | null;
|
|
108
|
+
readonly isConnected: boolean;
|
|
109
|
+
readonly lastChild: ChildNode | null;
|
|
110
|
+
readonly nextSibling: ChildNode | null;
|
|
111
|
+
readonly nodeName: string;
|
|
112
|
+
readonly nodeType: number;
|
|
113
|
+
nodeValue: string | null;
|
|
114
|
+
readonly parentElement: HTMLElement | null;
|
|
115
|
+
readonly parentNode: ParentNode | null;
|
|
116
|
+
readonly previousSibling: ChildNode | null;
|
|
117
|
+
textContent: string | null;
|
|
118
|
+
appendChild<T_1 extends Node>(node: T_1): T_1;
|
|
119
|
+
cloneNode(deep?: boolean | undefined): Node;
|
|
120
|
+
compareDocumentPosition(other: Node): number;
|
|
121
|
+
contains(other: Node | null): boolean;
|
|
122
|
+
getRootNode(options?: GetRootNodeOptions | undefined): Node;
|
|
123
|
+
hasChildNodes(): boolean;
|
|
124
|
+
insertBefore<T_2 extends Node>(node: T_2, child: Node | null): T_2;
|
|
125
|
+
isDefaultNamespace(namespace: string | null): boolean;
|
|
126
|
+
isEqualNode(otherNode: Node | null): boolean;
|
|
127
|
+
isSameNode(otherNode: Node | null): boolean;
|
|
128
|
+
lookupNamespaceURI(prefix: string | null): string | null;
|
|
129
|
+
lookupPrefix(namespace: string | null): string | null;
|
|
130
|
+
normalize(): void;
|
|
131
|
+
removeChild<T_3 extends Node>(child: T_3): T_3;
|
|
132
|
+
replaceChild<T_4 extends Node>(node: Node, child: T_4): T_4;
|
|
133
|
+
readonly ATTRIBUTE_NODE: number;
|
|
134
|
+
readonly CDATA_SECTION_NODE: number;
|
|
135
|
+
readonly COMMENT_NODE: number;
|
|
136
|
+
readonly DOCUMENT_FRAGMENT_NODE: number;
|
|
137
|
+
readonly DOCUMENT_NODE: number;
|
|
138
|
+
readonly DOCUMENT_POSITION_CONTAINED_BY: number;
|
|
139
|
+
readonly DOCUMENT_POSITION_CONTAINS: number;
|
|
140
|
+
readonly DOCUMENT_POSITION_DISCONNECTED: number;
|
|
141
|
+
readonly DOCUMENT_POSITION_FOLLOWING: number;
|
|
142
|
+
readonly DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC: number;
|
|
143
|
+
readonly DOCUMENT_POSITION_PRECEDING: number;
|
|
144
|
+
readonly DOCUMENT_TYPE_NODE: number;
|
|
145
|
+
readonly ELEMENT_NODE: number;
|
|
146
|
+
readonly ENTITY_NODE: number;
|
|
147
|
+
readonly ENTITY_REFERENCE_NODE: number;
|
|
148
|
+
readonly NOTATION_NODE: number;
|
|
149
|
+
readonly PROCESSING_INSTRUCTION_NODE: number;
|
|
150
|
+
readonly TEXT_NODE: number;
|
|
151
|
+
dispatchEvent(event: Event): boolean;
|
|
152
|
+
ariaAtomic: string | null;
|
|
153
|
+
ariaAutoComplete: string | null;
|
|
154
|
+
ariaBusy: string | null;
|
|
155
|
+
ariaChecked: string | null;
|
|
156
|
+
ariaColCount: string | null;
|
|
157
|
+
ariaColIndex: string | null;
|
|
158
|
+
ariaColSpan: string | null;
|
|
159
|
+
ariaCurrent: string | null;
|
|
160
|
+
ariaDisabled: string | null;
|
|
161
|
+
ariaExpanded: string | null;
|
|
162
|
+
ariaHasPopup: string | null;
|
|
163
|
+
ariaHidden: string | null;
|
|
164
|
+
ariaKeyShortcuts: string | null;
|
|
165
|
+
ariaLabel: string | null;
|
|
166
|
+
ariaLevel: string | null;
|
|
167
|
+
ariaLive: string | null;
|
|
168
|
+
ariaModal: string | null;
|
|
169
|
+
ariaMultiLine: string | null;
|
|
170
|
+
ariaMultiSelectable: string | null;
|
|
171
|
+
ariaOrientation: string | null;
|
|
172
|
+
ariaPlaceholder: string | null;
|
|
173
|
+
ariaPosInSet: string | null;
|
|
174
|
+
ariaPressed: string | null;
|
|
175
|
+
ariaReadOnly: string | null;
|
|
176
|
+
ariaRequired: string | null;
|
|
177
|
+
ariaRoleDescription: string | null;
|
|
178
|
+
ariaRowCount: string | null;
|
|
179
|
+
ariaRowIndex: string | null;
|
|
180
|
+
ariaRowSpan: string | null;
|
|
181
|
+
ariaSelected: string | null;
|
|
182
|
+
ariaSetSize: string | null;
|
|
183
|
+
ariaSort: string | null;
|
|
184
|
+
ariaValueMax: string | null;
|
|
185
|
+
ariaValueMin: string | null;
|
|
186
|
+
ariaValueNow: string | null;
|
|
187
|
+
ariaValueText: string | null;
|
|
188
|
+
animate(keyframes: PropertyIndexedKeyframes | Keyframe[] | null, options?: number | KeyframeAnimationOptions | undefined): Animation;
|
|
189
|
+
getAnimations(options?: GetAnimationsOptions | undefined): Animation[];
|
|
190
|
+
after(...nodes: (string | Node)[]): void;
|
|
191
|
+
before(...nodes: (string | Node)[]): void;
|
|
192
|
+
remove(): void;
|
|
193
|
+
replaceWith(...nodes: (string | Node)[]): void;
|
|
194
|
+
innerHTML: string;
|
|
195
|
+
readonly nextElementSibling: Element | null;
|
|
196
|
+
readonly previousElementSibling: Element | null;
|
|
197
|
+
readonly childElementCount: number;
|
|
198
|
+
readonly children: HTMLCollection;
|
|
199
|
+
readonly firstElementChild: Element | null;
|
|
200
|
+
readonly lastElementChild: Element | null;
|
|
201
|
+
append(...nodes: (string | Node)[]): void;
|
|
202
|
+
prepend(...nodes: (string | Node)[]): void;
|
|
203
|
+
querySelector<K_6 extends keyof HTMLElementTagNameMap>(selectors: K_6): HTMLElementTagNameMap[K_6] | null;
|
|
204
|
+
querySelector<K_7 extends keyof SVGElementTagNameMap>(selectors: K_7): SVGElementTagNameMap[K_7] | null;
|
|
205
|
+
querySelector<E_1 extends Element = Element>(selectors: string): E_1 | null;
|
|
206
|
+
querySelectorAll<K_8 extends keyof HTMLElementTagNameMap>(selectors: K_8): NodeListOf<HTMLElementTagNameMap[K_8]>;
|
|
207
|
+
querySelectorAll<K_9 extends keyof SVGElementTagNameMap>(selectors: K_9): NodeListOf<SVGElementTagNameMap[K_9]>;
|
|
208
|
+
querySelectorAll<E_2 extends Element = Element>(selectors: string): NodeListOf<E_2>;
|
|
209
|
+
replaceChildren(...nodes: (string | Node)[]): void;
|
|
210
|
+
readonly assignedSlot: HTMLSlotElement | null;
|
|
211
|
+
oncopy: ((this: DocumentAndElementEventHandlers, ev: ClipboardEvent) => any) | null;
|
|
212
|
+
oncut: ((this: DocumentAndElementEventHandlers, ev: ClipboardEvent) => any) | null;
|
|
213
|
+
onpaste: ((this: DocumentAndElementEventHandlers, ev: ClipboardEvent) => any) | null;
|
|
214
|
+
readonly style: CSSStyleDeclaration;
|
|
215
|
+
contentEditable: string;
|
|
216
|
+
enterKeyHint: string;
|
|
217
|
+
inputMode: string;
|
|
218
|
+
readonly isContentEditable: boolean;
|
|
219
|
+
onabort: ((this: GlobalEventHandlers, ev: UIEvent) => any) | null;
|
|
220
|
+
onanimationcancel: ((this: GlobalEventHandlers, ev: AnimationEvent) => any) | null;
|
|
221
|
+
onanimationend: ((this: GlobalEventHandlers, ev: AnimationEvent) => any) | null;
|
|
222
|
+
onanimationiteration: ((this: GlobalEventHandlers, ev: AnimationEvent) => any) | null;
|
|
223
|
+
onanimationstart: ((this: GlobalEventHandlers, ev: AnimationEvent) => any) | null;
|
|
224
|
+
onauxclick: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null;
|
|
225
|
+
onblur: ((this: GlobalEventHandlers, ev: FocusEvent) => any) | null;
|
|
226
|
+
oncanplay: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
227
|
+
oncanplaythrough: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
228
|
+
onchange: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
229
|
+
onclick: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null;
|
|
230
|
+
onclose: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
231
|
+
oncontextmenu: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null;
|
|
232
|
+
oncuechange: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
233
|
+
ondblclick: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null;
|
|
234
|
+
ondrag: ((this: GlobalEventHandlers, ev: DragEvent) => any) | null;
|
|
235
|
+
ondragend: ((this: GlobalEventHandlers, ev: DragEvent) => any) | null;
|
|
236
|
+
ondragenter: ((this: GlobalEventHandlers, ev: DragEvent) => any) | null;
|
|
237
|
+
ondragleave: ((this: GlobalEventHandlers, ev: DragEvent) => any) | null;
|
|
238
|
+
ondragover: ((this: GlobalEventHandlers, ev: DragEvent) => any) | null;
|
|
239
|
+
ondragstart: ((this: GlobalEventHandlers, ev: DragEvent) => any) | null;
|
|
240
|
+
ondrop: ((this: GlobalEventHandlers, ev: DragEvent) => any) | null;
|
|
241
|
+
ondurationchange: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
242
|
+
onemptied: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
243
|
+
onended: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
244
|
+
onerror: OnErrorEventHandler;
|
|
245
|
+
onfocus: ((this: GlobalEventHandlers, ev: FocusEvent) => any) | null;
|
|
246
|
+
onformdata: ((this: GlobalEventHandlers, ev: FormDataEvent) => any) | null;
|
|
247
|
+
ongotpointercapture: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null;
|
|
248
|
+
oninput: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
249
|
+
oninvalid: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
250
|
+
onkeydown: ((this: GlobalEventHandlers, ev: KeyboardEvent) => any) | null;
|
|
251
|
+
onkeypress: ((this: GlobalEventHandlers, ev: KeyboardEvent) => any) | null;
|
|
252
|
+
onkeyup: ((this: GlobalEventHandlers, ev: KeyboardEvent) => any) | null;
|
|
253
|
+
onload: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
254
|
+
onloadeddata: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
255
|
+
onloadedmetadata: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
256
|
+
onloadstart: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
257
|
+
onlostpointercapture: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null;
|
|
258
|
+
onmousedown: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null;
|
|
259
|
+
onmouseenter: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null;
|
|
260
|
+
onmouseleave: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null;
|
|
261
|
+
onmousemove: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null;
|
|
262
|
+
onmouseout: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null;
|
|
263
|
+
onmouseover: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null;
|
|
264
|
+
onmouseup: ((this: GlobalEventHandlers, ev: MouseEvent) => any) | null;
|
|
265
|
+
onpause: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
266
|
+
onplay: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
267
|
+
onplaying: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
268
|
+
onpointercancel: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null;
|
|
269
|
+
onpointerdown: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null;
|
|
270
|
+
onpointerenter: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null;
|
|
271
|
+
onpointerleave: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null;
|
|
272
|
+
onpointermove: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null;
|
|
273
|
+
onpointerout: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null;
|
|
274
|
+
onpointerover: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null;
|
|
275
|
+
onpointerup: ((this: GlobalEventHandlers, ev: PointerEvent) => any) | null;
|
|
276
|
+
onprogress: ((this: GlobalEventHandlers, ev: ProgressEvent<EventTarget>) => any) | null;
|
|
277
|
+
onratechange: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
278
|
+
onreset: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
279
|
+
onresize: ((this: GlobalEventHandlers, ev: UIEvent) => any) | null;
|
|
280
|
+
onscroll: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
281
|
+
onsecuritypolicyviolation: ((this: GlobalEventHandlers, ev: SecurityPolicyViolationEvent) => any) | null;
|
|
282
|
+
onseeked: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
283
|
+
onseeking: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
284
|
+
onselect: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
285
|
+
onselectionchange: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
286
|
+
onselectstart: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
287
|
+
onslotchange: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
288
|
+
onstalled: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
289
|
+
onsubmit: ((this: GlobalEventHandlers, ev: SubmitEvent) => any) | null;
|
|
290
|
+
onsuspend: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
291
|
+
ontimeupdate: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
292
|
+
ontoggle: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
293
|
+
ontouchcancel?: ((this: GlobalEventHandlers, ev: TouchEvent) => any) | null | undefined;
|
|
294
|
+
ontouchend?: ((this: GlobalEventHandlers, ev: TouchEvent) => any) | null | undefined;
|
|
295
|
+
ontouchmove?: ((this: GlobalEventHandlers, ev: TouchEvent) => any) | null | undefined;
|
|
296
|
+
ontouchstart?: ((this: GlobalEventHandlers, ev: TouchEvent) => any) | null | undefined;
|
|
297
|
+
ontransitioncancel: ((this: GlobalEventHandlers, ev: TransitionEvent) => any) | null;
|
|
298
|
+
ontransitionend: ((this: GlobalEventHandlers, ev: TransitionEvent) => any) | null;
|
|
299
|
+
ontransitionrun: ((this: GlobalEventHandlers, ev: TransitionEvent) => any) | null;
|
|
300
|
+
ontransitionstart: ((this: GlobalEventHandlers, ev: TransitionEvent) => any) | null;
|
|
301
|
+
onvolumechange: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
302
|
+
onwaiting: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
303
|
+
onwebkitanimationend: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
304
|
+
onwebkitanimationiteration: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
305
|
+
onwebkitanimationstart: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
306
|
+
onwebkittransitionend: ((this: GlobalEventHandlers, ev: Event) => any) | null;
|
|
307
|
+
onwheel: ((this: GlobalEventHandlers, ev: WheelEvent) => any) | null;
|
|
308
|
+
autofocus: boolean;
|
|
309
|
+
readonly dataset: DOMStringMap;
|
|
310
|
+
nonce?: string | undefined;
|
|
311
|
+
tabIndex: number;
|
|
312
|
+
blur(): void;
|
|
313
|
+
focus(options?: FocusOptions | undefined): void;
|
|
314
|
+
};
|
|
315
|
+
inject?: ProviderToken<any>[] | undefined;
|
|
316
|
+
providers?: Provider<any>[] | undefined;
|
|
317
|
+
} & T;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Injector } from '../injector';
|
|
2
|
+
import { environment } from './environment';
|
|
3
|
+
export function injectable(CustomElement) {
|
|
4
|
+
const { inject, providers } = CustomElement;
|
|
5
|
+
return class InjectableElement extends CustomElement {
|
|
6
|
+
constructor(...args) {
|
|
7
|
+
const injector = new Injector(providers, environment());
|
|
8
|
+
if (args.length || !inject) {
|
|
9
|
+
super(...args);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
super(...inject.map((dep) => () => injector.get(dep)));
|
|
13
|
+
}
|
|
14
|
+
this.injector = injector;
|
|
15
|
+
this.addEventListener('finddiroot', (e) => {
|
|
16
|
+
const parentInjector = findInjectorRoot(e);
|
|
17
|
+
if (parentInjector) {
|
|
18
|
+
this.injector.parent = parentInjector;
|
|
19
|
+
}
|
|
20
|
+
if (super.connectedCallback) {
|
|
21
|
+
super.connectedCallback();
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
connectedCallback() {
|
|
26
|
+
// only mark as an injector root if element defines providers
|
|
27
|
+
if (providers) {
|
|
28
|
+
this.setAttribute('joist-injector-root', 'true');
|
|
29
|
+
}
|
|
30
|
+
this.dispatchEvent(new Event('finddiroot'));
|
|
31
|
+
}
|
|
32
|
+
disconnectedCallback() {
|
|
33
|
+
delete this.injector.parent;
|
|
34
|
+
if (super.disconnectedCallback) {
|
|
35
|
+
super.disconnectedCallback();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function findInjectorRoot(e) {
|
|
41
|
+
const path = e.composedPath();
|
|
42
|
+
const parentInjector = path.find((el) => {
|
|
43
|
+
return el instanceof HTMLElement && el !== e.target && el.hasAttribute('joist-injector-root');
|
|
44
|
+
});
|
|
45
|
+
if (parentInjector) {
|
|
46
|
+
return Reflect.get(parentInjector, 'injector');
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
@@ -1,30 +1,13 @@
|
|
|
1
1
|
import { ProviderToken, Provider, ClassProviderToken } from './provider';
|
|
2
|
-
export
|
|
3
|
-
providers?: Provider<any>[];
|
|
4
|
-
bootstrap?: ProviderToken<any>[];
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Create an instance of a Dependency injector.
|
|
8
|
-
* Can be used to create a singleton of any class that is property annotated with dependencies.
|
|
9
|
-
*
|
|
10
|
-
* @param options configuration options for the current instance of Injector
|
|
11
|
-
* @param parent a parent instance of Injector
|
|
12
|
-
*/
|
|
2
|
+
export declare type Injected<T> = () => T;
|
|
13
3
|
export declare class Injector {
|
|
14
|
-
|
|
4
|
+
providers: Provider<any>[];
|
|
15
5
|
parent?: Injector | undefined;
|
|
16
|
-
|
|
17
|
-
constructor(
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* recursively check if a singleton instance is available for a provider
|
|
21
|
-
*/
|
|
22
|
-
has(token: ProviderToken<any>): boolean;
|
|
23
|
-
/**
|
|
24
|
-
* fetches a singleton instance of a provider
|
|
25
|
-
*/
|
|
6
|
+
instances: WeakMap<ProviderToken<any>, any>;
|
|
7
|
+
constructor(providers?: Provider<any>[], parent?: Injector | undefined);
|
|
8
|
+
has<T>(token: ProviderToken<T>): boolean;
|
|
26
9
|
get<T>(token: ProviderToken<T>): T;
|
|
27
10
|
create<T>(P: ClassProviderToken<T>): T;
|
|
28
|
-
private
|
|
11
|
+
private createAndCache;
|
|
29
12
|
private findProvider;
|
|
30
13
|
}
|
|
@@ -1,72 +1,56 @@
|
|
|
1
1
|
import { readProviderDeps, isProvidedInRoot } from './utils';
|
|
2
|
-
/**
|
|
3
|
-
* Create an instance of a Dependency injector.
|
|
4
|
-
* Can be used to create a singleton of any class that is property annotated with dependencies.
|
|
5
|
-
*
|
|
6
|
-
* @param options configuration options for the current instance of Injector
|
|
7
|
-
* @param parent a parent instance of Injector
|
|
8
|
-
*/
|
|
9
2
|
export class Injector {
|
|
10
|
-
constructor(
|
|
11
|
-
this.
|
|
12
|
-
this.parent = parent;
|
|
13
|
-
this.providerMap = new WeakMap();
|
|
14
|
-
if (this.options.bootstrap) {
|
|
15
|
-
this.options.bootstrap.forEach((provider) => this.get(provider));
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
setParent(parent) {
|
|
3
|
+
constructor(providers = [], parent) {
|
|
4
|
+
this.providers = providers;
|
|
19
5
|
this.parent = parent;
|
|
6
|
+
this.instances = new WeakMap();
|
|
20
7
|
}
|
|
21
|
-
/**
|
|
22
|
-
* recursively check if a singleton instance is available for a provider
|
|
23
|
-
*/
|
|
24
8
|
has(token) {
|
|
25
|
-
|
|
9
|
+
const hasLocally = this.instances.has(token) || !!this.findProvider(token);
|
|
10
|
+
if (hasLocally) {
|
|
26
11
|
return true;
|
|
27
12
|
}
|
|
28
|
-
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
else if (this.parent) {
|
|
32
|
-
return this.parent.has(token);
|
|
33
|
-
}
|
|
34
|
-
return false;
|
|
13
|
+
return this.parent ? this.parent.has(token) : false;
|
|
35
14
|
}
|
|
36
|
-
/**
|
|
37
|
-
* fetches a singleton instance of a provider
|
|
38
|
-
*/
|
|
39
15
|
get(token) {
|
|
40
|
-
|
|
41
|
-
|
|
16
|
+
// check for a local instance
|
|
17
|
+
if (this.instances.has(token)) {
|
|
18
|
+
return this.instances.get(token);
|
|
42
19
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
20
|
+
const provider = this.findProvider(token);
|
|
21
|
+
// check for a provider definition
|
|
22
|
+
if (provider) {
|
|
23
|
+
if ('use' in provider) {
|
|
24
|
+
return this.createAndCache(provider.use);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
return this.createAndCache(provider);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
// check for a parent and attempt to get there
|
|
31
|
+
if (this.parent) {
|
|
32
|
+
if (this.parent.has(token) || isProvidedInRoot(token)) {
|
|
33
|
+
return this.parent.get(token);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
// If nothing else treat as a local class provider
|
|
37
|
+
return this.createAndCache(token);
|
|
46
38
|
}
|
|
47
39
|
create(P) {
|
|
48
40
|
const deps = readProviderDeps(P);
|
|
49
|
-
return new P(...deps.map((dep) => this.get(dep)));
|
|
41
|
+
return new P(...deps.map((dep) => () => this.get(dep)));
|
|
50
42
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
// If provider is defined in current scope use that implementation
|
|
56
|
-
return this.create(provider.use);
|
|
57
|
-
}
|
|
58
|
-
if (this.parent && (isProvidedInRoot(token) || this.parent.has(token))) {
|
|
59
|
-
// if a parent is available and contains an instance of the provider already use that
|
|
60
|
-
return this.parent.get(token);
|
|
61
|
-
}
|
|
62
|
-
// if nothing else found assume ClassProviderToken
|
|
63
|
-
return this.create(token);
|
|
43
|
+
createAndCache(token) {
|
|
44
|
+
const instance = this.create(token);
|
|
45
|
+
this.instances.set(token, instance);
|
|
46
|
+
return instance;
|
|
64
47
|
}
|
|
65
48
|
findProvider(token) {
|
|
66
|
-
if (!this.
|
|
49
|
+
if (!this.providers) {
|
|
67
50
|
return undefined;
|
|
68
51
|
}
|
|
69
|
-
return this.
|
|
52
|
+
return this.providers.find((provider) => {
|
|
53
|
+
return provider === token || provider.provide === token;
|
|
54
|
+
});
|
|
70
55
|
}
|
|
71
56
|
}
|
|
72
|
-
//# sourceMappingURL=injector.js.map
|
|
@@ -7,7 +7,8 @@ export declare type AbstractClassProviderToken<T> = Function & {
|
|
|
7
7
|
[key: string]: any;
|
|
8
8
|
};
|
|
9
9
|
export declare type ProviderToken<T> = ClassProviderToken<T> | AbstractClassProviderToken<T>;
|
|
10
|
-
export interface
|
|
10
|
+
export interface ProviderDef<T> {
|
|
11
11
|
provide: ProviderToken<T>;
|
|
12
12
|
use: ClassProviderToken<T>;
|
|
13
13
|
}
|
|
14
|
+
export declare type Provider<T> = ProviderDef<T> | ClassProviderToken<T>;
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
export function service(provider) {
|
|
2
|
-
Object.defineProperty(provider, 'provideInRoot', {
|
|
2
|
+
Object.defineProperty(provider, 'provideInRoot', {
|
|
3
|
+
get() {
|
|
4
|
+
return true;
|
|
5
|
+
},
|
|
6
|
+
enumerable: false,
|
|
7
|
+
configurable: false,
|
|
8
|
+
});
|
|
3
9
|
return provider;
|
|
4
10
|
}
|
|
5
|
-
//# sourceMappingURL=service.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { ProviderToken } from './provider';
|
|
2
|
-
export declare const PROVIDER_DEPS_KEY = "
|
|
2
|
+
export declare const PROVIDER_DEPS_KEY = "inject";
|
|
3
3
|
export declare function readProviderDeps(provider: ProviderToken<any>): ProviderToken<any>[];
|
|
4
4
|
export declare function isProvidedInRoot(provider: ProviderToken<any>): any;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
export const PROVIDER_DEPS_KEY = '
|
|
1
|
+
export const PROVIDER_DEPS_KEY = 'inject';
|
|
2
2
|
export function readProviderDeps(provider) {
|
|
3
3
|
return provider[PROVIDER_DEPS_KEY] || provider.prototype[PROVIDER_DEPS_KEY] || [];
|
|
4
4
|
}
|
|
5
5
|
export function isProvidedInRoot(provider) {
|
|
6
6
|
return provider.provideInRoot || false;
|
|
7
7
|
}
|
|
8
|
-
//# sourceMappingURL=utils.js.map
|
package/target/build/lib.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
export { Injector,
|
|
2
|
-
export { Provider, ProviderToken } from './lib/provider';
|
|
1
|
+
export { Injector, Injected } from './lib/injector';
|
|
2
|
+
export { ProviderDef, Provider, ProviderToken } from './lib/provider';
|
|
3
3
|
export { readProviderDeps } from './lib/utils';
|
|
4
4
|
export { service } from './lib/service';
|
|
5
|
-
export { getEnvironmentRef, defineEnvironment } from './lib/environment';
|
|
6
|
-
export { injectable } from './lib/injectable';
|
package/target/build/lib.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
1
|
export { Injector } from './lib/injector';
|
|
2
2
|
export { readProviderDeps } from './lib/utils';
|
|
3
3
|
export { service } from './lib/service';
|
|
4
|
-
export { getEnvironmentRef, defineEnvironment } from './lib/environment';
|
|
5
|
-
export { injectable } from './lib/injectable';
|
|
6
|
-
//# sourceMappingURL=lib.js.map
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { Injector } from './injector';
|
|
2
|
-
import { Provider } from './provider';
|
|
3
|
-
export declare function defineEnvironment(providers?: Provider<any>[]): Injector;
|
|
4
|
-
export declare function getEnvironmentRef(): Injector;
|
|
5
|
-
export declare function clearEnvironment(): void;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Injector } from './injector';
|
|
2
|
-
let rootInjector = null;
|
|
3
|
-
export function defineEnvironment(providers = []) {
|
|
4
|
-
rootInjector = new Injector({ providers });
|
|
5
|
-
return rootInjector;
|
|
6
|
-
}
|
|
7
|
-
export function getEnvironmentRef() {
|
|
8
|
-
if (rootInjector) {
|
|
9
|
-
return rootInjector;
|
|
10
|
-
}
|
|
11
|
-
return defineEnvironment();
|
|
12
|
-
}
|
|
13
|
-
export function clearEnvironment() {
|
|
14
|
-
rootInjector = null;
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=environment.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"environment.js","sourceRoot":"","sources":["../../../lib/environment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGtC,IAAI,YAAY,GAAoB,IAAI,CAAC;AAEzC,MAAM,UAAU,iBAAiB,CAAC,YAA6B,EAAE;IAC/D,YAAY,GAAG,IAAI,QAAQ,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC;IAE3C,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,MAAM,UAAU,iBAAiB;IAC/B,IAAI,YAAY,EAAE;QAChB,OAAO,YAAY,CAAC;KACrB;IAED,OAAO,iBAAiB,EAAE,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,gBAAgB;IAC9B,YAAY,GAAG,IAAI,CAAC;AACtB,CAAC"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Provider, ProviderToken } from './provider';
|
|
2
|
-
export interface Injectable {
|
|
3
|
-
deps: ProviderToken<any>[];
|
|
4
|
-
providers?: Provider<any>[];
|
|
5
|
-
new (...args: any[]): any;
|
|
6
|
-
}
|
|
7
|
-
export declare function injectable<T extends Injectable>(Clazz: T): {
|
|
8
|
-
new (...args: any[]): {
|
|
9
|
-
[x: string]: any;
|
|
10
|
-
};
|
|
11
|
-
deps: ProviderToken<any>[];
|
|
12
|
-
providers?: Provider<any>[] | undefined;
|
|
13
|
-
} & T;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { getEnvironmentRef } from './environment';
|
|
2
|
-
import { Injector } from './injector';
|
|
3
|
-
export function injectable(Clazz) {
|
|
4
|
-
const { deps, providers } = Clazz;
|
|
5
|
-
return class InjectableElement extends Clazz {
|
|
6
|
-
constructor(...args) {
|
|
7
|
-
if (args.length || !deps.length) {
|
|
8
|
-
super(...args);
|
|
9
|
-
}
|
|
10
|
-
else {
|
|
11
|
-
const i = new Injector({ providers }, getEnvironmentRef());
|
|
12
|
-
super(...deps.map((dep) => i.get(dep)));
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=injectable.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"injectable.js","sourceRoot":"","sources":["../../../lib/injectable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAUtC,MAAM,UAAU,UAAU,CAAuB,KAAQ;IACvD,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,KAAK,CAAC;IAElC,OAAO,MAAM,iBAAkB,SAAQ,KAAK;QAC1C,YAAY,GAAG,IAAW;YACxB,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;gBAC/B,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;aAChB;iBAAM;gBACL,MAAM,CAAC,GAAG,IAAI,QAAQ,CAAC,EAAE,SAAS,EAAE,EAAE,iBAAiB,EAAE,CAAC,CAAC;gBAE3D,KAAK,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;aACzC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"injector.js","sourceRoot":"","sources":["../../../lib/injector.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAO7D;;;;;;GAMG;AACH,MAAM,OAAO,QAAQ;IAGnB,YAAmB,UAA2B,EAAE,EAAS,MAAiB;QAAvD,YAAO,GAAP,OAAO,CAAsB;QAAS,WAAM,GAAN,MAAM,CAAW;QAFlE,gBAAW,GAAG,IAAI,OAAO,EAA2B,CAAC;QAG3D,IAAI,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE;YAC1B,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC;SAClE;IACH,CAAC;IAED,SAAS,CAAC,MAAiB;QACzB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,GAAG,CAAC,KAAyB;QAC3B,IAAI,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;YAC/B,OAAO,IAAI,CAAC;SACb;aAAM,IAAI,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE;YACnC,OAAO,IAAI,CAAC;SACb;aAAM,IAAI,IAAI,CAAC,MAAM,EAAE;YACtB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;SAC/B;QAED,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;OAEG;IACH,GAAG,CAAI,KAAuB;QAC5B,IAAI,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;YAC/B,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;SACpC;QAED,IAAI,QAAQ,GAAM,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QAEtC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAEtC,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,MAAM,CAAI,CAAwB;QAChC,MAAM,IAAI,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC;QAEjC,OAAO,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACpD,CAAC;IAEO,OAAO,CAAI,KAAuB;QACxC,uDAAuD;QACvD,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;QAE1C,IAAI,QAAQ,EAAE;YACZ,kEAAkE;YAClE,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;SAClC;QAED,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE;YACtE,qFAAqF;YACrF,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;SAC/B;QAED,kDAAkD;QAClD,OAAO,IAAI,CAAC,MAAM,CAAC,KAA8B,CAAC,CAAC;IACrD,CAAC;IAEO,YAAY,CAAC,KAAyB;QAC5C,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE;YAC3B,OAAO,SAAS,CAAC;SAClB;QAED,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,KAAK,KAAK,CAAC,CAAC;IAC/E,CAAC;CACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../lib/provider.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../../lib/service.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,OAAO,CAAC,QAA4B;IAClD,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,eAAe,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAElE,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../lib/utils.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC;AAExC,MAAM,UAAU,gBAAgB,CAAC,QAA4B;IAC3D,OAAO,QAAQ,CAAC,iBAAiB,CAAC,IAAI,QAAQ,CAAC,SAAS,CAAC,iBAAiB,CAAC,IAAI,EAAE,CAAC;AACpF,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,QAA4B;IAC3D,OAAO,QAAQ,CAAC,aAAa,IAAI,KAAK,CAAC;AACzC,CAAC"}
|
package/target/build/lib.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lib.js","sourceRoot":"","sources":["../../lib.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAmB,MAAM,gBAAgB,CAAC;AAE3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC"}
|