@armscye/container 0.3.0 → 0.4.0
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 +164 -1
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @armscye/container
|
|
2
2
|
|
|
3
|
-
> A collection of shared standard TypeScript definitions.
|
|
3
|
+
> A collection of shared standard TypeScript definitions (@container).
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -15,3 +15,166 @@ or using yarn:
|
|
|
15
15
|
```sh
|
|
16
16
|
yarn add @armscye/container --dev
|
|
17
17
|
```
|
|
18
|
+
|
|
19
|
+
## Reference
|
|
20
|
+
|
|
21
|
+
### ClassProvider `Interface`
|
|
22
|
+
|
|
23
|
+
Configures the `Container` to return an instance of `useClass` for a token.
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
interface ClassProvider<T = any> {
|
|
27
|
+
provide: ProviderToken;
|
|
28
|
+
|
|
29
|
+
useClass: NoArgument<T>;
|
|
30
|
+
|
|
31
|
+
shared?: boolean;
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
**Properties**
|
|
36
|
+
|
|
37
|
+
| Property | Description |
|
|
38
|
+
| ------------------------- | ------------------------------------------ |
|
|
39
|
+
| provide: ProviderToken | A provider token. |
|
|
40
|
+
| useClass: NoArgument<any> | A class to instantiate for the `token`. |
|
|
41
|
+
| shared?: boolean | When true, the created instance is cached. |
|
|
42
|
+
|
|
43
|
+
### Container `Interface`
|
|
44
|
+
|
|
45
|
+
Describes the interface of a container that exposes methods to read its entries.
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
interface Container {
|
|
49
|
+
get<T>(token: ProviderToken): T;
|
|
50
|
+
|
|
51
|
+
has(token: ProviderToken): boolean;
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
**Methods**
|
|
56
|
+
|
|
57
|
+
get(token: ProviderToken): T
|
|
58
|
+
|
|
59
|
+
Retrieves an entry from the container based on its provider token.
|
|
60
|
+
|
|
61
|
+
_Parameters_
|
|
62
|
+
|
|
63
|
+
- `token`: The unique identifier of the entry to retrieve.
|
|
64
|
+
|
|
65
|
+
_Returns_
|
|
66
|
+
|
|
67
|
+
The entry associated with the provided token, if found.
|
|
68
|
+
|
|
69
|
+
_Throws_
|
|
70
|
+
|
|
71
|
+
`Error` if the entry doesn't exist or an error occurs during retrieval.
|
|
72
|
+
|
|
73
|
+
has(token: ProviderToken): boolean
|
|
74
|
+
|
|
75
|
+
Checks whether an entry for a specific provider token exists in the container.
|
|
76
|
+
|
|
77
|
+
_Parameters_
|
|
78
|
+
|
|
79
|
+
`token`: The unique identifier of the entry to check for.
|
|
80
|
+
|
|
81
|
+
_Returns_
|
|
82
|
+
|
|
83
|
+
`true` if an entry for the provided token exists, `false` otherwise.
|
|
84
|
+
|
|
85
|
+
### ExistingProvider `Interface`
|
|
86
|
+
|
|
87
|
+
Configures the `Container` to return a value of another `useExisting` token.
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
interface ExistingProvider<T = any> {
|
|
91
|
+
provide: ProviderToken;
|
|
92
|
+
|
|
93
|
+
useExisting: T;
|
|
94
|
+
|
|
95
|
+
shared?: boolean;
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
**Properties**
|
|
100
|
+
|
|
101
|
+
| Property | Description |
|
|
102
|
+
| -------------------------- | ------------------------------------------ |
|
|
103
|
+
| provide: ProviderToken | A provider token. |
|
|
104
|
+
| useExisting: ProviderToken | Existing `token` to return. |
|
|
105
|
+
| shared?: boolean | When true, the created instance is cached. |
|
|
106
|
+
|
|
107
|
+
### FactoryProvider `Interface`
|
|
108
|
+
|
|
109
|
+
Configures the `Container` to return a value by invoking a `useFactory` function.
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
interface FactoryProvider<T = any> {
|
|
113
|
+
provide: ProviderToken;
|
|
114
|
+
|
|
115
|
+
useFactory: Factory<T>;
|
|
116
|
+
|
|
117
|
+
shared?: boolean;
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
**Properties**
|
|
122
|
+
|
|
123
|
+
| Property | Description |
|
|
124
|
+
| ---------------------- | ----------------------------------------------------------------- |
|
|
125
|
+
| provide: ProviderToken | A provider token. |
|
|
126
|
+
| useFactory: Factory | A factory function to invoke to create an object for the `token`. |
|
|
127
|
+
| shared?: boolean | When true, the created instance is cached. |
|
|
128
|
+
|
|
129
|
+
### Factory `Type`
|
|
130
|
+
|
|
131
|
+
A function to invoke to create an object. The function is invoked with an instance of the container in order to access required dependencies.
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
type Factory<T = any> = (container: Container) => T;
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### ProviderToken `Type`
|
|
138
|
+
|
|
139
|
+
Token that can be used to retrieve an instance from a container.
|
|
140
|
+
|
|
141
|
+
```ts
|
|
142
|
+
type ProviderToken = string | symbol;
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Provider `Type`
|
|
146
|
+
|
|
147
|
+
Describes how the `Container` should be configured.
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
type Provider<T = any> =
|
|
151
|
+
| ValueProvider<T>
|
|
152
|
+
| ClassProvider<T>
|
|
153
|
+
| FactoryProvider<T>
|
|
154
|
+
| ExistingProvider<T>;
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### ValueProvider `Interface`
|
|
158
|
+
|
|
159
|
+
Configures the `Container` to return a value for a token.
|
|
160
|
+
|
|
161
|
+
```ts
|
|
162
|
+
interface ValueProvider<T = any> {
|
|
163
|
+
provide: ProviderToken;
|
|
164
|
+
|
|
165
|
+
useValue: T;
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
**Properties**
|
|
170
|
+
|
|
171
|
+
| Property | Description |
|
|
172
|
+
| ---------------------- | ----------------------------------------------------------- |
|
|
173
|
+
| provide: ProviderToken | A provider token. |
|
|
174
|
+
| useValue: any | The actual value that will be provided for the given token. |
|
|
175
|
+
|
|
176
|
+
## License
|
|
177
|
+
|
|
178
|
+
This project is licensed under the **MIT license**.
|
|
179
|
+
|
|
180
|
+
See [LICENSE](LICENSE) for more information.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@armscye/container",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "A collection of shared standard TypeScript definitions",
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "A collection of shared standard TypeScript definitions (@container)",
|
|
5
5
|
"author": "Augustus Kamau",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -11,10 +11,11 @@
|
|
|
11
11
|
"keywords": [
|
|
12
12
|
"armscye",
|
|
13
13
|
"typescript",
|
|
14
|
-
"types"
|
|
14
|
+
"types",
|
|
15
|
+
"container"
|
|
15
16
|
],
|
|
16
17
|
"dependencies": {
|
|
17
|
-
"@armscye/core": "^0.
|
|
18
|
+
"@armscye/core": "^0.3.0"
|
|
18
19
|
},
|
|
19
20
|
"homepage": "https://github.com/armscye/armscye#readme",
|
|
20
21
|
"repository": {
|
|
@@ -27,5 +28,5 @@
|
|
|
27
28
|
"publishConfig": {
|
|
28
29
|
"access": "public"
|
|
29
30
|
},
|
|
30
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "a26e3829ccbd43eae0ab1a1dd165af7ae7b355c1"
|
|
31
32
|
}
|