ditox-react 2.2.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 +2 -2
- package/dist/browser/index.js.map +1 -1
- package/dist/cjs/DependencyContainer.d.ts +2 -2
- package/dist/cjs/DependencyContainer.js +5 -1
- package/dist/cjs/DependencyContainer.js.map +1 -1
- package/dist/cjs/DependencyModule.js +5 -1
- package/dist/cjs/DependencyModule.js.map +1 -1
- package/dist/esm/DependencyContainer.d.ts +2 -2
- package/dist/umd/index.d.ts +2 -2
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.map +1 -1
- package/docs/README.md +102 -56
- package/package.json +9 -10
- package/src/DependencyContainer.test.tsx +1 -2
- package/src/DependencyModule.test.tsx +1 -1
- package/src/hooks.test.tsx +14 -20
package/dist/browser/index.d.ts
CHANGED
|
@@ -4,13 +4,13 @@ import { ReactNode, ReactElement } from 'react';
|
|
|
4
4
|
/**
|
|
5
5
|
* A callback for binding dependencies to a container
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
type DependencyContainerBinder = (container: Container) => unknown;
|
|
8
8
|
/**
|
|
9
9
|
* Specifies an existed container or options for a new container:
|
|
10
10
|
* @property binder - A callback which setup bindings to the container.
|
|
11
11
|
* @property root - If `true` then a new container does not depend on any parent containers
|
|
12
12
|
*/
|
|
13
|
-
|
|
13
|
+
type DependencyContainerParams = {
|
|
14
14
|
children: ReactNode;
|
|
15
15
|
root?: boolean;
|
|
16
16
|
binder?: DependencyContainerBinder;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -4,13 +4,13 @@ export declare const DependencyContainerContext: React.Context<Container | undef
|
|
|
4
4
|
/**
|
|
5
5
|
* A callback for binding dependencies to a container
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
7
|
+
export type DependencyContainerBinder = (container: Container) => unknown;
|
|
8
8
|
/**
|
|
9
9
|
* Specifies an existed container or options for a new container:
|
|
10
10
|
* @property binder - A callback which setup bindings to the container.
|
|
11
11
|
* @property root - If `true` then a new container does not depend on any parent containers
|
|
12
12
|
*/
|
|
13
|
-
export
|
|
13
|
+
export type DependencyContainerParams = {
|
|
14
14
|
children: ReactNode;
|
|
15
15
|
root?: boolean;
|
|
16
16
|
binder?: DependencyContainerBinder;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DependencyContainer.js","sourceRoot":"","sources":["../../src/DependencyContainer.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DependencyContainer.js","sourceRoot":"","sources":["../../src/DependencyContainer.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,iCAAsC;AACtC,+CAOe;AAEF,QAAA,0BAA0B,GAAG,IAAA,qBAAa,EACrD,SAAS,CACV,CAAC;AAkBF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,SAAgB,mBAAmB,CACjC,MAAiC;IAEjC,MAAM,EAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAC,GAAG,MAAM,CAAC;IACxC,MAAM,eAAe,GAAG,IAAA,kBAAU,EAAC,kCAA0B,CAAC,CAAC;IAE/D,MAAM,SAAS,GAAG,IAAA,eAAO,EAAC,GAAG,EAAE;QAC7B,MAAM,SAAS,GAAG,IAAA,uBAAe,EAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC;QACtE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAG,SAAS,CAAC,CAAC;QAEpB,OAAO,SAAS,CAAC;IACnB,CAAC,EAAE,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,CAAC,CAAC,CAAC;IAEpC,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,OAAO,GAAG,EAAE,CAAC,SAAS,CAAC,SAAS,EAAE,CAAC;IACrC,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;IAEhB,OAAO,CACL,8BAAC,kCAA0B,CAAC,QAAQ,IAAC,KAAK,EAAE,SAAS,IAClD,QAAQ,CAC2B,CACvC,CAAC;AACJ,CAAC;AAtBD,kDAsBC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,yBAAyB,CAAC,MAGzC;IACC,MAAM,EAAC,QAAQ,EAAE,SAAS,EAAC,GAAG,MAAM,CAAC;IAErC,OAAO,CACL,8BAAC,kCAA0B,CAAC,QAAQ,IAAC,KAAK,EAAE,SAAS,IAClD,QAAQ,CAC2B,CACvC,CAAC;AACJ,CAAC;AAXD,8DAWC"}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DependencyModule.js","sourceRoot":"","sources":["../../src/DependencyModule.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DependencyModule.js","sourceRoot":"","sources":["../../src/DependencyModule.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AACA,iCAAiC;AACjC,+CAAkE;AAClE,+DAG+B;AAE/B;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,SAAgB,gBAAgB,CAAC,MAIhC;IACC,MAAM,EAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAC,GAAG,MAAM,CAAC;IAEzC,MAAM,MAAM,GAA8B,IAAA,mBAAW,EACnD,CAAC,SAAS,EAAE,EAAE,CAAC,IAAA,kBAAU,EAAC,SAAS,EAAE,MAAM,EAAE,EAAC,KAAK,EAAC,CAAC,EACrD,CAAC,MAAM,EAAE,KAAK,CAAC,CAChB,CAAC;IAEF,OAAO,8BAAC,yCAAmB,IAAC,MAAM,EAAE,MAAM,IAAG,QAAQ,CAAuB,CAAC;AAC/E,CAAC;AAbD,4CAaC"}
|
|
@@ -4,13 +4,13 @@ export declare const DependencyContainerContext: React.Context<Container | undef
|
|
|
4
4
|
/**
|
|
5
5
|
* A callback for binding dependencies to a container
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
7
|
+
export type DependencyContainerBinder = (container: Container) => unknown;
|
|
8
8
|
/**
|
|
9
9
|
* Specifies an existed container or options for a new container:
|
|
10
10
|
* @property binder - A callback which setup bindings to the container.
|
|
11
11
|
* @property root - If `true` then a new container does not depend on any parent containers
|
|
12
12
|
*/
|
|
13
|
-
export
|
|
13
|
+
export type DependencyContainerParams = {
|
|
14
14
|
children: ReactNode;
|
|
15
15
|
root?: boolean;
|
|
16
16
|
binder?: DependencyContainerBinder;
|
package/dist/umd/index.d.ts
CHANGED
|
@@ -4,13 +4,13 @@ import { ReactNode, ReactElement } from 'react';
|
|
|
4
4
|
/**
|
|
5
5
|
* A callback for binding dependencies to a container
|
|
6
6
|
*/
|
|
7
|
-
|
|
7
|
+
type DependencyContainerBinder = (container: Container) => unknown;
|
|
8
8
|
/**
|
|
9
9
|
* Specifies an existed container or options for a new container:
|
|
10
10
|
* @property binder - A callback which setup bindings to the container.
|
|
11
11
|
* @property root - If `true` then a new container does not depend on any parent containers
|
|
12
12
|
*/
|
|
13
|
-
|
|
13
|
+
type DependencyContainerParams = {
|
|
14
14
|
children: ReactNode;
|
|
15
15
|
root?: boolean;
|
|
16
16
|
binder?: DependencyContainerBinder;
|
package/dist/umd/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("ditox"),require("react")):"function"==typeof define&&define.amd?define(["exports","ditox","react"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).DitoxReact={},e.Ditox,e.React)}(this,(function(e,n,t){"use strict";
|
|
1
|
+
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("ditox"),require("react")):"function"==typeof define&&define.amd?define(["exports","ditox","react"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).DitoxReact={},e.Ditox,e.React)}(this,(function(e,n,t){"use strict";var r=t.createContext(void 0);function o(e){var o=e.children,i=e.root,u=e.binder,c=t.useContext(r),d=t.useMemo((function(){var e=n.createContainer(i?void 0:c);return null==u||u(e),e}),[u,c,i]);return t.useEffect((function(){return function(){return d.removeAll()}}),[d]),t.createElement(r.Provider,{value:d},o)}function i(e){var n=t.useContext(r);if(!n&&"strict"===e)throw new Error("Container is not provided by DependencyContainer component");return n}e.DependencyContainer=o,e.DependencyModule=function(e){var r=e.children,i=e.module,u=e.scope,c=t.useCallback((function(e){return n.bindModule(e,i,{scope:u})}),[i,u]);return t.createElement(o,{binder:c},r)},e.useDependency=function(e){var n=i("strict");return t.useMemo((function(){return n.resolve(e)}),[n,e])},e.useDependencyContainer=i,e.useOptionalDependency=function(e){var n=i();return t.useMemo((function(){return null==n?void 0:n.get(e)}),[n,e])}}));
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/umd/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/docs/README.md
CHANGED
|
@@ -4,7 +4,7 @@ ditox-react
|
|
|
4
4
|
|
|
5
5
|
## Table of contents
|
|
6
6
|
|
|
7
|
-
### Type
|
|
7
|
+
### Type Aliases
|
|
8
8
|
|
|
9
9
|
- [DependencyContainerBinder](README.md#dependencycontainerbinder)
|
|
10
10
|
- [DependencyContainerParams](README.md#dependencycontainerparams)
|
|
@@ -44,11 +44,19 @@ Returns a dependency by token, or fails with an error. Functions
|
|
|
44
44
|
|
|
45
45
|
- [useDependency](README.md#usedependency)
|
|
46
46
|
|
|
47
|
-
###
|
|
47
|
+
### Hook
|
|
48
|
+
|
|
49
|
+
Returns a dependency container, or `undefined` in case the container is not provided. Functions
|
|
48
50
|
|
|
49
51
|
- [useDependencyContainer](README.md#usedependencycontainer)
|
|
50
52
|
|
|
51
|
-
|
|
53
|
+
### Hook
|
|
54
|
+
|
|
55
|
+
Returns a dependency container. Throws an error in case the container is not provided. Functions
|
|
56
|
+
|
|
57
|
+
- [useDependencyContainer](README.md#usedependencycontainer)
|
|
58
|
+
|
|
59
|
+
## Type Aliases
|
|
52
60
|
|
|
53
61
|
### DependencyContainerBinder
|
|
54
62
|
|
|
@@ -62,8 +70,8 @@ A callback for binding dependencies to a container
|
|
|
62
70
|
|
|
63
71
|
##### Parameters
|
|
64
72
|
|
|
65
|
-
| Name
|
|
66
|
-
|
|
|
73
|
+
| Name | Type |
|
|
74
|
+
| :---------- | :---------- |
|
|
67
75
|
| `container` | `Container` |
|
|
68
76
|
|
|
69
77
|
##### Returns
|
|
@@ -72,9 +80,9 @@ A callback for binding dependencies to a container
|
|
|
72
80
|
|
|
73
81
|
#### Defined in
|
|
74
82
|
|
|
75
|
-
[DependencyContainer.tsx:19](https://github.com/mnasyrov/ditox/blob/
|
|
83
|
+
[DependencyContainer.tsx:19](https://github.com/mnasyrov/ditox/blob/37f658c/packages/ditox-react/src/DependencyContainer.tsx#L19)
|
|
76
84
|
|
|
77
|
-
|
|
85
|
+
---
|
|
78
86
|
|
|
79
87
|
### DependencyContainerParams
|
|
80
88
|
|
|
@@ -82,21 +90,25 @@ ___
|
|
|
82
90
|
|
|
83
91
|
Specifies an existed container or options for a new container:
|
|
84
92
|
|
|
85
|
-
**`
|
|
93
|
+
**`Property`**
|
|
94
|
+
|
|
95
|
+
A callback which setup bindings to the container.
|
|
96
|
+
|
|
97
|
+
**`Property`**
|
|
86
98
|
|
|
87
|
-
|
|
99
|
+
If `true` then a new container does not depend on any parent containers
|
|
88
100
|
|
|
89
101
|
#### Type declaration
|
|
90
102
|
|
|
91
|
-
| Name
|
|
92
|
-
|
|
|
93
|
-
| `binder?`
|
|
94
|
-
| `children` | `ReactNode`
|
|
95
|
-
| `root?`
|
|
103
|
+
| Name | Type |
|
|
104
|
+
| :--------- | :----------------------------------------------------------------- |
|
|
105
|
+
| `binder?` | [`DependencyContainerBinder`](README.md#dependencycontainerbinder) |
|
|
106
|
+
| `children` | `ReactNode` |
|
|
107
|
+
| `root?` | `boolean` |
|
|
96
108
|
|
|
97
109
|
#### Defined in
|
|
98
110
|
|
|
99
|
-
[DependencyContainer.tsx:26](https://github.com/mnasyrov/ditox/blob/
|
|
111
|
+
[DependencyContainer.tsx:26](https://github.com/mnasyrov/ditox/blob/37f658c/packages/ditox-react/src/DependencyContainer.tsx#L26)
|
|
100
112
|
|
|
101
113
|
## Component
|
|
102
114
|
|
|
@@ -108,7 +120,7 @@ If a parent container is exist, it is connected to the current one by default. F
|
|
|
108
120
|
|
|
109
121
|
▸ **DependencyModule**(`params`): `ReactElement`
|
|
110
122
|
|
|
111
|
-
**`
|
|
123
|
+
**`Example`**
|
|
112
124
|
|
|
113
125
|
```tsx
|
|
114
126
|
const LOGGER_MODULE: ModuleDeclaration<LoggerModule> = {
|
|
@@ -124,12 +136,12 @@ function App() {
|
|
|
124
136
|
|
|
125
137
|
#### Parameters
|
|
126
138
|
|
|
127
|
-
| Name
|
|
128
|
-
|
|
|
129
|
-
| `params`
|
|
130
|
-
| `params.children` | `ReactNode`
|
|
131
|
-
| `params.module`
|
|
132
|
-
| `params.scope?`
|
|
139
|
+
| Name | Type | Description |
|
|
140
|
+
| :---------------- | :-------------------------------------------------------------- | :------------------------------------------------------------- |
|
|
141
|
+
| `params` | `Object` | - |
|
|
142
|
+
| `params.children` | `ReactNode` | - |
|
|
143
|
+
| `params.module` | `ModuleDeclaration`<`Module`<`Record`<`string`, `unknown`\>\>\> | Module declaration for binding |
|
|
144
|
+
| `params.scope?` | `"scoped"` \| `"singleton"` | Optional scope for binding: `singleton` (default) or `scoped`. |
|
|
133
145
|
|
|
134
146
|
#### Returns
|
|
135
147
|
|
|
@@ -137,9 +149,9 @@ function App() {
|
|
|
137
149
|
|
|
138
150
|
#### Defined in
|
|
139
151
|
|
|
140
|
-
[DependencyModule.tsx:33](https://github.com/mnasyrov/ditox/blob/
|
|
152
|
+
[DependencyModule.tsx:33](https://github.com/mnasyrov/ditox/blob/37f658c/packages/ditox-react/src/DependencyModule.tsx#L33)
|
|
141
153
|
|
|
142
|
-
|
|
154
|
+
---
|
|
143
155
|
|
|
144
156
|
## Component
|
|
145
157
|
|
|
@@ -158,7 +170,7 @@ and the container will not depend on any parent container. Functions
|
|
|
158
170
|
|
|
159
171
|
▸ **DependencyContainer**(`params`): `ReactElement`
|
|
160
172
|
|
|
161
|
-
**`
|
|
173
|
+
**`Example`**
|
|
162
174
|
|
|
163
175
|
```tsx
|
|
164
176
|
const TOKEN = token();
|
|
@@ -178,8 +190,8 @@ function App() {
|
|
|
178
190
|
|
|
179
191
|
#### Parameters
|
|
180
192
|
|
|
181
|
-
| Name
|
|
182
|
-
|
|
|
193
|
+
| Name | Type |
|
|
194
|
+
| :------- | :----------------------------------------------------------------- |
|
|
183
195
|
| `params` | [`DependencyContainerParams`](README.md#dependencycontainerparams) |
|
|
184
196
|
|
|
185
197
|
#### Returns
|
|
@@ -188,9 +200,9 @@ function App() {
|
|
|
188
200
|
|
|
189
201
|
#### Defined in
|
|
190
202
|
|
|
191
|
-
[DependencyContainer.tsx:68](https://github.com/mnasyrov/ditox/blob/
|
|
203
|
+
[DependencyContainer.tsx:68](https://github.com/mnasyrov/ditox/blob/37f658c/packages/ditox-react/src/DependencyContainer.tsx#L68)
|
|
192
204
|
|
|
193
|
-
|
|
205
|
+
---
|
|
194
206
|
|
|
195
207
|
## Hook
|
|
196
208
|
|
|
@@ -203,13 +215,13 @@ Returns a dependency by token, or `undefined` in case the dependency i
|
|
|
203
215
|
#### Type parameters
|
|
204
216
|
|
|
205
217
|
| Name |
|
|
206
|
-
|
|
|
207
|
-
| `T`
|
|
218
|
+
| :--- |
|
|
219
|
+
| `T` |
|
|
208
220
|
|
|
209
221
|
#### Parameters
|
|
210
222
|
|
|
211
|
-
| Name
|
|
212
|
-
| :------ |
|
|
223
|
+
| Name | Type |
|
|
224
|
+
| :------ | :------------ |
|
|
213
225
|
| `token` | `Token`<`T`\> |
|
|
214
226
|
|
|
215
227
|
#### Returns
|
|
@@ -218,9 +230,9 @@ Returns a dependency by token, or `undefined` in case the dependency i
|
|
|
218
230
|
|
|
219
231
|
#### Defined in
|
|
220
232
|
|
|
221
|
-
[hooks.ts:52](https://github.com/mnasyrov/ditox/blob/
|
|
233
|
+
[hooks.ts:52](https://github.com/mnasyrov/ditox/blob/37f658c/packages/ditox-react/src/hooks.ts#L52)
|
|
222
234
|
|
|
223
|
-
|
|
235
|
+
---
|
|
224
236
|
|
|
225
237
|
## Hook
|
|
226
238
|
|
|
@@ -233,13 +245,13 @@ Returns a dependency by token, or fails with an error. Functions
|
|
|
233
245
|
#### Type parameters
|
|
234
246
|
|
|
235
247
|
| Name |
|
|
236
|
-
|
|
|
237
|
-
| `T`
|
|
248
|
+
| :--- |
|
|
249
|
+
| `T` |
|
|
238
250
|
|
|
239
251
|
#### Parameters
|
|
240
252
|
|
|
241
|
-
| Name
|
|
242
|
-
| :------ |
|
|
253
|
+
| Name | Type |
|
|
254
|
+
| :------ | :------------ |
|
|
243
255
|
| `token` | `Token`<`T`\> |
|
|
244
256
|
|
|
245
257
|
#### Returns
|
|
@@ -248,25 +260,23 @@ Returns a dependency by token, or fails with an error. Functions
|
|
|
248
260
|
|
|
249
261
|
#### Defined in
|
|
250
262
|
|
|
251
|
-
[hooks.ts:41](https://github.com/mnasyrov/ditox/blob/
|
|
263
|
+
[hooks.ts:41](https://github.com/mnasyrov/ditox/blob/37f658c/packages/ditox-react/src/hooks.ts#L41)
|
|
252
264
|
|
|
253
|
-
|
|
265
|
+
---
|
|
266
|
+
|
|
267
|
+
## Hook
|
|
254
268
|
|
|
255
|
-
|
|
269
|
+
Returns a dependency container, or `undefined` in case the container is not provided. Functions
|
|
256
270
|
|
|
257
271
|
### useDependencyContainer
|
|
258
272
|
|
|
259
273
|
▸ **useDependencyContainer**(`mode`): `Container`
|
|
260
274
|
|
|
261
|
-
**`category`** Hook
|
|
262
|
-
|
|
263
|
-
Returns a dependency container. Throws an error in case the container is not provided.
|
|
264
|
-
|
|
265
275
|
#### Parameters
|
|
266
276
|
|
|
267
|
-
| Name
|
|
268
|
-
|
|
|
269
|
-
| `mode` |
|
|
277
|
+
| Name | Type |
|
|
278
|
+
| :----- | :--------- |
|
|
279
|
+
| `mode` | `"strict"` |
|
|
270
280
|
|
|
271
281
|
#### Returns
|
|
272
282
|
|
|
@@ -274,19 +284,55 @@ Returns a dependency container. Throws an error in case the container is not pro
|
|
|
274
284
|
|
|
275
285
|
#### Defined in
|
|
276
286
|
|
|
277
|
-
[hooks.ts:10](https://github.com/mnasyrov/ditox/blob/
|
|
287
|
+
[hooks.ts:10](https://github.com/mnasyrov/ditox/blob/37f658c/packages/ditox-react/src/hooks.ts#L10)
|
|
278
288
|
|
|
279
289
|
▸ **useDependencyContainer**(`mode?`): `Container` \| `undefined`
|
|
280
290
|
|
|
281
|
-
|
|
291
|
+
#### Parameters
|
|
292
|
+
|
|
293
|
+
| Name | Type |
|
|
294
|
+
| :------ | :----------- |
|
|
295
|
+
| `mode?` | `"optional"` |
|
|
296
|
+
|
|
297
|
+
#### Returns
|
|
298
|
+
|
|
299
|
+
`Container` \| `undefined`
|
|
300
|
+
|
|
301
|
+
#### Defined in
|
|
282
302
|
|
|
283
|
-
|
|
303
|
+
[hooks.ts:16](https://github.com/mnasyrov/ditox/blob/37f658c/packages/ditox-react/src/hooks.ts#L16)
|
|
304
|
+
|
|
305
|
+
---
|
|
306
|
+
|
|
307
|
+
## Hook
|
|
308
|
+
|
|
309
|
+
Returns a dependency container. Throws an error in case the container is not provided. Functions
|
|
310
|
+
|
|
311
|
+
### useDependencyContainer
|
|
312
|
+
|
|
313
|
+
▸ **useDependencyContainer**(`mode`): `Container`
|
|
314
|
+
|
|
315
|
+
#### Parameters
|
|
316
|
+
|
|
317
|
+
| Name | Type |
|
|
318
|
+
| :----- | :--------- |
|
|
319
|
+
| `mode` | `"strict"` |
|
|
320
|
+
|
|
321
|
+
#### Returns
|
|
322
|
+
|
|
323
|
+
`Container`
|
|
324
|
+
|
|
325
|
+
#### Defined in
|
|
326
|
+
|
|
327
|
+
[hooks.ts:10](https://github.com/mnasyrov/ditox/blob/37f658c/packages/ditox-react/src/hooks.ts#L10)
|
|
328
|
+
|
|
329
|
+
▸ **useDependencyContainer**(`mode?`): `Container` \| `undefined`
|
|
284
330
|
|
|
285
331
|
#### Parameters
|
|
286
332
|
|
|
287
|
-
| Name
|
|
288
|
-
| :------ |
|
|
289
|
-
| `mode?` |
|
|
333
|
+
| Name | Type |
|
|
334
|
+
| :------ | :----------- |
|
|
335
|
+
| `mode?` | `"optional"` |
|
|
290
336
|
|
|
291
337
|
#### Returns
|
|
292
338
|
|
|
@@ -294,4 +340,4 @@ Returns a dependency container, or `undefined` in case the container is not prov
|
|
|
294
340
|
|
|
295
341
|
#### Defined in
|
|
296
342
|
|
|
297
|
-
[hooks.ts:16](https://github.com/mnasyrov/ditox/blob/
|
|
343
|
+
[hooks.ts:16](https://github.com/mnasyrov/ditox/blob/37f658c/packages/ditox-react/src/hooks.ts#L16)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ditox-react",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "Ditox.js tooling for React.js",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -51,18 +51,17 @@
|
|
|
51
51
|
"build:rollup": "rollup -c"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"ditox": "2.
|
|
54
|
+
"ditox": "2.3.0"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
|
-
"react": "^16.8.0 || ^17.0.0"
|
|
57
|
+
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
|
-
"@testing-library/react": "
|
|
61
|
-
"@
|
|
62
|
-
"
|
|
63
|
-
"react": "
|
|
64
|
-
"react-
|
|
65
|
-
"react-test-renderer": "17.0.2"
|
|
60
|
+
"@testing-library/react": "13.4.0",
|
|
61
|
+
"@types/react": "18.0.26",
|
|
62
|
+
"react": "18.2.0",
|
|
63
|
+
"react-dom": "18.2.0",
|
|
64
|
+
"react-test-renderer": "18.2.0"
|
|
66
65
|
},
|
|
67
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "3d34ea7a89e0bb599fa2d9dbfa67e75ec68bfba2"
|
|
68
67
|
}
|
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
* @jest-environment jsdom
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {render} from '@testing-library/react';
|
|
6
|
-
import {renderHook} from '@testing-library/react-hooks';
|
|
5
|
+
import {render, renderHook} from '@testing-library/react';
|
|
7
6
|
import {Container, createContainer, Token, token} from 'ditox';
|
|
8
7
|
import React, {useEffect} from 'react';
|
|
9
8
|
import {
|
package/src/hooks.test.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {renderHook} from '@testing-library/react
|
|
1
|
+
import {renderHook} from '@testing-library/react';
|
|
2
2
|
import {createContainer, token} from 'ditox';
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import {CustomDependencyContainer} from './DependencyContainer';
|
|
@@ -8,6 +8,10 @@ import {
|
|
|
8
8
|
useOptionalDependency,
|
|
9
9
|
} from './hooks';
|
|
10
10
|
|
|
11
|
+
beforeAll(() => {
|
|
12
|
+
jest.spyOn(console, 'error').mockImplementation();
|
|
13
|
+
});
|
|
14
|
+
|
|
11
15
|
describe('useDependencyContainer()', () => {
|
|
12
16
|
it('should return a provided container in "strict" mode', () => {
|
|
13
17
|
const container = createContainer();
|
|
@@ -24,11 +28,7 @@ describe('useDependencyContainer()', () => {
|
|
|
24
28
|
});
|
|
25
29
|
|
|
26
30
|
it('should throw an error in "strict" mode in case a container is not provided', () => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
expect(() => {
|
|
30
|
-
throw result.error;
|
|
31
|
-
}).toThrowError(
|
|
31
|
+
expect(() => renderHook(() => useDependencyContainer('strict'))).toThrow(
|
|
32
32
|
'Container is not provided by DependencyContainer component',
|
|
33
33
|
);
|
|
34
34
|
});
|
|
@@ -73,11 +73,7 @@ describe('useDependency()', () => {
|
|
|
73
73
|
it('should throw an error in case a container is not provided', () => {
|
|
74
74
|
const TOKEN = token('token');
|
|
75
75
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
expect(() => {
|
|
79
|
-
throw result.error;
|
|
80
|
-
}).toThrowError(
|
|
76
|
+
expect(() => renderHook(() => useDependency(TOKEN))).toThrowError(
|
|
81
77
|
'Container is not provided by DependencyContainer component',
|
|
82
78
|
);
|
|
83
79
|
});
|
|
@@ -86,16 +82,14 @@ describe('useDependency()', () => {
|
|
|
86
82
|
const TOKEN = token('token');
|
|
87
83
|
const container = createContainer();
|
|
88
84
|
|
|
89
|
-
const {result} = renderHook(() => useDependency(TOKEN), {
|
|
90
|
-
wrapper: ({children}) => (
|
|
91
|
-
<CustomDependencyContainer container={container}>
|
|
92
|
-
{children}
|
|
93
|
-
</CustomDependencyContainer>
|
|
94
|
-
),
|
|
95
|
-
});
|
|
96
|
-
|
|
97
85
|
expect(() => {
|
|
98
|
-
|
|
86
|
+
renderHook(() => useDependency(TOKEN), {
|
|
87
|
+
wrapper: ({children}) => (
|
|
88
|
+
<CustomDependencyContainer container={container}>
|
|
89
|
+
{children}
|
|
90
|
+
</CustomDependencyContainer>
|
|
91
|
+
),
|
|
92
|
+
});
|
|
99
93
|
}).toThrowError('Token "token" is not provided');
|
|
100
94
|
});
|
|
101
95
|
});
|