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