ditox 1.4.2 → 2.0.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 +1 -1
- package/dist/{index.d.ts → browser/index.d.ts} +0 -0
- 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 +5 -0
- package/dist/cjs/index.js +22 -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/{src/utils.js.flow → dist/cjs/utils.d.ts} +21 -60
- package/dist/cjs/utils.js +98 -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 +5 -0
- package/dist/esm/index.js +4 -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.d.ts +74 -0
- package/dist/esm/utils.js +88 -0
- package/dist/esm/utils.js.map +1 -0
- package/{lib → dist/umd}/index.d.ts +0 -0
- package/dist/umd/index.js +2 -0
- package/dist/umd/index.js.map +1 -0
- package/docs/.nojekyll +1 -0
- package/docs/README.md +111 -96
- package/docs/classes/{resolvererror.md → ResolverError.md} +14 -12
- package/package.json +15 -16
- package/src/ditox.test.ts +10 -1
- package/src/index.ts +8 -9
- package/src/modules.test.ts +2 -0
- package/CHANGELOG.md +0 -132
- 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/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
|
|
|
@@ -56,7 +56,7 @@ Options for module binding.
|
|
|
56
56
|
|
|
57
57
|
#### Defined in
|
|
58
58
|
|
|
59
|
-
[packages/ditox/src/modules.ts:83](https://github.com/mnasyrov/ditox/blob/
|
|
59
|
+
[packages/ditox/src/modules.ts:83](https://github.com/mnasyrov/ditox/blob/8c2302d/packages/ditox/src/modules.ts#L83)
|
|
60
60
|
|
|
61
61
|
___
|
|
62
62
|
|
|
@@ -70,23 +70,23 @@ Dependency container.
|
|
|
70
70
|
|
|
71
71
|
| Name | Type |
|
|
72
72
|
| :------ | :------ |
|
|
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)
|
|
73
|
+
| `bindFactory` | <T\>(`token`: [`Token`](README.md#token)<`T`\>, `factory`: (`container`: [`Container`](README.md#container)) => `T`, `options?`: [`FactoryOptions`](README.md#factoryoptions)<`T`\>) => `void` |
|
|
74
|
+
| `bindValue` | <T\>(`token`: [`Token`](README.md#token)<`T`\>, `value`: `T`) => `void` |
|
|
75
|
+
| `get` | <T\>(`token`: [`Token`](README.md#token)<`T`\>) => `undefined` \| `T` |
|
|
76
|
+
| `hasToken` | (`token`: [`Token`](README.md#token)<`unknown`\>) => `boolean` |
|
|
77
|
+
| `remove` | <T\>(`token`: [`Token`](README.md#token)<`T`\>) => `void` |
|
|
78
78
|
| `removeAll` | () => `void` |
|
|
79
|
-
| `resolve` | <T\>(`token`: [Token](README.md#token)
|
|
79
|
+
| `resolve` | <T\>(`token`: [`Token`](README.md#token)<`T`\>) => `T` |
|
|
80
80
|
|
|
81
81
|
#### Defined in
|
|
82
82
|
|
|
83
|
-
[packages/ditox/src/ditox.ts:95](https://github.com/mnasyrov/ditox/blob/
|
|
83
|
+
[packages/ditox/src/ditox.ts:95](https://github.com/mnasyrov/ditox/blob/8c2302d/packages/ditox/src/ditox.ts#L95)
|
|
84
84
|
|
|
85
85
|
___
|
|
86
86
|
|
|
87
87
|
### FactoryOptions
|
|
88
88
|
|
|
89
|
-
Ƭ **FactoryOptions
|
|
89
|
+
Ƭ **FactoryOptions**<`T`\>: { `scope?`: ``"scoped"`` \| ``"singleton"`` ; `onRemoved?`: (`value`: `T`) => `void` } \| { `scope`: ``"transient"`` }
|
|
90
90
|
|
|
91
91
|
Options for factory binding.
|
|
92
92
|
|
|
@@ -105,7 +105,7 @@ Options for factory binding.
|
|
|
105
105
|
|
|
106
106
|
#### Defined in
|
|
107
107
|
|
|
108
|
-
[packages/ditox/src/ditox.ts:83](https://github.com/mnasyrov/ditox/blob/
|
|
108
|
+
[packages/ditox/src/ditox.ts:83](https://github.com/mnasyrov/ditox/blob/8c2302d/packages/ditox/src/ditox.ts#L83)
|
|
109
109
|
|
|
110
110
|
___
|
|
111
111
|
|
|
@@ -117,13 +117,13 @@ ___
|
|
|
117
117
|
|
|
118
118
|
#### Defined in
|
|
119
119
|
|
|
120
|
-
[packages/ditox/src/ditox.ts:71](https://github.com/mnasyrov/ditox/blob/
|
|
120
|
+
[packages/ditox/src/ditox.ts:71](https://github.com/mnasyrov/ditox/blob/8c2302d/packages/ditox/src/ditox.ts#L71)
|
|
121
121
|
|
|
122
122
|
___
|
|
123
123
|
|
|
124
124
|
### Module
|
|
125
125
|
|
|
126
|
-
Ƭ **Module
|
|
126
|
+
Ƭ **Module**<`ModuleProps`\>: `ModuleController` & `ModuleProps`
|
|
127
127
|
|
|
128
128
|
Dependency module
|
|
129
129
|
|
|
@@ -138,27 +138,27 @@ type LoggerModule = Module<{
|
|
|
138
138
|
|
|
139
139
|
| Name | Type |
|
|
140
140
|
| :------ | :------ |
|
|
141
|
-
| `ModuleProps` |
|
|
141
|
+
| `ModuleProps` | extends `AnyObject` = `EmptyObject` |
|
|
142
142
|
|
|
143
143
|
#### Defined in
|
|
144
144
|
|
|
145
|
-
[packages/ditox/src/modules.ts:22](https://github.com/mnasyrov/ditox/blob/
|
|
145
|
+
[packages/ditox/src/modules.ts:22](https://github.com/mnasyrov/ditox/blob/8c2302d/packages/ditox/src/modules.ts#L22)
|
|
146
146
|
|
|
147
147
|
___
|
|
148
148
|
|
|
149
149
|
### ModuleBindingEntry
|
|
150
150
|
|
|
151
|
-
Ƭ **ModuleBindingEntry**: [ModuleDeclaration](README.md#moduledeclaration)
|
|
151
|
+
Ƭ **ModuleBindingEntry**: [`ModuleDeclaration`](README.md#moduledeclaration)<`AnyObject`\> \| { `module`: [`ModuleDeclaration`](README.md#moduledeclaration)<`AnyObject`\> ; `options`: [`BindModuleOptions`](README.md#bindmoduleoptions) }
|
|
152
152
|
|
|
153
153
|
#### Defined in
|
|
154
154
|
|
|
155
|
-
[packages/ditox/src/modules.ts:87](https://github.com/mnasyrov/ditox/blob/
|
|
155
|
+
[packages/ditox/src/modules.ts:87](https://github.com/mnasyrov/ditox/blob/8c2302d/packages/ditox/src/modules.ts#L87)
|
|
156
156
|
|
|
157
157
|
___
|
|
158
158
|
|
|
159
159
|
### ModuleDeclaration
|
|
160
160
|
|
|
161
|
-
Ƭ **ModuleDeclaration
|
|
161
|
+
Ƭ **ModuleDeclaration**<`T`\>: `Object`
|
|
162
162
|
|
|
163
163
|
Description how to bind the module in declarative way.
|
|
164
164
|
|
|
@@ -183,29 +183,29 @@ const LOGGER_MODULE: ModuleDeclaration<LoggerModule> = {
|
|
|
183
183
|
|
|
184
184
|
| Name | Type |
|
|
185
185
|
| :------ | :------ |
|
|
186
|
-
| `T` |
|
|
186
|
+
| `T` | extends [`Module`](README.md#module)<`AnyObject`\> |
|
|
187
187
|
|
|
188
188
|
#### Type declaration
|
|
189
189
|
|
|
190
190
|
| Name | Type | Description |
|
|
191
191
|
| :------ | :------ | :------ |
|
|
192
|
-
| `
|
|
193
|
-
| `
|
|
194
|
-
| `
|
|
195
|
-
| `
|
|
196
|
-
| `
|
|
197
|
-
| `
|
|
198
|
-
| `
|
|
192
|
+
| `exportedProps?` | [`ModuleDeclaration`](README.md#moduledeclaration)<`T`\>[``"exports"``] | Dictionary of module properties which are bound to tokens. **`deprecated`** Use `exports` property. |
|
|
193
|
+
| `exports?` | { [K in keyof GetModuleProps<T\>]?: Token<GetModuleProps<T\>[K]\> } | Dictionary of module properties which are bound to tokens. |
|
|
194
|
+
| `imports?` | `ReadonlyArray`<[`ModuleBindingEntry`](README.md#modulebindingentry)\> | Modules for binding |
|
|
195
|
+
| `token` | [`Token`](README.md#token)<`T`\> | Token for the module |
|
|
196
|
+
| `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. |
|
|
197
|
+
| `beforeBinding?` | (`container`: [`Container`](README.md#container)) => `void` | Callback could be used to prepare an environment. It is called before binding the module. |
|
|
198
|
+
| `factory` | (`container`: [`Container`](README.md#container)) => `T` | Factory of the module |
|
|
199
199
|
|
|
200
200
|
#### Defined in
|
|
201
201
|
|
|
202
|
-
[packages/ditox/src/modules.ts:47](https://github.com/mnasyrov/ditox/blob/
|
|
202
|
+
[packages/ditox/src/modules.ts:47](https://github.com/mnasyrov/ditox/blob/8c2302d/packages/ditox/src/modules.ts#L47)
|
|
203
203
|
|
|
204
204
|
___
|
|
205
205
|
|
|
206
206
|
### Token
|
|
207
207
|
|
|
208
|
-
Ƭ **Token
|
|
208
|
+
Ƭ **Token**<`T`\>: `RequiredToken`<`T`\> \| `OptionalToken`<`T`\>
|
|
209
209
|
|
|
210
210
|
Binding token.
|
|
211
211
|
|
|
@@ -217,13 +217,13 @@ Binding token.
|
|
|
217
217
|
|
|
218
218
|
#### Defined in
|
|
219
219
|
|
|
220
|
-
[packages/ditox/src/ditox.ts:25](https://github.com/mnasyrov/ditox/blob/
|
|
220
|
+
[packages/ditox/src/ditox.ts:25](https://github.com/mnasyrov/ditox/blob/8c2302d/packages/ditox/src/ditox.ts#L25)
|
|
221
221
|
|
|
222
222
|
## Functions
|
|
223
223
|
|
|
224
224
|
### bindModule
|
|
225
225
|
|
|
226
|
-
▸ **bindModule
|
|
226
|
+
▸ **bindModule**<`T`\>(`container`, `moduleDeclaration`, `options?`): `void`
|
|
227
227
|
|
|
228
228
|
Binds the dependency module to the container
|
|
229
229
|
|
|
@@ -236,15 +236,15 @@ bindModule(container, LOGGER_MODULE);
|
|
|
236
236
|
|
|
237
237
|
| Name | Type |
|
|
238
238
|
| :------ | :------ |
|
|
239
|
-
| `T` |
|
|
239
|
+
| `T` | extends [`Module`](README.md#module)<`AnyObject`\> |
|
|
240
240
|
|
|
241
241
|
#### Parameters
|
|
242
242
|
|
|
243
243
|
| Name | Type | Description |
|
|
244
244
|
| :------ | :------ | :------ |
|
|
245
|
-
| `container` | [Container](README.md#container) | Dependency container. |
|
|
246
|
-
| `moduleDeclaration` | [ModuleDeclaration](README.md#moduledeclaration)
|
|
247
|
-
| `options?` | [BindModuleOptions](README.md#bindmoduleoptions) | Options for module binding. |
|
|
245
|
+
| `container` | [`Container`](README.md#container) | Dependency container. |
|
|
246
|
+
| `moduleDeclaration` | [`ModuleDeclaration`](README.md#moduledeclaration)<`T`\> | Declaration of the dependency module. |
|
|
247
|
+
| `options?` | [`BindModuleOptions`](README.md#bindmoduleoptions) | Options for module binding. |
|
|
248
248
|
|
|
249
249
|
#### Returns
|
|
250
250
|
|
|
@@ -252,7 +252,7 @@ bindModule(container, LOGGER_MODULE);
|
|
|
252
252
|
|
|
253
253
|
#### Defined in
|
|
254
254
|
|
|
255
|
-
[packages/ditox/src/modules.ts:105](https://github.com/mnasyrov/ditox/blob/
|
|
255
|
+
[packages/ditox/src/modules.ts:105](https://github.com/mnasyrov/ditox/blob/8c2302d/packages/ditox/src/modules.ts#L105)
|
|
256
256
|
|
|
257
257
|
___
|
|
258
258
|
|
|
@@ -266,8 +266,8 @@ Binds dependency modules to the container
|
|
|
266
266
|
|
|
267
267
|
| Name | Type | Description |
|
|
268
268
|
| :------ | :------ | :------ |
|
|
269
|
-
| `container` | [Container](README.md#container) | Dependency container for binding |
|
|
270
|
-
| `modules` | `
|
|
269
|
+
| `container` | [`Container`](README.md#container) | Dependency container for binding |
|
|
270
|
+
| `modules` | readonly [`ModuleBindingEntry`](README.md#modulebindingentry)[] | Array of module binding entries: module declaration or `{module: ModuleDeclaration, options: BindModuleOptions}` objects. |
|
|
271
271
|
|
|
272
272
|
#### Returns
|
|
273
273
|
|
|
@@ -275,13 +275,13 @@ Binds dependency modules to the container
|
|
|
275
275
|
|
|
276
276
|
#### Defined in
|
|
277
277
|
|
|
278
|
-
[packages/ditox/src/modules.ts:166](https://github.com/mnasyrov/ditox/blob/
|
|
278
|
+
[packages/ditox/src/modules.ts:166](https://github.com/mnasyrov/ditox/blob/8c2302d/packages/ditox/src/modules.ts#L166)
|
|
279
279
|
|
|
280
280
|
___
|
|
281
281
|
|
|
282
282
|
### bindMultiValue
|
|
283
283
|
|
|
284
|
-
▸ **bindMultiValue
|
|
284
|
+
▸ **bindMultiValue**<`T`\>(`container`, `token`, `value`): `void`
|
|
285
285
|
|
|
286
286
|
Rebinds the array by the token with added new value.
|
|
287
287
|
|
|
@@ -295,8 +295,8 @@ Rebinds the array by the token with added new value.
|
|
|
295
295
|
|
|
296
296
|
| Name | Type | Description |
|
|
297
297
|
| :------ | :------ | :------ |
|
|
298
|
-
| `container` | [Container](README.md#container) | Dependency container. |
|
|
299
|
-
| `token` | [Token](README.md#token)<
|
|
298
|
+
| `container` | [`Container`](README.md#container) | Dependency container. |
|
|
299
|
+
| `token` | [`Token`](README.md#token)<readonly `T`[]\> | Token for an array of values. |
|
|
300
300
|
| `value` | `T` | New value which is added to the end of the array. |
|
|
301
301
|
|
|
302
302
|
#### Returns
|
|
@@ -305,13 +305,13 @@ Rebinds the array by the token with added new value.
|
|
|
305
305
|
|
|
306
306
|
#### Defined in
|
|
307
307
|
|
|
308
|
-
[packages/ditox/src/utils.ts:14](https://github.com/mnasyrov/ditox/blob/
|
|
308
|
+
[packages/ditox/src/utils.ts:14](https://github.com/mnasyrov/ditox/blob/8c2302d/packages/ditox/src/utils.ts#L14)
|
|
309
309
|
|
|
310
310
|
___
|
|
311
311
|
|
|
312
312
|
### createContainer
|
|
313
313
|
|
|
314
|
-
▸ **createContainer**(`parentContainer?`): [Container](README.md#container)
|
|
314
|
+
▸ **createContainer**(`parentContainer?`): [`Container`](README.md#container)
|
|
315
315
|
|
|
316
316
|
Creates a new dependency container.
|
|
317
317
|
|
|
@@ -321,21 +321,21 @@ Container can have an optional parent to chain token resolution. The parent is u
|
|
|
321
321
|
|
|
322
322
|
| Name | Type | Description |
|
|
323
323
|
| :------ | :------ | :------ |
|
|
324
|
-
| `parentContainer?` | [Container](README.md#container) | Optional parent container. |
|
|
324
|
+
| `parentContainer?` | [`Container`](README.md#container) | Optional parent container. |
|
|
325
325
|
|
|
326
326
|
#### Returns
|
|
327
327
|
|
|
328
|
-
[Container](README.md#container)
|
|
328
|
+
[`Container`](README.md#container)
|
|
329
329
|
|
|
330
330
|
#### Defined in
|
|
331
331
|
|
|
332
|
-
[packages/ditox/src/ditox.ts:204](https://github.com/mnasyrov/ditox/blob/
|
|
332
|
+
[packages/ditox/src/ditox.ts:204](https://github.com/mnasyrov/ditox/blob/8c2302d/packages/ditox/src/ditox.ts#L204)
|
|
333
333
|
|
|
334
334
|
___
|
|
335
335
|
|
|
336
336
|
### declareModule
|
|
337
337
|
|
|
338
|
-
▸ **declareModule
|
|
338
|
+
▸ **declareModule**<`T`\>(`declaration`): [`ModuleDeclaration`](README.md#moduledeclaration)<`T`\>
|
|
339
339
|
|
|
340
340
|
Declares a module binding
|
|
341
341
|
|
|
@@ -365,21 +365,21 @@ const LOGGER_MODULE = declareModule<LoggerModule>({
|
|
|
365
365
|
|
|
366
366
|
| Name | Type | Description |
|
|
367
367
|
| :------ | :------ | :------ |
|
|
368
|
-
| `declaration` | `Omit`<[ModuleDeclaration](README.md#moduledeclaration)
|
|
368
|
+
| `declaration` | `Omit`<[`ModuleDeclaration`](README.md#moduledeclaration)<`T`\>, ``"token"``\> & `Partial`<`Pick`<[`ModuleDeclaration`](README.md#moduledeclaration)<`T`\>, ``"token"``\>\> | a module declaration |
|
|
369
369
|
|
|
370
370
|
#### Returns
|
|
371
371
|
|
|
372
|
-
[ModuleDeclaration](README.md#moduledeclaration)
|
|
372
|
+
[`ModuleDeclaration`](README.md#moduledeclaration)<`T`\>
|
|
373
373
|
|
|
374
374
|
#### Defined in
|
|
375
375
|
|
|
376
|
-
[packages/ditox/src/modules.ts:201](https://github.com/mnasyrov/ditox/blob/
|
|
376
|
+
[packages/ditox/src/modules.ts:201](https://github.com/mnasyrov/ditox/blob/8c2302d/packages/ditox/src/modules.ts#L201)
|
|
377
377
|
|
|
378
378
|
___
|
|
379
379
|
|
|
380
380
|
### declareModuleBindings
|
|
381
381
|
|
|
382
|
-
▸ **declareModuleBindings**(`modules`): [ModuleDeclaration](README.md#moduledeclaration)<[Module](README.md#module)\>
|
|
382
|
+
▸ **declareModuleBindings**(`modules`): [`ModuleDeclaration`](README.md#moduledeclaration)<[`Module`](README.md#module)\>
|
|
383
383
|
|
|
384
384
|
Declares bindings of several modules
|
|
385
385
|
|
|
@@ -387,21 +387,21 @@ Declares bindings of several modules
|
|
|
387
387
|
|
|
388
388
|
| Name | Type | Description |
|
|
389
389
|
| :------ | :------ | :------ |
|
|
390
|
-
| `modules` | `
|
|
390
|
+
| `modules` | readonly [`ModuleBindingEntry`](README.md#modulebindingentry)[] | module declaration entries |
|
|
391
391
|
|
|
392
392
|
#### Returns
|
|
393
393
|
|
|
394
|
-
[ModuleDeclaration](README.md#moduledeclaration)<[Module](README.md#module)\>
|
|
394
|
+
[`ModuleDeclaration`](README.md#moduledeclaration)<[`Module`](README.md#module)\>
|
|
395
395
|
|
|
396
396
|
#### Defined in
|
|
397
397
|
|
|
398
|
-
[packages/ditox/src/modules.ts:213](https://github.com/mnasyrov/ditox/blob/
|
|
398
|
+
[packages/ditox/src/modules.ts:213](https://github.com/mnasyrov/ditox/blob/8c2302d/packages/ditox/src/modules.ts#L213)
|
|
399
399
|
|
|
400
400
|
___
|
|
401
401
|
|
|
402
402
|
### getProps
|
|
403
403
|
|
|
404
|
-
▸ **getProps
|
|
404
|
+
▸ **getProps**<`Props`\>(`container`, `tokens`): `Partial`<`Props`\>
|
|
405
405
|
|
|
406
406
|
Returns an object with resolved properties which are specified by token properties.
|
|
407
407
|
If a token is not found, then `undefined` value is used.
|
|
@@ -416,28 +416,28 @@ console.log(props); // {a: 1, b: 2}
|
|
|
416
416
|
|
|
417
417
|
| Name | Type |
|
|
418
418
|
| :------ | :------ |
|
|
419
|
-
| `Props` |
|
|
419
|
+
| `Props` | extends `ValuesProps` |
|
|
420
420
|
|
|
421
421
|
#### Parameters
|
|
422
422
|
|
|
423
423
|
| Name | Type |
|
|
424
424
|
| :------ | :------ |
|
|
425
|
-
| `container` | [Container](README.md#container) |
|
|
426
|
-
| `tokens` | `TokenProps
|
|
425
|
+
| `container` | [`Container`](README.md#container) |
|
|
426
|
+
| `tokens` | `TokenProps`<`Props`\> |
|
|
427
427
|
|
|
428
428
|
#### Returns
|
|
429
429
|
|
|
430
|
-
`Partial
|
|
430
|
+
`Partial`<`Props`\>
|
|
431
431
|
|
|
432
432
|
#### Defined in
|
|
433
433
|
|
|
434
|
-
[packages/ditox/src/utils.ts:83](https://github.com/mnasyrov/ditox/blob/
|
|
434
|
+
[packages/ditox/src/utils.ts:83](https://github.com/mnasyrov/ditox/blob/8c2302d/packages/ditox/src/utils.ts#L83)
|
|
435
435
|
|
|
436
436
|
___
|
|
437
437
|
|
|
438
438
|
### getValues
|
|
439
439
|
|
|
440
|
-
▸ **getValues
|
|
440
|
+
▸ **getValues**<`Tokens`, `Values`\>(`container`, ...`tokens`): `Values`
|
|
441
441
|
|
|
442
442
|
Returns an array of resolved values by the specified token.
|
|
443
443
|
If a token is not found, then `undefined` value is used.
|
|
@@ -446,14 +446,14 @@ If a token is not found, then `undefined` value is used.
|
|
|
446
446
|
|
|
447
447
|
| Name | Type |
|
|
448
448
|
| :------ | :------ |
|
|
449
|
-
| `Tokens` |
|
|
450
|
-
| `Values` |
|
|
449
|
+
| `Tokens` | extends [`Token`](README.md#token)<`unknown`\>[] |
|
|
450
|
+
| `Values` | extends { [K in string \| number \| symbol]: Tokens[K] extends Token<V\> ? V : never } |
|
|
451
451
|
|
|
452
452
|
#### Parameters
|
|
453
453
|
|
|
454
454
|
| Name | Type |
|
|
455
455
|
| :------ | :------ |
|
|
456
|
-
| `container` | [Container](README.md#container) |
|
|
456
|
+
| `container` | [`Container`](README.md#container) |
|
|
457
457
|
| `...tokens` | `Tokens` |
|
|
458
458
|
|
|
459
459
|
#### Returns
|
|
@@ -462,13 +462,13 @@ If a token is not found, then `undefined` value is used.
|
|
|
462
462
|
|
|
463
463
|
#### Defined in
|
|
464
464
|
|
|
465
|
-
[packages/ditox/src/utils.ts:28](https://github.com/mnasyrov/ditox/blob/
|
|
465
|
+
[packages/ditox/src/utils.ts:28](https://github.com/mnasyrov/ditox/blob/8c2302d/packages/ditox/src/utils.ts#L28)
|
|
466
466
|
|
|
467
467
|
___
|
|
468
468
|
|
|
469
469
|
### injectable
|
|
470
470
|
|
|
471
|
-
▸ **injectable
|
|
471
|
+
▸ **injectable**<`Tokens`, `Values`, `Result`\>(`factory`, ...`tokens`): (`container`: [`Container`](README.md#container)) => `Result`
|
|
472
472
|
|
|
473
473
|
Decorates a factory by passing resolved tokens as factory arguments.
|
|
474
474
|
|
|
@@ -476,8 +476,8 @@ Decorates a factory by passing resolved tokens as factory arguments.
|
|
|
476
476
|
|
|
477
477
|
| Name | Type |
|
|
478
478
|
| :------ | :------ |
|
|
479
|
-
| `Tokens` |
|
|
480
|
-
| `Values` |
|
|
479
|
+
| `Tokens` | extends [`Token`](README.md#token)<`unknown`\>[] |
|
|
480
|
+
| `Values` | extends { [K in string \| number \| symbol]: Tokens[K] extends Token<V\> ? V : never } |
|
|
481
481
|
| `Result` | `Result` |
|
|
482
482
|
|
|
483
483
|
#### Parameters
|
|
@@ -495,25 +495,29 @@ Decorated factory which takes a dependency container as a single argument.
|
|
|
495
495
|
|
|
496
496
|
▸ (`container`): `Result`
|
|
497
497
|
|
|
498
|
+
Decorates a factory by passing resolved tokens as factory arguments.
|
|
499
|
+
|
|
498
500
|
##### Parameters
|
|
499
501
|
|
|
500
502
|
| Name | Type |
|
|
501
503
|
| :------ | :------ |
|
|
502
|
-
| `container` | [Container](README.md#container) |
|
|
504
|
+
| `container` | [`Container`](README.md#container) |
|
|
503
505
|
|
|
504
506
|
##### Returns
|
|
505
507
|
|
|
506
508
|
`Result`
|
|
507
509
|
|
|
510
|
+
Decorated factory which takes a dependency container as a single argument.
|
|
511
|
+
|
|
508
512
|
#### Defined in
|
|
509
513
|
|
|
510
|
-
[packages/ditox/src/utils.ts:56](https://github.com/mnasyrov/ditox/blob/
|
|
514
|
+
[packages/ditox/src/utils.ts:56](https://github.com/mnasyrov/ditox/blob/8c2302d/packages/ditox/src/utils.ts#L56)
|
|
511
515
|
|
|
512
516
|
___
|
|
513
517
|
|
|
514
518
|
### injectableProps
|
|
515
519
|
|
|
516
|
-
▸ **injectableProps
|
|
520
|
+
▸ **injectableProps**<`Props`, `Result`\>(`factory`, `tokens`): (`container`: [`Container`](README.md#container)) => `Result`
|
|
517
521
|
|
|
518
522
|
Decorates a factory by passing a resolved object with tokens as the first argument.
|
|
519
523
|
|
|
@@ -528,7 +532,7 @@ const result = decoratedFactory(container);
|
|
|
528
532
|
|
|
529
533
|
| Name | Type |
|
|
530
534
|
| :------ | :------ |
|
|
531
|
-
| `Props` |
|
|
535
|
+
| `Props` | extends `ValuesProps` |
|
|
532
536
|
| `Result` | `Result` |
|
|
533
537
|
|
|
534
538
|
#### Parameters
|
|
@@ -536,7 +540,7 @@ const result = decoratedFactory(container);
|
|
|
536
540
|
| Name | Type | Description |
|
|
537
541
|
| :------ | :------ | :------ |
|
|
538
542
|
| `factory` | (`props`: `Props`) => `Result` | A factory. |
|
|
539
|
-
| `tokens` | `TokenProps
|
|
543
|
+
| `tokens` | `TokenProps`<`Props`\> | Object with tokens. |
|
|
540
544
|
|
|
541
545
|
#### Returns
|
|
542
546
|
|
|
@@ -546,25 +550,36 @@ Decorated factory which takes a dependency container as a single argument.
|
|
|
546
550
|
|
|
547
551
|
▸ (`container`): `Result`
|
|
548
552
|
|
|
553
|
+
Decorates a factory by passing a resolved object with tokens as the first argument.
|
|
554
|
+
|
|
555
|
+
**`example`**
|
|
556
|
+
```ts
|
|
557
|
+
const factory = ({a, b}: {a: number, b: number}) => a + b;
|
|
558
|
+
const decoratedFactory = injectableProps(factory, {a: tokenA, b: tokenB});
|
|
559
|
+
const result = decoratedFactory(container);
|
|
560
|
+
```
|
|
561
|
+
|
|
549
562
|
##### Parameters
|
|
550
563
|
|
|
551
564
|
| Name | Type |
|
|
552
565
|
| :------ | :------ |
|
|
553
|
-
| `container` | [Container](README.md#container) |
|
|
566
|
+
| `container` | [`Container`](README.md#container) |
|
|
554
567
|
|
|
555
568
|
##### Returns
|
|
556
569
|
|
|
557
570
|
`Result`
|
|
558
571
|
|
|
572
|
+
Decorated factory which takes a dependency container as a single argument.
|
|
573
|
+
|
|
559
574
|
#### Defined in
|
|
560
575
|
|
|
561
|
-
[packages/ditox/src/utils.ts:124](https://github.com/mnasyrov/ditox/blob/
|
|
576
|
+
[packages/ditox/src/utils.ts:124](https://github.com/mnasyrov/ditox/blob/8c2302d/packages/ditox/src/utils.ts#L124)
|
|
562
577
|
|
|
563
578
|
___
|
|
564
579
|
|
|
565
580
|
### optional
|
|
566
581
|
|
|
567
|
-
▸ **optional
|
|
582
|
+
▸ **optional**<`T`\>(`token`, `optionalValue`): `OptionalToken`<`T`\>
|
|
568
583
|
|
|
569
584
|
Decorate a token with an optional value.
|
|
570
585
|
This value is be used as default value in case a container does not have registered token.
|
|
@@ -579,18 +594,18 @@ This value is be used as default value in case a container does not have registe
|
|
|
579
594
|
|
|
580
595
|
| Name | Type | Description |
|
|
581
596
|
| :------ | :------ | :------ |
|
|
582
|
-
| `token` | [Token](README.md#token)
|
|
597
|
+
| `token` | [`Token`](README.md#token)<`T`\> | Existed token. |
|
|
583
598
|
| `optionalValue` | `T` | Default value for the resolver. |
|
|
584
599
|
|
|
585
600
|
#### Returns
|
|
586
601
|
|
|
587
|
-
`OptionalToken
|
|
602
|
+
`OptionalToken`<`T`\>
|
|
588
603
|
|
|
589
604
|
#### Defined in
|
|
590
605
|
|
|
591
|
-
[packages/ditox/src/ditox.ts:41](https://github.com/mnasyrov/ditox/blob/
|
|
606
|
+
[packages/ditox/src/ditox.ts:41](https://github.com/mnasyrov/ditox/blob/8c2302d/packages/ditox/src/ditox.ts#L41)
|
|
592
607
|
|
|
593
|
-
▸ **optional
|
|
608
|
+
▸ **optional**<`T`\>(`token`): `OptionalToken`<`T` \| `undefined`\>
|
|
594
609
|
|
|
595
610
|
#### Type parameters
|
|
596
611
|
|
|
@@ -602,21 +617,21 @@ This value is be used as default value in case a container does not have registe
|
|
|
602
617
|
|
|
603
618
|
| Name | Type |
|
|
604
619
|
| :------ | :------ |
|
|
605
|
-
| `token` | [Token](README.md#token)
|
|
620
|
+
| `token` | [`Token`](README.md#token)<`T`\> |
|
|
606
621
|
|
|
607
622
|
#### Returns
|
|
608
623
|
|
|
609
|
-
`OptionalToken
|
|
624
|
+
`OptionalToken`<`T` \| `undefined`\>
|
|
610
625
|
|
|
611
626
|
#### Defined in
|
|
612
627
|
|
|
613
|
-
[packages/ditox/src/ditox.ts:45](https://github.com/mnasyrov/ditox/blob/
|
|
628
|
+
[packages/ditox/src/ditox.ts:45](https://github.com/mnasyrov/ditox/blob/8c2302d/packages/ditox/src/ditox.ts#L45)
|
|
614
629
|
|
|
615
630
|
___
|
|
616
631
|
|
|
617
632
|
### resolveProps
|
|
618
633
|
|
|
619
|
-
▸ **resolveProps
|
|
634
|
+
▸ **resolveProps**<`Props`\>(`container`, `tokens`): `Props`
|
|
620
635
|
|
|
621
636
|
Returns an object with resolved properties which are specified by token properties.
|
|
622
637
|
If a token is not found, then `ResolverError` is thrown.
|
|
@@ -631,14 +646,14 @@ console.log(props); // {a: 1, b: 2}
|
|
|
631
646
|
|
|
632
647
|
| Name | Type |
|
|
633
648
|
| :------ | :------ |
|
|
634
|
-
| `Props` |
|
|
649
|
+
| `Props` | extends `ValuesProps` |
|
|
635
650
|
|
|
636
651
|
#### Parameters
|
|
637
652
|
|
|
638
653
|
| Name | Type |
|
|
639
654
|
| :------ | :------ |
|
|
640
|
-
| `container` | [Container](README.md#container) |
|
|
641
|
-
| `tokens` | `TokenProps
|
|
655
|
+
| `container` | [`Container`](README.md#container) |
|
|
656
|
+
| `tokens` | `TokenProps`<`Props`\> |
|
|
642
657
|
|
|
643
658
|
#### Returns
|
|
644
659
|
|
|
@@ -646,13 +661,13 @@ console.log(props); // {a: 1, b: 2}
|
|
|
646
661
|
|
|
647
662
|
#### Defined in
|
|
648
663
|
|
|
649
|
-
[packages/ditox/src/utils.ts:102](https://github.com/mnasyrov/ditox/blob/
|
|
664
|
+
[packages/ditox/src/utils.ts:102](https://github.com/mnasyrov/ditox/blob/8c2302d/packages/ditox/src/utils.ts#L102)
|
|
650
665
|
|
|
651
666
|
___
|
|
652
667
|
|
|
653
668
|
### resolveValues
|
|
654
669
|
|
|
655
|
-
▸ **resolveValues
|
|
670
|
+
▸ **resolveValues**<`Tokens`, `Values`\>(`container`, ...`tokens`): `Values`
|
|
656
671
|
|
|
657
672
|
Returns an array of resolved values by the specified token.
|
|
658
673
|
If a token is not found, then `ResolverError` is thrown.
|
|
@@ -661,14 +676,14 @@ If a token is not found, then `ResolverError` is thrown.
|
|
|
661
676
|
|
|
662
677
|
| Name | Type |
|
|
663
678
|
| :------ | :------ |
|
|
664
|
-
| `Tokens` |
|
|
665
|
-
| `Values` |
|
|
679
|
+
| `Tokens` | extends [`Token`](README.md#token)<`unknown`\>[] |
|
|
680
|
+
| `Values` | extends { [K in string \| number \| symbol]: Tokens[K] extends Token<V\> ? V : never } |
|
|
666
681
|
|
|
667
682
|
#### Parameters
|
|
668
683
|
|
|
669
684
|
| Name | Type |
|
|
670
685
|
| :------ | :------ |
|
|
671
|
-
| `container` | [Container](README.md#container) |
|
|
686
|
+
| `container` | [`Container`](README.md#container) |
|
|
672
687
|
| `...tokens` | `Tokens` |
|
|
673
688
|
|
|
674
689
|
#### Returns
|
|
@@ -677,13 +692,13 @@ If a token is not found, then `ResolverError` is thrown.
|
|
|
677
692
|
|
|
678
693
|
#### Defined in
|
|
679
694
|
|
|
680
|
-
[packages/ditox/src/utils.ts:41](https://github.com/mnasyrov/ditox/blob/
|
|
695
|
+
[packages/ditox/src/utils.ts:41](https://github.com/mnasyrov/ditox/blob/8c2302d/packages/ditox/src/utils.ts#L41)
|
|
681
696
|
|
|
682
697
|
___
|
|
683
698
|
|
|
684
699
|
### token
|
|
685
700
|
|
|
686
|
-
▸ **token
|
|
701
|
+
▸ **token**<`T`\>(`description?`): [`Token`](README.md#token)<`T`\>
|
|
687
702
|
|
|
688
703
|
Creates a new binding token.
|
|
689
704
|
|
|
@@ -701,8 +716,8 @@ Creates a new binding token.
|
|
|
701
716
|
|
|
702
717
|
#### Returns
|
|
703
718
|
|
|
704
|
-
[Token](README.md#token)
|
|
719
|
+
[`Token`](README.md#token)<`T`\>
|
|
705
720
|
|
|
706
721
|
#### Defined in
|
|
707
722
|
|
|
708
|
-
[packages/ditox/src/ditox.ts:31](https://github.com/mnasyrov/ditox/blob/
|
|
723
|
+
[packages/ditox/src/ditox.ts:31](https://github.com/mnasyrov/ditox/blob/8c2302d/packages/ditox/src/ditox.ts#L31)
|