ditox 2.1.0 → 2.3.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/dist/browser/index.d.ts +24 -88
- package/dist/browser/index.js +1 -1
- package/dist/browser/index.js.map +1 -1
- package/dist/cjs/ditox.d.ts +9 -9
- package/dist/cjs/index.d.ts +0 -1
- package/dist/cjs/index.js +1 -6
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/modules.d.ts +10 -15
- package/dist/cjs/modules.js +1 -2
- package/dist/cjs/modules.js.map +1 -1
- package/dist/cjs/utils.d.ts +2 -2
- package/dist/esm/ditox.d.ts +9 -9
- package/dist/esm/index.d.ts +0 -1
- package/dist/esm/index.js +0 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/modules.d.ts +10 -15
- package/dist/esm/modules.js +1 -2
- package/dist/esm/modules.js.map +1 -1
- package/dist/esm/utils.d.ts +2 -2
- package/dist/umd/index.d.ts +24 -88
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.map +1 -1
- package/docs/README.md +207 -388
- package/docs/classes/ResolverError.md +19 -17
- package/package.json +2 -2
- package/src/index.ts +0 -7
- package/src/modules.ts +4 -9
- package/dist/cjs/utils-deprecated.d.ts +0 -59
- package/dist/cjs/utils-deprecated.js +0 -66
- package/dist/cjs/utils-deprecated.js.map +0 -1
- package/dist/esm/utils-deprecated.d.ts +0 -59
- package/dist/esm/utils-deprecated.js +0 -59
- package/dist/esm/utils-deprecated.js.map +0 -1
- package/src/utils-deprecated.test.ts +0 -286
- package/src/utils-deprecated.ts +0 -87
package/docs/README.md
CHANGED
|
@@ -8,7 +8,7 @@ ditox
|
|
|
8
8
|
|
|
9
9
|
- [ResolverError](classes/ResolverError.md)
|
|
10
10
|
|
|
11
|
-
### Type
|
|
11
|
+
### Type Aliases
|
|
12
12
|
|
|
13
13
|
- [BindModuleOptions](README.md#bindmoduleoptions)
|
|
14
14
|
- [Container](README.md#container)
|
|
@@ -27,21 +27,17 @@ ditox
|
|
|
27
27
|
- [createContainer](README.md#createcontainer)
|
|
28
28
|
- [declareModule](README.md#declaremodule)
|
|
29
29
|
- [declareModuleBindings](README.md#declaremodulebindings)
|
|
30
|
-
- [getProps](README.md#getprops)
|
|
31
|
-
- [getValues](README.md#getvalues)
|
|
32
30
|
- [injectable](README.md#injectable)
|
|
33
31
|
- [injectableClass](README.md#injectableclass)
|
|
34
|
-
- [injectableProps](README.md#injectableprops)
|
|
35
32
|
- [isToken](README.md#istoken)
|
|
36
33
|
- [optional](README.md#optional)
|
|
37
|
-
- [resolveProps](README.md#resolveprops)
|
|
38
34
|
- [resolveValue](README.md#resolvevalue)
|
|
39
35
|
- [resolveValues](README.md#resolvevalues)
|
|
40
|
-
- [token](README.md#token)
|
|
36
|
+
- [token](README.md#token-1)
|
|
41
37
|
- [tryResolveValue](README.md#tryresolvevalue)
|
|
42
38
|
- [tryResolveValues](README.md#tryresolvevalues)
|
|
43
39
|
|
|
44
|
-
## Type
|
|
40
|
+
## Type Aliases
|
|
45
41
|
|
|
46
42
|
### BindModuleOptions
|
|
47
43
|
|
|
@@ -50,20 +46,21 @@ ditox
|
|
|
50
46
|
Options for module binding.
|
|
51
47
|
|
|
52
48
|
`scope` types:
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
|
|
50
|
+
- `singleton` - **This is the default**. The module is created and cached by the container which registered the factory.
|
|
51
|
+
- `scoped` - The module is created and cached by the container which starts resolving.
|
|
55
52
|
|
|
56
53
|
#### Type declaration
|
|
57
54
|
|
|
58
|
-
| Name
|
|
59
|
-
|
|
|
60
|
-
| `scope?` |
|
|
55
|
+
| Name | Type |
|
|
56
|
+
| :------- | :-------------------------- |
|
|
57
|
+
| `scope?` | `"scoped"` \| `"singleton"` |
|
|
61
58
|
|
|
62
59
|
#### Defined in
|
|
63
60
|
|
|
64
|
-
[packages/ditox/src/modules.ts:
|
|
61
|
+
[packages/ditox/src/modules.ts:78](https://github.com/mnasyrov/ditox/blob/37f658c/packages/ditox/src/modules.ts#L78)
|
|
65
62
|
|
|
66
|
-
|
|
63
|
+
---
|
|
67
64
|
|
|
68
65
|
### Container
|
|
69
66
|
|
|
@@ -73,58 +70,61 @@ Dependency container.
|
|
|
73
70
|
|
|
74
71
|
#### Type declaration
|
|
75
72
|
|
|
76
|
-
| Name
|
|
77
|
-
|
|
|
73
|
+
| Name | Type |
|
|
74
|
+
| :------------ | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
78
75
|
| `bindFactory` | <T\>(`token`: [`Token`](README.md#token)<`T`\>, `factory`: (`container`: [`Container`](README.md#container)) => `T`, `options?`: [`FactoryOptions`](README.md#factoryoptions)<`T`\>) => `void` |
|
|
79
|
-
| `bindValue`
|
|
80
|
-
| `get`
|
|
81
|
-
| `hasToken`
|
|
82
|
-
| `remove`
|
|
83
|
-
| `removeAll`
|
|
84
|
-
| `resolve`
|
|
76
|
+
| `bindValue` | <T\>(`token`: [`Token`](README.md#token)<`T`\>, `value`: `T`) => `void` |
|
|
77
|
+
| `get` | <T\>(`token`: [`Token`](README.md#token)<`T`\>) => `undefined` \| `T` |
|
|
78
|
+
| `hasToken` | (`token`: [`Token`](README.md#token)<`unknown`\>) => `boolean` |
|
|
79
|
+
| `remove` | <T\>(`token`: [`Token`](README.md#token)<`T`\>) => `void` |
|
|
80
|
+
| `removeAll` | () => `void` |
|
|
81
|
+
| `resolve` | <T\>(`token`: [`Token`](README.md#token)<`T`\>) => `T` |
|
|
85
82
|
|
|
86
83
|
#### Defined in
|
|
87
84
|
|
|
88
|
-
[packages/ditox/src/ditox.ts:95](https://github.com/mnasyrov/ditox/blob/
|
|
85
|
+
[packages/ditox/src/ditox.ts:95](https://github.com/mnasyrov/ditox/blob/37f658c/packages/ditox/src/ditox.ts#L95)
|
|
89
86
|
|
|
90
|
-
|
|
87
|
+
---
|
|
91
88
|
|
|
92
89
|
### FactoryOptions
|
|
93
90
|
|
|
94
|
-
Ƭ **FactoryOptions**<`T`\>: { `
|
|
91
|
+
Ƭ **FactoryOptions**<`T`\>: { `onRemoved?`: (`value`: `T`) => `void` ; `scope?`: `"scoped"` \| `"singleton"` } \| { `scope`: `"transient"` }
|
|
95
92
|
|
|
96
93
|
Options for factory binding.
|
|
97
94
|
|
|
98
95
|
`scope` types:
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
96
|
+
|
|
97
|
+
- `singleton` - **This is the default**. The value is created and cached by the container which registered the factory.
|
|
98
|
+
- `scoped` - The value is created and cached by the container which starts resolving.
|
|
99
|
+
- `transient` - The value is created every time it is resolved.
|
|
102
100
|
|
|
103
101
|
`scoped` and `singleton` scopes can have `onRemoved` callback. It is called when a token is removed from the container.
|
|
104
102
|
|
|
105
103
|
#### Type parameters
|
|
106
104
|
|
|
107
105
|
| Name |
|
|
108
|
-
|
|
|
109
|
-
| `T`
|
|
106
|
+
| :--- |
|
|
107
|
+
| `T` |
|
|
110
108
|
|
|
111
109
|
#### Defined in
|
|
112
110
|
|
|
113
|
-
[packages/ditox/src/ditox.ts:83](https://github.com/mnasyrov/ditox/blob/
|
|
111
|
+
[packages/ditox/src/ditox.ts:83](https://github.com/mnasyrov/ditox/blob/37f658c/packages/ditox/src/ditox.ts#L83)
|
|
114
112
|
|
|
115
|
-
|
|
113
|
+
---
|
|
116
114
|
|
|
117
115
|
### FactoryScope
|
|
118
116
|
|
|
119
|
-
Ƭ **FactoryScope**:
|
|
117
|
+
Ƭ **FactoryScope**: `"scoped"` \| `"singleton"` \| `"transient"`
|
|
118
|
+
|
|
119
|
+
**`See`**
|
|
120
120
|
|
|
121
|
-
|
|
121
|
+
https://github.com/mnasyrov/ditox#factory-lifetimes
|
|
122
122
|
|
|
123
123
|
#### Defined in
|
|
124
124
|
|
|
125
|
-
[packages/ditox/src/ditox.ts:71](https://github.com/mnasyrov/ditox/blob/
|
|
125
|
+
[packages/ditox/src/ditox.ts:71](https://github.com/mnasyrov/ditox/blob/37f658c/packages/ditox/src/ditox.ts#L71)
|
|
126
126
|
|
|
127
|
-
|
|
127
|
+
---
|
|
128
128
|
|
|
129
129
|
### Module
|
|
130
130
|
|
|
@@ -132,7 +132,8 @@ ___
|
|
|
132
132
|
|
|
133
133
|
Dependency module
|
|
134
134
|
|
|
135
|
-
**`
|
|
135
|
+
**`Example`**
|
|
136
|
+
|
|
136
137
|
```ts
|
|
137
138
|
type LoggerModule = Module<{
|
|
138
139
|
logger: Logger;
|
|
@@ -141,25 +142,25 @@ type LoggerModule = Module<{
|
|
|
141
142
|
|
|
142
143
|
#### Type parameters
|
|
143
144
|
|
|
144
|
-
| Name
|
|
145
|
-
|
|
|
145
|
+
| Name | Type |
|
|
146
|
+
| :------------ | :---------------------------------- |
|
|
146
147
|
| `ModuleProps` | extends `AnyObject` = `EmptyObject` |
|
|
147
148
|
|
|
148
149
|
#### Defined in
|
|
149
150
|
|
|
150
|
-
[packages/ditox/src/modules.ts:22](https://github.com/mnasyrov/ditox/blob/
|
|
151
|
+
[packages/ditox/src/modules.ts:22](https://github.com/mnasyrov/ditox/blob/37f658c/packages/ditox/src/modules.ts#L22)
|
|
151
152
|
|
|
152
|
-
|
|
153
|
+
---
|
|
153
154
|
|
|
154
155
|
### ModuleBindingEntry
|
|
155
156
|
|
|
156
|
-
Ƭ **ModuleBindingEntry**: [`ModuleDeclaration`](README.md#moduledeclaration)<`AnyObject`\> \| { `module`: [`ModuleDeclaration`](README.md#moduledeclaration)<`AnyObject`\> ; `options`: [`BindModuleOptions`](README.md#bindmoduleoptions)
|
|
157
|
+
Ƭ **ModuleBindingEntry**: [`ModuleDeclaration`](README.md#moduledeclaration)<`AnyObject`\> \| { `module`: [`ModuleDeclaration`](README.md#moduledeclaration)<`AnyObject`\> ; `options`: [`BindModuleOptions`](README.md#bindmoduleoptions) }
|
|
157
158
|
|
|
158
159
|
#### Defined in
|
|
159
160
|
|
|
160
|
-
[packages/ditox/src/modules.ts:
|
|
161
|
+
[packages/ditox/src/modules.ts:82](https://github.com/mnasyrov/ditox/blob/37f658c/packages/ditox/src/modules.ts#L82)
|
|
161
162
|
|
|
162
|
-
|
|
163
|
+
---
|
|
163
164
|
|
|
164
165
|
### ModuleDeclaration
|
|
165
166
|
|
|
@@ -167,16 +168,17 @@ ___
|
|
|
167
168
|
|
|
168
169
|
Description how to bind the module in declarative way.
|
|
169
170
|
|
|
170
|
-
**`
|
|
171
|
+
**`Example`**
|
|
172
|
+
|
|
171
173
|
```ts
|
|
172
174
|
const LOGGER_MODULE: ModuleDeclaration<LoggerModule> = {
|
|
173
175
|
token: LOGGER_MODULE_TOKEN,
|
|
174
176
|
factory: (container) => {
|
|
175
177
|
const transport = container.resolve(TRANSPORT_TOKEN).open();
|
|
176
178
|
return {
|
|
177
|
-
logger: {
|
|
179
|
+
logger: {log: (message) => transport.write(message)},
|
|
178
180
|
destroy: () => transport.close(),
|
|
179
|
-
}
|
|
181
|
+
};
|
|
180
182
|
},
|
|
181
183
|
exports: {
|
|
182
184
|
logger: LOGGER_TOKEN,
|
|
@@ -186,27 +188,26 @@ const LOGGER_MODULE: ModuleDeclaration<LoggerModule> = {
|
|
|
186
188
|
|
|
187
189
|
#### Type parameters
|
|
188
190
|
|
|
189
|
-
| Name | Type
|
|
190
|
-
|
|
|
191
|
-
| `T`
|
|
191
|
+
| Name | Type |
|
|
192
|
+
| :--- | :------------------------------------------------- |
|
|
193
|
+
| `T` | extends [`Module`](README.md#module)<`AnyObject`\> |
|
|
192
194
|
|
|
193
195
|
#### Type declaration
|
|
194
196
|
|
|
195
|
-
| Name
|
|
196
|
-
|
|
|
197
|
-
| `
|
|
198
|
-
| `
|
|
199
|
-
| `
|
|
200
|
-
| `
|
|
201
|
-
| `
|
|
202
|
-
| `
|
|
203
|
-
| `factory` | (`container`: [`Container`](README.md#container)) => `T` | Factory of the module |
|
|
197
|
+
| Name | Type | Description |
|
|
198
|
+
| :--------------- | :--------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------ |
|
|
199
|
+
| `afterBinding?` | (`container`: [`Container`](README.md#container)) => `void` | Callback could be used to export complex dependencies from the module. It is called after binding the module. |
|
|
200
|
+
| `beforeBinding?` | (`container`: [`Container`](README.md#container)) => `void` | Callback could be used to prepare an environment. It is called before binding the module. |
|
|
201
|
+
| `exports?` | { [K in keyof GetModuleProps<T\>]?: Token<GetModuleProps<T\>[K]\> } | Dictionary of module properties which are bound to tokens. |
|
|
202
|
+
| `factory` | (`container`: [`Container`](README.md#container)) => `T` | Factory of the module |
|
|
203
|
+
| `imports?` | `ReadonlyArray`<[`ModuleBindingEntry`](README.md#modulebindingentry)\> | Modules for binding |
|
|
204
|
+
| `token` | [`Token`](README.md#token)<`T`\> | Token for the module |
|
|
204
205
|
|
|
205
206
|
#### Defined in
|
|
206
207
|
|
|
207
|
-
[packages/ditox/src/modules.ts:47](https://github.com/mnasyrov/ditox/blob/
|
|
208
|
+
[packages/ditox/src/modules.ts:47](https://github.com/mnasyrov/ditox/blob/37f658c/packages/ditox/src/modules.ts#L47)
|
|
208
209
|
|
|
209
|
-
|
|
210
|
+
---
|
|
210
211
|
|
|
211
212
|
### Token
|
|
212
213
|
|
|
@@ -217,12 +218,12 @@ Binding token.
|
|
|
217
218
|
#### Type parameters
|
|
218
219
|
|
|
219
220
|
| Name |
|
|
220
|
-
|
|
|
221
|
-
| `T`
|
|
221
|
+
| :--- |
|
|
222
|
+
| `T` |
|
|
222
223
|
|
|
223
224
|
#### Defined in
|
|
224
225
|
|
|
225
|
-
[packages/ditox/src/ditox.ts:25](https://github.com/mnasyrov/ditox/blob/
|
|
226
|
+
[packages/ditox/src/ditox.ts:25](https://github.com/mnasyrov/ditox/blob/37f658c/packages/ditox/src/ditox.ts#L25)
|
|
226
227
|
|
|
227
228
|
## Functions
|
|
228
229
|
|
|
@@ -232,24 +233,25 @@ Binding token.
|
|
|
232
233
|
|
|
233
234
|
Binds the dependency module to the container
|
|
234
235
|
|
|
235
|
-
**`
|
|
236
|
+
**`Example`**
|
|
237
|
+
|
|
236
238
|
```ts
|
|
237
239
|
bindModule(container, LOGGER_MODULE);
|
|
238
240
|
```
|
|
239
241
|
|
|
240
242
|
#### Type parameters
|
|
241
243
|
|
|
242
|
-
| Name | Type
|
|
243
|
-
|
|
|
244
|
-
| `T`
|
|
244
|
+
| Name | Type |
|
|
245
|
+
| :--- | :------------------------------------------------- |
|
|
246
|
+
| `T` | extends [`Module`](README.md#module)<`AnyObject`\> |
|
|
245
247
|
|
|
246
248
|
#### Parameters
|
|
247
249
|
|
|
248
|
-
| Name
|
|
249
|
-
|
|
|
250
|
-
| `container`
|
|
250
|
+
| Name | Type | Description |
|
|
251
|
+
| :------------------ | :------------------------------------------------------- | :------------------------------------ |
|
|
252
|
+
| `container` | [`Container`](README.md#container) | Dependency container. |
|
|
251
253
|
| `moduleDeclaration` | [`ModuleDeclaration`](README.md#moduledeclaration)<`T`\> | Declaration of the dependency module. |
|
|
252
|
-
| `options?`
|
|
254
|
+
| `options?` | [`BindModuleOptions`](README.md#bindmoduleoptions) | Options for module binding. |
|
|
253
255
|
|
|
254
256
|
#### Returns
|
|
255
257
|
|
|
@@ -257,9 +259,9 @@ bindModule(container, LOGGER_MODULE);
|
|
|
257
259
|
|
|
258
260
|
#### Defined in
|
|
259
261
|
|
|
260
|
-
[packages/ditox/src/modules.ts:
|
|
262
|
+
[packages/ditox/src/modules.ts:100](https://github.com/mnasyrov/ditox/blob/37f658c/packages/ditox/src/modules.ts#L100)
|
|
261
263
|
|
|
262
|
-
|
|
264
|
+
---
|
|
263
265
|
|
|
264
266
|
### bindModules
|
|
265
267
|
|
|
@@ -269,10 +271,10 @@ Binds dependency modules to the container
|
|
|
269
271
|
|
|
270
272
|
#### Parameters
|
|
271
273
|
|
|
272
|
-
| Name
|
|
273
|
-
|
|
|
274
|
-
| `container` | [`Container`](README.md#container)
|
|
275
|
-
| `modules`
|
|
274
|
+
| Name | Type | Description |
|
|
275
|
+
| :---------- | :-------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------ |
|
|
276
|
+
| `container` | [`Container`](README.md#container) | Dependency container for binding |
|
|
277
|
+
| `modules` | readonly [`ModuleBindingEntry`](README.md#modulebindingentry)[] | Array of module binding entries: module declaration or `{module: ModuleDeclaration, options: BindModuleOptions}` objects. |
|
|
276
278
|
|
|
277
279
|
#### Returns
|
|
278
280
|
|
|
@@ -280,9 +282,9 @@ Binds dependency modules to the container
|
|
|
280
282
|
|
|
281
283
|
#### Defined in
|
|
282
284
|
|
|
283
|
-
[packages/ditox/src/modules.ts:
|
|
285
|
+
[packages/ditox/src/modules.ts:161](https://github.com/mnasyrov/ditox/blob/37f658c/packages/ditox/src/modules.ts#L161)
|
|
284
286
|
|
|
285
|
-
|
|
287
|
+
---
|
|
286
288
|
|
|
287
289
|
### bindMultiValue
|
|
288
290
|
|
|
@@ -293,16 +295,16 @@ Rebinds the array by the token with added new value.
|
|
|
293
295
|
#### Type parameters
|
|
294
296
|
|
|
295
297
|
| Name |
|
|
296
|
-
|
|
|
297
|
-
| `T`
|
|
298
|
+
| :--- |
|
|
299
|
+
| `T` |
|
|
298
300
|
|
|
299
301
|
#### Parameters
|
|
300
302
|
|
|
301
|
-
| Name
|
|
302
|
-
|
|
|
303
|
-
| `container` | [`Container`](README.md#container)
|
|
304
|
-
| `token`
|
|
305
|
-
| `value`
|
|
303
|
+
| Name | Type | Description |
|
|
304
|
+
| :---------- | :------------------------------------------ | :------------------------------------------------ |
|
|
305
|
+
| `container` | [`Container`](README.md#container) | Dependency container. |
|
|
306
|
+
| `token` | [`Token`](README.md#token)<readonly `T`[]\> | Token for an array of values. |
|
|
307
|
+
| `value` | `T` | New value which is added to the end of the array. |
|
|
306
308
|
|
|
307
309
|
#### Returns
|
|
308
310
|
|
|
@@ -310,9 +312,9 @@ Rebinds the array by the token with added new value.
|
|
|
310
312
|
|
|
311
313
|
#### Defined in
|
|
312
314
|
|
|
313
|
-
[packages/ditox/src/utils.ts:27](https://github.com/mnasyrov/ditox/blob/
|
|
315
|
+
[packages/ditox/src/utils.ts:27](https://github.com/mnasyrov/ditox/blob/37f658c/packages/ditox/src/utils.ts#L27)
|
|
314
316
|
|
|
315
|
-
|
|
317
|
+
---
|
|
316
318
|
|
|
317
319
|
### createContainer
|
|
318
320
|
|
|
@@ -324,8 +326,8 @@ Container can have an optional parent to chain token resolution. The parent is u
|
|
|
324
326
|
|
|
325
327
|
#### Parameters
|
|
326
328
|
|
|
327
|
-
| Name
|
|
328
|
-
|
|
|
329
|
+
| Name | Type | Description |
|
|
330
|
+
| :----------------- | :--------------------------------- | :------------------------- |
|
|
329
331
|
| `parentContainer?` | [`Container`](README.md#container) | Optional parent container. |
|
|
330
332
|
|
|
331
333
|
#### Returns
|
|
@@ -334,9 +336,9 @@ Container can have an optional parent to chain token resolution. The parent is u
|
|
|
334
336
|
|
|
335
337
|
#### Defined in
|
|
336
338
|
|
|
337
|
-
[packages/ditox/src/ditox.ts:204](https://github.com/mnasyrov/ditox/blob/
|
|
339
|
+
[packages/ditox/src/ditox.ts:204](https://github.com/mnasyrov/ditox/blob/37f658c/packages/ditox/src/ditox.ts#L204)
|
|
338
340
|
|
|
339
|
-
|
|
341
|
+
---
|
|
340
342
|
|
|
341
343
|
### declareModule
|
|
342
344
|
|
|
@@ -344,15 +346,16 @@ ___
|
|
|
344
346
|
|
|
345
347
|
Declares a module binding
|
|
346
348
|
|
|
347
|
-
**`
|
|
349
|
+
**`Example`**
|
|
350
|
+
|
|
348
351
|
```ts
|
|
349
352
|
const LOGGER_MODULE = declareModule<LoggerModule>({
|
|
350
353
|
factory: (container) => {
|
|
351
354
|
const transport = container.resolve(TRANSPORT_TOKEN).open();
|
|
352
355
|
return {
|
|
353
|
-
logger: {
|
|
356
|
+
logger: {log: (message) => transport.write(message)},
|
|
354
357
|
destroy: () => transport.close(),
|
|
355
|
-
}
|
|
358
|
+
};
|
|
356
359
|
},
|
|
357
360
|
exports: {
|
|
358
361
|
logger: LOGGER_TOKEN,
|
|
@@ -362,15 +365,15 @@ const LOGGER_MODULE = declareModule<LoggerModule>({
|
|
|
362
365
|
|
|
363
366
|
#### Type parameters
|
|
364
367
|
|
|
365
|
-
| Name |
|
|
366
|
-
|
|
|
367
|
-
| `T` |
|
|
368
|
+
| Name | Type |
|
|
369
|
+
| :--- | :------------------------------------------------- |
|
|
370
|
+
| `T` | extends [`Module`](README.md#module)<`AnyObject`\> |
|
|
368
371
|
|
|
369
372
|
#### Parameters
|
|
370
373
|
|
|
371
|
-
| Name
|
|
372
|
-
|
|
|
373
|
-
| `declaration` | `Omit`<[`ModuleDeclaration`](README.md#moduledeclaration)<`T`\>,
|
|
374
|
+
| Name | Type | Description |
|
|
375
|
+
| :------------ | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------- |
|
|
376
|
+
| `declaration` | `Omit`<[`ModuleDeclaration`](README.md#moduledeclaration)<`T`\>, `"token"`\> & `Partial`<`Pick`<[`ModuleDeclaration`](README.md#moduledeclaration)<`T`\>, `"token"`\>\> | a module declaration |
|
|
374
377
|
|
|
375
378
|
#### Returns
|
|
376
379
|
|
|
@@ -378,9 +381,9 @@ const LOGGER_MODULE = declareModule<LoggerModule>({
|
|
|
378
381
|
|
|
379
382
|
#### Defined in
|
|
380
383
|
|
|
381
|
-
[packages/ditox/src/modules.ts:
|
|
384
|
+
[packages/ditox/src/modules.ts:196](https://github.com/mnasyrov/ditox/blob/37f658c/packages/ditox/src/modules.ts#L196)
|
|
382
385
|
|
|
383
|
-
|
|
386
|
+
---
|
|
384
387
|
|
|
385
388
|
### declareModuleBindings
|
|
386
389
|
|
|
@@ -390,8 +393,8 @@ Declares bindings of several modules
|
|
|
390
393
|
|
|
391
394
|
#### Parameters
|
|
392
395
|
|
|
393
|
-
| Name
|
|
394
|
-
|
|
|
396
|
+
| Name | Type | Description |
|
|
397
|
+
| :-------- | :-------------------------------------------------------------- | :------------------------- |
|
|
395
398
|
| `modules` | readonly [`ModuleBindingEntry`](README.md#modulebindingentry)[] | module declaration entries |
|
|
396
399
|
|
|
397
400
|
#### Returns
|
|
@@ -400,84 +403,13 @@ Declares bindings of several modules
|
|
|
400
403
|
|
|
401
404
|
#### Defined in
|
|
402
405
|
|
|
403
|
-
[packages/ditox/src/modules.ts:
|
|
404
|
-
|
|
405
|
-
___
|
|
406
|
-
|
|
407
|
-
### getProps
|
|
408
|
-
|
|
409
|
-
▸ **getProps**<`Props`\>(`container`, `tokens`): `Partial`<`Props`\>
|
|
410
|
-
|
|
411
|
-
Returns an object with resolved properties which are specified by token properties.
|
|
412
|
-
If a token is not found, then `undefined` value is used.
|
|
413
|
-
|
|
414
|
-
**`deprecated`** Use `tryResolveValue()` function.
|
|
415
|
-
|
|
416
|
-
**`example`**
|
|
417
|
-
```ts
|
|
418
|
-
const props = getProps(container, {a: tokenA, b: tokenB});
|
|
419
|
-
console.log(props); // {a: 1, b: 2}
|
|
420
|
-
```
|
|
421
|
-
|
|
422
|
-
#### Type parameters
|
|
423
|
-
|
|
424
|
-
| Name | Type |
|
|
425
|
-
| :------ | :------ |
|
|
426
|
-
| `Props` | extends `ValuesProps` |
|
|
427
|
-
|
|
428
|
-
#### Parameters
|
|
429
|
-
|
|
430
|
-
| Name | Type |
|
|
431
|
-
| :------ | :------ |
|
|
432
|
-
| `container` | [`Container`](README.md#container) |
|
|
433
|
-
| `tokens` | `TokenProps`<`Props`\> |
|
|
434
|
-
|
|
435
|
-
#### Returns
|
|
436
|
-
|
|
437
|
-
`Partial`<`Props`\>
|
|
438
|
-
|
|
439
|
-
#### Defined in
|
|
440
|
-
|
|
441
|
-
[packages/ditox/src/utils-deprecated.ts:41](https://github.com/mnasyrov/ditox/blob/aea7a8f/packages/ditox/src/utils-deprecated.ts#L41)
|
|
442
|
-
|
|
443
|
-
___
|
|
406
|
+
[packages/ditox/src/modules.ts:208](https://github.com/mnasyrov/ditox/blob/37f658c/packages/ditox/src/modules.ts#L208)
|
|
444
407
|
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
▸ **getValues**<`Tokens`, `Values`\>(`container`, ...`tokens`): `Values`
|
|
448
|
-
|
|
449
|
-
Returns an array of resolved values by the specified token.
|
|
450
|
-
If a token is not found, then `undefined` value is used.
|
|
451
|
-
|
|
452
|
-
**`deprecated`** Use `tryResolveValues()` function.
|
|
453
|
-
|
|
454
|
-
#### Type parameters
|
|
455
|
-
|
|
456
|
-
| Name | Type |
|
|
457
|
-
| :------ | :------ |
|
|
458
|
-
| `Tokens` | extends [`Token`](README.md#token)<`unknown`\>[] |
|
|
459
|
-
| `Values` | extends { [K in string \| number \| symbol]: Tokens[K] extends Token<V\> ? V : never } |
|
|
460
|
-
|
|
461
|
-
#### Parameters
|
|
462
|
-
|
|
463
|
-
| Name | Type |
|
|
464
|
-
| :------ | :------ |
|
|
465
|
-
| `container` | [`Container`](README.md#container) |
|
|
466
|
-
| `...tokens` | `Tokens` |
|
|
467
|
-
|
|
468
|
-
#### Returns
|
|
469
|
-
|
|
470
|
-
`Values`
|
|
471
|
-
|
|
472
|
-
#### Defined in
|
|
473
|
-
|
|
474
|
-
[packages/ditox/src/utils-deprecated.ts:20](https://github.com/mnasyrov/ditox/blob/aea7a8f/packages/ditox/src/utils-deprecated.ts#L20)
|
|
475
|
-
|
|
476
|
-
___
|
|
408
|
+
---
|
|
477
409
|
|
|
478
410
|
### injectable
|
|
479
411
|
|
|
480
|
-
▸ **injectable**<`Tokens`, `Values`, `Result`\>(`factory`,
|
|
412
|
+
▸ **injectable**<`Tokens`, `Values`, `Result`\>(`this`, `factory`, `...tokens`): (`container`: [`Container`](README.md#container)) => `Result`
|
|
481
413
|
|
|
482
414
|
Decorates a factory by passing resolved values as factory arguments.
|
|
483
415
|
|
|
@@ -486,18 +418,19 @@ then returns an object containing resolved values as properties.
|
|
|
486
418
|
|
|
487
419
|
#### Type parameters
|
|
488
420
|
|
|
489
|
-
| Name
|
|
490
|
-
|
|
|
491
|
-
| `Tokens` | extends ([`Token`](README.md#token)<`unknown`\> \| { [key: string]
|
|
421
|
+
| Name | Type |
|
|
422
|
+
| :------- | :------------------------------------------------------------------------------------------------------------------------------------ |
|
|
423
|
+
| `Tokens` | extends ([`Token`](README.md#token)<`unknown`\> \| { `[key: string]`: [`Token`](README.md#token)<`unknown`\>; })[] |
|
|
492
424
|
| `Values` | extends { [K in string \| number \| symbol]: Tokens[K] extends Token<V\> ? V : Tokens[K] extends TokenProps<Props\> ? Props : never } |
|
|
493
|
-
| `Result` | `Result`
|
|
425
|
+
| `Result` | `Result` |
|
|
494
426
|
|
|
495
427
|
#### Parameters
|
|
496
428
|
|
|
497
|
-
| Name
|
|
498
|
-
|
|
|
499
|
-
| `
|
|
500
|
-
|
|
|
429
|
+
| Name | Type | Description |
|
|
430
|
+
| :---------- | :---------------------------------- | :-------------------------------------------- |
|
|
431
|
+
| `this` | `unknown` | - |
|
|
432
|
+
| `factory` | (...`params`: `Values`) => `Result` | A factory. |
|
|
433
|
+
| `...tokens` | `Tokens` | Tokens which correspond to factory arguments. |
|
|
501
434
|
|
|
502
435
|
#### Returns
|
|
503
436
|
|
|
@@ -507,32 +440,25 @@ Decorated factory which takes a dependency container as a single argument.
|
|
|
507
440
|
|
|
508
441
|
▸ (`container`): `Result`
|
|
509
442
|
|
|
510
|
-
Decorates a factory by passing resolved values as factory arguments.
|
|
511
|
-
|
|
512
|
-
If an argument is an object which has tokens as its properties,
|
|
513
|
-
then returns an object containing resolved values as properties.
|
|
514
|
-
|
|
515
443
|
##### Parameters
|
|
516
444
|
|
|
517
|
-
| Name
|
|
518
|
-
|
|
|
445
|
+
| Name | Type |
|
|
446
|
+
| :---------- | :--------------------------------- |
|
|
519
447
|
| `container` | [`Container`](README.md#container) |
|
|
520
448
|
|
|
521
449
|
##### Returns
|
|
522
450
|
|
|
523
451
|
`Result`
|
|
524
452
|
|
|
525
|
-
Decorated factory which takes a dependency container as a single argument.
|
|
526
|
-
|
|
527
453
|
#### Defined in
|
|
528
454
|
|
|
529
|
-
[packages/ditox/src/utils.ts:178](https://github.com/mnasyrov/ditox/blob/
|
|
455
|
+
[packages/ditox/src/utils.ts:178](https://github.com/mnasyrov/ditox/blob/37f658c/packages/ditox/src/utils.ts#L178)
|
|
530
456
|
|
|
531
|
-
|
|
457
|
+
---
|
|
532
458
|
|
|
533
459
|
### injectableClass
|
|
534
460
|
|
|
535
|
-
▸ **injectableClass**<`Tokens`, `Values`, `Result`\>(`constructor`,
|
|
461
|
+
▸ **injectableClass**<`Tokens`, `Values`, `Result`\>(`this`, `constructor`, `...tokens`): (`container`: [`Container`](README.md#container)) => `Result`
|
|
536
462
|
|
|
537
463
|
Decorates a class by passing resolved values as arguments to its constructor.
|
|
538
464
|
|
|
@@ -541,18 +467,19 @@ then returns an object containing resolved values as properties.
|
|
|
541
467
|
|
|
542
468
|
#### Type parameters
|
|
543
469
|
|
|
544
|
-
| Name
|
|
545
|
-
|
|
|
546
|
-
| `Tokens` | extends ([`Token`](README.md#token)<`unknown`\> \| { [key: string]
|
|
470
|
+
| Name | Type |
|
|
471
|
+
| :------- | :------------------------------------------------------------------------------------------------------------------------------------ |
|
|
472
|
+
| `Tokens` | extends ([`Token`](README.md#token)<`unknown`\> \| { `[key: string]`: [`Token`](README.md#token)<`unknown`\>; })[] |
|
|
547
473
|
| `Values` | extends { [K in string \| number \| symbol]: Tokens[K] extends Token<V\> ? V : Tokens[K] extends TokenProps<Props\> ? Props : never } |
|
|
548
|
-
| `Result` | `Result`
|
|
474
|
+
| `Result` | `Result` |
|
|
549
475
|
|
|
550
476
|
#### Parameters
|
|
551
477
|
|
|
552
|
-
| Name
|
|
553
|
-
|
|
|
554
|
-
| `
|
|
555
|
-
|
|
|
478
|
+
| Name | Type | Description |
|
|
479
|
+
| :------------ | :---------------------------------- | :----------------------------------------------- |
|
|
480
|
+
| `this` | `unknown` | - |
|
|
481
|
+
| `constructor` | (...`params`: `Values`) => `Result` | Constructor of a class |
|
|
482
|
+
| `...tokens` | `Tokens` | Tokens which correspond to constructor arguments |
|
|
556
483
|
|
|
557
484
|
#### Returns
|
|
558
485
|
|
|
@@ -563,95 +490,21 @@ and returns a new created class.
|
|
|
563
490
|
|
|
564
491
|
▸ (`container`): `Result`
|
|
565
492
|
|
|
566
|
-
Decorates a class by passing resolved values as arguments to its constructor.
|
|
567
|
-
|
|
568
|
-
If an argument is an object which has tokens as its properties,
|
|
569
|
-
then returns an object containing resolved values as properties.
|
|
570
|
-
|
|
571
493
|
##### Parameters
|
|
572
494
|
|
|
573
|
-
| Name
|
|
574
|
-
|
|
|
495
|
+
| Name | Type |
|
|
496
|
+
| :---------- | :--------------------------------- |
|
|
575
497
|
| `container` | [`Container`](README.md#container) |
|
|
576
498
|
|
|
577
499
|
##### Returns
|
|
578
500
|
|
|
579
501
|
`Result`
|
|
580
502
|
|
|
581
|
-
A factory function which takes a dependency container as a single argument
|
|
582
|
-
and returns a new created class.
|
|
583
|
-
|
|
584
503
|
#### Defined in
|
|
585
504
|
|
|
586
|
-
[packages/ditox/src/utils.ts:211](https://github.com/mnasyrov/ditox/blob/
|
|
587
|
-
|
|
588
|
-
___
|
|
505
|
+
[packages/ditox/src/utils.ts:211](https://github.com/mnasyrov/ditox/blob/37f658c/packages/ditox/src/utils.ts#L211)
|
|
589
506
|
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
▸ **injectableProps**<`Props`, `Result`\>(`factory`, `tokens`): (`container`: [`Container`](README.md#container)) => `Result`
|
|
593
|
-
|
|
594
|
-
Decorates a factory by passing a resolved object with tokens as the first argument.
|
|
595
|
-
|
|
596
|
-
**`deprecated`** Use `injectable()` function.
|
|
597
|
-
|
|
598
|
-
**`example`**
|
|
599
|
-
```ts
|
|
600
|
-
const factory = ({a, b}: {a: number, b: number}) => a + b;
|
|
601
|
-
const decoratedFactory = injectableProps(factory, {a: tokenA, b: tokenB});
|
|
602
|
-
const result = decoratedFactory(container);
|
|
603
|
-
```
|
|
604
|
-
|
|
605
|
-
#### Type parameters
|
|
606
|
-
|
|
607
|
-
| Name | Type |
|
|
608
|
-
| :------ | :------ |
|
|
609
|
-
| `Props` | extends `ValuesProps` |
|
|
610
|
-
| `Result` | `Result` |
|
|
611
|
-
|
|
612
|
-
#### Parameters
|
|
613
|
-
|
|
614
|
-
| Name | Type | Description |
|
|
615
|
-
| :------ | :------ | :------ |
|
|
616
|
-
| `factory` | (`props`: `Props`) => `Result` | A factory. |
|
|
617
|
-
| `tokens` | `TokenProps`<`Props`\> | Object with tokens. |
|
|
618
|
-
|
|
619
|
-
#### Returns
|
|
620
|
-
|
|
621
|
-
`fn`
|
|
622
|
-
|
|
623
|
-
Decorated factory which takes a dependency container as a single argument.
|
|
624
|
-
|
|
625
|
-
▸ (`container`): `Result`
|
|
626
|
-
|
|
627
|
-
Decorates a factory by passing a resolved object with tokens as the first argument.
|
|
628
|
-
|
|
629
|
-
**`deprecated`** Use `injectable()` function.
|
|
630
|
-
|
|
631
|
-
**`example`**
|
|
632
|
-
```ts
|
|
633
|
-
const factory = ({a, b}: {a: number, b: number}) => a + b;
|
|
634
|
-
const decoratedFactory = injectableProps(factory, {a: tokenA, b: tokenB});
|
|
635
|
-
const result = decoratedFactory(container);
|
|
636
|
-
```
|
|
637
|
-
|
|
638
|
-
##### Parameters
|
|
639
|
-
|
|
640
|
-
| Name | Type |
|
|
641
|
-
| :------ | :------ |
|
|
642
|
-
| `container` | [`Container`](README.md#container) |
|
|
643
|
-
|
|
644
|
-
##### Returns
|
|
645
|
-
|
|
646
|
-
`Result`
|
|
647
|
-
|
|
648
|
-
Decorated factory which takes a dependency container as a single argument.
|
|
649
|
-
|
|
650
|
-
#### Defined in
|
|
651
|
-
|
|
652
|
-
[packages/ditox/src/utils-deprecated.ts:82](https://github.com/mnasyrov/ditox/blob/aea7a8f/packages/ditox/src/utils-deprecated.ts#L82)
|
|
653
|
-
|
|
654
|
-
___
|
|
507
|
+
---
|
|
655
508
|
|
|
656
509
|
### isToken
|
|
657
510
|
|
|
@@ -662,13 +515,13 @@ Checks if a value is the token
|
|
|
662
515
|
#### Type parameters
|
|
663
516
|
|
|
664
517
|
| Name |
|
|
665
|
-
|
|
|
666
|
-
| `T`
|
|
518
|
+
| :--- |
|
|
519
|
+
| `T` |
|
|
667
520
|
|
|
668
521
|
#### Parameters
|
|
669
522
|
|
|
670
|
-
| Name
|
|
671
|
-
| :------ |
|
|
523
|
+
| Name | Type |
|
|
524
|
+
| :------ | :-------- |
|
|
672
525
|
| `value` | `unknown` |
|
|
673
526
|
|
|
674
527
|
#### Returns
|
|
@@ -677,9 +530,9 @@ value is Token<T\>
|
|
|
677
530
|
|
|
678
531
|
#### Defined in
|
|
679
532
|
|
|
680
|
-
[packages/ditox/src/utils.ts:11](https://github.com/mnasyrov/ditox/blob/
|
|
533
|
+
[packages/ditox/src/utils.ts:11](https://github.com/mnasyrov/ditox/blob/37f658c/packages/ditox/src/utils.ts#L11)
|
|
681
534
|
|
|
682
|
-
|
|
535
|
+
---
|
|
683
536
|
|
|
684
537
|
### optional
|
|
685
538
|
|
|
@@ -691,15 +544,15 @@ This value is be used as default value in case a container does not have registe
|
|
|
691
544
|
#### Type parameters
|
|
692
545
|
|
|
693
546
|
| Name |
|
|
694
|
-
|
|
|
695
|
-
| `T`
|
|
547
|
+
| :--- |
|
|
548
|
+
| `T` |
|
|
696
549
|
|
|
697
550
|
#### Parameters
|
|
698
551
|
|
|
699
|
-
| Name
|
|
700
|
-
|
|
|
701
|
-
| `token`
|
|
702
|
-
| `optionalValue` | `T`
|
|
552
|
+
| Name | Type | Description |
|
|
553
|
+
| :-------------- | :------------------------------- | :------------------------------ |
|
|
554
|
+
| `token` | [`Token`](README.md#token)<`T`\> | Existed token. |
|
|
555
|
+
| `optionalValue` | `T` | Default value for the resolver. |
|
|
703
556
|
|
|
704
557
|
#### Returns
|
|
705
558
|
|
|
@@ -707,20 +560,20 @@ This value is be used as default value in case a container does not have registe
|
|
|
707
560
|
|
|
708
561
|
#### Defined in
|
|
709
562
|
|
|
710
|
-
[packages/ditox/src/ditox.ts:41](https://github.com/mnasyrov/ditox/blob/
|
|
563
|
+
[packages/ditox/src/ditox.ts:41](https://github.com/mnasyrov/ditox/blob/37f658c/packages/ditox/src/ditox.ts#L41)
|
|
711
564
|
|
|
712
565
|
▸ **optional**<`T`\>(`token`): `OptionalToken`<`T` \| `undefined`\>
|
|
713
566
|
|
|
714
567
|
#### Type parameters
|
|
715
568
|
|
|
716
569
|
| Name |
|
|
717
|
-
|
|
|
718
|
-
| `T`
|
|
570
|
+
| :--- |
|
|
571
|
+
| `T` |
|
|
719
572
|
|
|
720
573
|
#### Parameters
|
|
721
574
|
|
|
722
|
-
| Name
|
|
723
|
-
| :------ |
|
|
575
|
+
| Name | Type |
|
|
576
|
+
| :------ | :------------------------------- |
|
|
724
577
|
| `token` | [`Token`](README.md#token)<`T`\> |
|
|
725
578
|
|
|
726
579
|
#### Returns
|
|
@@ -729,47 +582,9 @@ This value is be used as default value in case a container does not have registe
|
|
|
729
582
|
|
|
730
583
|
#### Defined in
|
|
731
584
|
|
|
732
|
-
[packages/ditox/src/ditox.ts:45](https://github.com/mnasyrov/ditox/blob/
|
|
733
|
-
|
|
734
|
-
___
|
|
735
|
-
|
|
736
|
-
### resolveProps
|
|
737
|
-
|
|
738
|
-
▸ **resolveProps**<`Props`\>(`container`, `tokens`): `Props`
|
|
585
|
+
[packages/ditox/src/ditox.ts:45](https://github.com/mnasyrov/ditox/blob/37f658c/packages/ditox/src/ditox.ts#L45)
|
|
739
586
|
|
|
740
|
-
|
|
741
|
-
If a token is not found, then `ResolverError` is thrown.
|
|
742
|
-
|
|
743
|
-
**`deprecated`** Use `resolveValue()` function.
|
|
744
|
-
|
|
745
|
-
**`example`**
|
|
746
|
-
```ts
|
|
747
|
-
const props = resolveProps(container, {a: tokenA, b: tokenB});
|
|
748
|
-
console.log(props); // {a: 1, b: 2}
|
|
749
|
-
```
|
|
750
|
-
|
|
751
|
-
#### Type parameters
|
|
752
|
-
|
|
753
|
-
| Name | Type |
|
|
754
|
-
| :------ | :------ |
|
|
755
|
-
| `Props` | extends `ValuesProps` |
|
|
756
|
-
|
|
757
|
-
#### Parameters
|
|
758
|
-
|
|
759
|
-
| Name | Type |
|
|
760
|
-
| :------ | :------ |
|
|
761
|
-
| `container` | [`Container`](README.md#container) |
|
|
762
|
-
| `tokens` | `TokenProps`<`Props`\> |
|
|
763
|
-
|
|
764
|
-
#### Returns
|
|
765
|
-
|
|
766
|
-
`Props`
|
|
767
|
-
|
|
768
|
-
#### Defined in
|
|
769
|
-
|
|
770
|
-
[packages/ditox/src/utils-deprecated.ts:60](https://github.com/mnasyrov/ditox/blob/aea7a8f/packages/ditox/src/utils-deprecated.ts#L60)
|
|
771
|
-
|
|
772
|
-
___
|
|
587
|
+
---
|
|
773
588
|
|
|
774
589
|
### resolveValue
|
|
775
590
|
|
|
@@ -782,7 +597,8 @@ then returns an object containing resolved values as properties.
|
|
|
782
597
|
|
|
783
598
|
If a value is not found by the token, then `ResolverError` is thrown.
|
|
784
599
|
|
|
785
|
-
**`
|
|
600
|
+
**`Example`**
|
|
601
|
+
|
|
786
602
|
```ts
|
|
787
603
|
const value = resolveValue(container, tokenA);
|
|
788
604
|
console.log(value); // 1
|
|
@@ -793,17 +609,17 @@ console.log(props); // {a: 1, b: 2}
|
|
|
793
609
|
|
|
794
610
|
#### Type parameters
|
|
795
611
|
|
|
796
|
-
| Name
|
|
797
|
-
|
|
|
798
|
-
| `Tokens` | extends [`Token`](README.md#token)<`unknown`\> \| { [key: string]
|
|
799
|
-
| `Values` | extends `unknown`
|
|
612
|
+
| Name | Type |
|
|
613
|
+
| :------- | :------------------------------------------------------------------------------------------------------------- |
|
|
614
|
+
| `Tokens` | extends [`Token`](README.md#token)<`unknown`\> \| { `[key: string]`: [`Token`](README.md#token)<`unknown`\>; } |
|
|
615
|
+
| `Values` | extends `unknown` |
|
|
800
616
|
|
|
801
617
|
#### Parameters
|
|
802
618
|
|
|
803
|
-
| Name
|
|
804
|
-
|
|
|
619
|
+
| Name | Type |
|
|
620
|
+
| :---------- | :--------------------------------- |
|
|
805
621
|
| `container` | [`Container`](README.md#container) |
|
|
806
|
-
| `token`
|
|
622
|
+
| `token` | `Tokens` |
|
|
807
623
|
|
|
808
624
|
#### Returns
|
|
809
625
|
|
|
@@ -811,13 +627,13 @@ console.log(props); // {a: 1, b: 2}
|
|
|
811
627
|
|
|
812
628
|
#### Defined in
|
|
813
629
|
|
|
814
|
-
[packages/ditox/src/utils.ts:118](https://github.com/mnasyrov/ditox/blob/
|
|
630
|
+
[packages/ditox/src/utils.ts:118](https://github.com/mnasyrov/ditox/blob/37f658c/packages/ditox/src/utils.ts#L118)
|
|
815
631
|
|
|
816
|
-
|
|
632
|
+
---
|
|
817
633
|
|
|
818
634
|
### resolveValues
|
|
819
635
|
|
|
820
|
-
▸ **resolveValues**<`Tokens`, `Values`\>(`container`,
|
|
636
|
+
▸ **resolveValues**<`Tokens`, `Values`\>(`container`, `...tokens`): `Values`
|
|
821
637
|
|
|
822
638
|
Returns an array of resolved values or objects with resolved values.
|
|
823
639
|
|
|
@@ -826,7 +642,8 @@ then returns an object containing resolved values as properties.
|
|
|
826
642
|
|
|
827
643
|
If a token is not found, then `ResolverError` is thrown.
|
|
828
644
|
|
|
829
|
-
**`
|
|
645
|
+
**`Example`**
|
|
646
|
+
|
|
830
647
|
```ts
|
|
831
648
|
const items1 = resolveValues(container, tokenA);
|
|
832
649
|
console.log(items1); // [1]
|
|
@@ -837,17 +654,17 @@ console.log(items2); // [1, {a: 1, b: 2}]
|
|
|
837
654
|
|
|
838
655
|
#### Type parameters
|
|
839
656
|
|
|
840
|
-
| Name
|
|
841
|
-
|
|
|
842
|
-
| `Tokens` | extends ([`Token`](README.md#token)<`unknown`\> \| { [key: string]
|
|
657
|
+
| Name | Type |
|
|
658
|
+
| :------- | :------------------------------------------------------------------------------------------------------------------------------------ |
|
|
659
|
+
| `Tokens` | extends ([`Token`](README.md#token)<`unknown`\> \| { `[key: string]`: [`Token`](README.md#token)<`unknown`\>; })[] |
|
|
843
660
|
| `Values` | extends { [K in string \| number \| symbol]: Tokens[K] extends Token<V\> ? V : Tokens[K] extends TokenProps<Props\> ? Props : never } |
|
|
844
661
|
|
|
845
662
|
#### Parameters
|
|
846
663
|
|
|
847
|
-
| Name
|
|
848
|
-
|
|
|
664
|
+
| Name | Type |
|
|
665
|
+
| :---------- | :--------------------------------- |
|
|
849
666
|
| `container` | [`Container`](README.md#container) |
|
|
850
|
-
| `...tokens` | `Tokens`
|
|
667
|
+
| `...tokens` | `Tokens` |
|
|
851
668
|
|
|
852
669
|
#### Returns
|
|
853
670
|
|
|
@@ -855,9 +672,9 @@ console.log(items2); // [1, {a: 1, b: 2}]
|
|
|
855
672
|
|
|
856
673
|
#### Defined in
|
|
857
674
|
|
|
858
|
-
[packages/ditox/src/utils.ts:154](https://github.com/mnasyrov/ditox/blob/
|
|
675
|
+
[packages/ditox/src/utils.ts:154](https://github.com/mnasyrov/ditox/blob/37f658c/packages/ditox/src/utils.ts#L154)
|
|
859
676
|
|
|
860
|
-
|
|
677
|
+
---
|
|
861
678
|
|
|
862
679
|
### token
|
|
863
680
|
|
|
@@ -868,13 +685,13 @@ Creates a new binding token.
|
|
|
868
685
|
#### Type parameters
|
|
869
686
|
|
|
870
687
|
| Name |
|
|
871
|
-
|
|
|
872
|
-
| `T`
|
|
688
|
+
| :--- |
|
|
689
|
+
| `T` |
|
|
873
690
|
|
|
874
691
|
#### Parameters
|
|
875
692
|
|
|
876
|
-
| Name
|
|
877
|
-
|
|
|
693
|
+
| Name | Type | Description |
|
|
694
|
+
| :------------- | :------- | :------------------------------------------- |
|
|
878
695
|
| `description?` | `string` | Token description for better error messages. |
|
|
879
696
|
|
|
880
697
|
#### Returns
|
|
@@ -883,9 +700,9 @@ Creates a new binding token.
|
|
|
883
700
|
|
|
884
701
|
#### Defined in
|
|
885
702
|
|
|
886
|
-
[packages/ditox/src/ditox.ts:31](https://github.com/mnasyrov/ditox/blob/
|
|
703
|
+
[packages/ditox/src/ditox.ts:31](https://github.com/mnasyrov/ditox/blob/37f658c/packages/ditox/src/ditox.ts#L31)
|
|
887
704
|
|
|
888
|
-
|
|
705
|
+
---
|
|
889
706
|
|
|
890
707
|
### tryResolveValue
|
|
891
708
|
|
|
@@ -898,7 +715,8 @@ then returns an object containing resolved values as properties.
|
|
|
898
715
|
|
|
899
716
|
If a token is not found, then `undefined` value is used.
|
|
900
717
|
|
|
901
|
-
**`
|
|
718
|
+
**`Example`**
|
|
719
|
+
|
|
902
720
|
```ts
|
|
903
721
|
const value = tryResolveValue(container, tokenA);
|
|
904
722
|
console.log(value); // 1
|
|
@@ -909,17 +727,17 @@ console.log(props); // {a: 1, b: 2}
|
|
|
909
727
|
|
|
910
728
|
#### Type parameters
|
|
911
729
|
|
|
912
|
-
| Name
|
|
913
|
-
|
|
|
914
|
-
| `Tokens` | extends [`Token`](README.md#token)<`unknown`\> \| { [key: string]
|
|
915
|
-
| `Values` | extends `unknown`
|
|
730
|
+
| Name | Type |
|
|
731
|
+
| :------- | :------------------------------------------------------------------------------------------------------------- |
|
|
732
|
+
| `Tokens` | extends [`Token`](README.md#token)<`unknown`\> \| { `[key: string]`: [`Token`](README.md#token)<`unknown`\>; } |
|
|
733
|
+
| `Values` | extends `unknown` |
|
|
916
734
|
|
|
917
735
|
#### Parameters
|
|
918
736
|
|
|
919
|
-
| Name
|
|
920
|
-
|
|
|
737
|
+
| Name | Type |
|
|
738
|
+
| :---------- | :--------------------------------- |
|
|
921
739
|
| `container` | [`Container`](README.md#container) |
|
|
922
|
-
| `token`
|
|
740
|
+
| `token` | `Tokens` |
|
|
923
741
|
|
|
924
742
|
#### Returns
|
|
925
743
|
|
|
@@ -927,13 +745,13 @@ console.log(props); // {a: 1, b: 2}
|
|
|
927
745
|
|
|
928
746
|
#### Defined in
|
|
929
747
|
|
|
930
|
-
[packages/ditox/src/utils.ts:54](https://github.com/mnasyrov/ditox/blob/
|
|
748
|
+
[packages/ditox/src/utils.ts:54](https://github.com/mnasyrov/ditox/blob/37f658c/packages/ditox/src/utils.ts#L54)
|
|
931
749
|
|
|
932
|
-
|
|
750
|
+
---
|
|
933
751
|
|
|
934
752
|
### tryResolveValues
|
|
935
753
|
|
|
936
|
-
▸ **tryResolveValues**<`Tokens`, `Values`\>(`container`,
|
|
754
|
+
▸ **tryResolveValues**<`Tokens`, `Values`\>(`container`, `...tokens`): `Values`
|
|
937
755
|
|
|
938
756
|
Returns an array of resolved values or objects with resolved values.
|
|
939
757
|
|
|
@@ -942,7 +760,8 @@ then returns an object containing resolved values as properties.
|
|
|
942
760
|
|
|
943
761
|
If a token is not found, then `undefined` value is used.
|
|
944
762
|
|
|
945
|
-
**`
|
|
763
|
+
**`Example`**
|
|
764
|
+
|
|
946
765
|
```ts
|
|
947
766
|
const items1 = tryResolveValues(container, tokenA);
|
|
948
767
|
console.log(items1); // [1]
|
|
@@ -953,17 +772,17 @@ console.log(items2); // [1, {a: 1, b: 2}]
|
|
|
953
772
|
|
|
954
773
|
#### Type parameters
|
|
955
774
|
|
|
956
|
-
| Name
|
|
957
|
-
|
|
|
958
|
-
| `Tokens` | extends ([`Token`](README.md#token)<`unknown`\> \| { [key: string]
|
|
775
|
+
| Name | Type |
|
|
776
|
+
| :------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
777
|
+
| `Tokens` | extends ([`Token`](README.md#token)<`unknown`\> \| { `[key: string]`: [`Token`](README.md#token)<`unknown`\>; })[] |
|
|
959
778
|
| `Values` | extends { [K in string \| number \| symbol]: Tokens[K] extends Token<V\> ? undefined \| V : Tokens[K] extends TokenProps<Props\> ? Partial<Props\> : never } |
|
|
960
779
|
|
|
961
780
|
#### Parameters
|
|
962
781
|
|
|
963
|
-
| Name
|
|
964
|
-
|
|
|
782
|
+
| Name | Type |
|
|
783
|
+
| :---------- | :--------------------------------- |
|
|
965
784
|
| `container` | [`Container`](README.md#container) |
|
|
966
|
-
| `...tokens` | `Tokens`
|
|
785
|
+
| `...tokens` | `Tokens` |
|
|
967
786
|
|
|
968
787
|
#### Returns
|
|
969
788
|
|
|
@@ -971,4 +790,4 @@ console.log(items2); // [1, {a: 1, b: 2}]
|
|
|
971
790
|
|
|
972
791
|
#### Defined in
|
|
973
792
|
|
|
974
|
-
[packages/ditox/src/utils.ts:88](https://github.com/mnasyrov/ditox/blob/
|
|
793
|
+
[packages/ditox/src/utils.ts:88](https://github.com/mnasyrov/ditox/blob/37f658c/packages/ditox/src/utils.ts#L88)
|