ditox-react 1.4.1 → 2.2.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/{index.browser.js → browser/index.js} +1 -1
- package/dist/browser/index.js.map +1 -0
- package/dist/cjs/DependencyContainer.d.ts +78 -0
- package/dist/cjs/DependencyContainer.js +101 -0
- package/dist/cjs/DependencyContainer.js.map +1 -0
- package/{src/DependencyModule.js.flow → dist/cjs/DependencyModule.d.ts} +7 -11
- package/dist/cjs/DependencyModule.js +56 -0
- package/dist/cjs/DependencyModule.js.map +1 -0
- package/dist/cjs/hooks.d.ts +25 -0
- package/dist/cjs/hooks.js +39 -0
- package/dist/cjs/hooks.js.map +1 -0
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/esm/DependencyContainer.d.ts +78 -0
- package/dist/esm/DependencyContainer.js +77 -0
- package/dist/esm/DependencyContainer.js.map +1 -0
- package/dist/esm/DependencyModule.d.ts +31 -0
- package/dist/esm/DependencyModule.js +33 -0
- package/dist/esm/DependencyModule.js.map +1 -0
- package/dist/esm/hooks.d.ts +25 -0
- package/dist/esm/hooks.js +33 -0
- package/dist/esm/hooks.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -0
- package/{lib → dist/umd}/index.d.ts +0 -0
- package/dist/{index.umd.js → umd/index.js} +1 -1
- package/dist/umd/index.js.map +1 -0
- package/docs/.nojekyll +1 -0
- package/docs/README.md +23 -65
- package/package.json +21 -22
- package/CHANGELOG.md +0 -125
- package/dist/index.browser.js.flow +0 -4
- package/dist/index.browser.js.map +0 -1
- package/dist/index.js +0 -129
- package/dist/index.js.flow +0 -4
- package/dist/index.js.map +0 -1
- package/dist/index.module.d.ts +0 -111
- package/dist/index.module.js +0 -117
- package/dist/index.module.js.flow +0 -4
- package/dist/index.module.js.map +0 -1
- package/dist/index.umd.d.ts +0 -111
- package/dist/index.umd.js.flow +0 -4
- package/dist/index.umd.js.map +0 -1
- package/lib/index.js +0 -117
- package/lib/index.js.flow +0 -4
- package/lib/index.js.map +0 -1
- package/src/DependencyContainer.js.flow +0 -18
- package/src/hooks.js.flow +0 -12
- package/src/index.js.flow +0 -5
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useContext, useMemo } from 'react';
|
|
2
|
+
import { DependencyContainerContext } from './DependencyContainer';
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export function useDependencyContainer(mode) {
|
|
7
|
+
const container = useContext(DependencyContainerContext);
|
|
8
|
+
if (!container && mode === 'strict') {
|
|
9
|
+
throw new Error('Container is not provided by DependencyContainer component');
|
|
10
|
+
}
|
|
11
|
+
return container;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* @category Hook
|
|
15
|
+
*
|
|
16
|
+
* Returns a dependency by token, or fails with an error.
|
|
17
|
+
*/
|
|
18
|
+
export function useDependency(token) {
|
|
19
|
+
const container = useDependencyContainer('strict');
|
|
20
|
+
const value = useMemo(() => container.resolve(token), [container, token]);
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* @category Hook
|
|
25
|
+
*
|
|
26
|
+
* Returns a dependency by token, or `undefined` in case the dependency is not provided.
|
|
27
|
+
*/
|
|
28
|
+
export function useOptionalDependency(token) {
|
|
29
|
+
const container = useDependencyContainer();
|
|
30
|
+
const value = useMemo(() => container === null || container === void 0 ? void 0 : container.get(token), [container, token]);
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../src/hooks.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,UAAU,EAAE,OAAO,EAAC,MAAM,OAAO,CAAC;AAC1C,OAAO,EAAC,0BAA0B,EAAC,MAAM,uBAAuB,CAAC;AAgBjE;;GAEG;AACH,MAAM,UAAU,sBAAsB,CACpC,IAA4B;IAE5B,MAAM,SAAS,GAAG,UAAU,CAAC,0BAA0B,CAAC,CAAC;IAEzD,IAAI,CAAC,SAAS,IAAI,IAAI,KAAK,QAAQ,EAAE;QACnC,MAAM,IAAI,KAAK,CACb,4DAA4D,CAC7D,CAAC;KACH;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAI,KAAe;IAC9C,MAAM,SAAS,GAAG,sBAAsB,CAAC,QAAQ,CAAC,CAAC;IACnD,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC;IAC1E,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAI,KAAe;IACtD,MAAM,SAAS,GAAG,sBAAsB,EAAE,CAAC;IAC3C,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC;IACvE,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type { DependencyContainerBinder, DependencyContainerParams, } from './DependencyContainer';
|
|
2
|
+
export { DependencyContainer } from './DependencyContainer';
|
|
3
|
+
export { useDependencyContainer, useDependency, useOptionalDependency, } from './hooks';
|
|
4
|
+
export { DependencyModule } from './DependencyModule';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,mBAAmB,EAAC,MAAM,uBAAuB,CAAC;AAE1D,OAAO,EACL,sBAAsB,EACtB,aAAa,EACb,qBAAqB,GACtB,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAC"}
|
|
File without changes
|
|
@@ -1,2 +1,2 @@
|
|
|
1
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";function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=r(t),u=t.createContext(void 0);function i(e){var r=e.children,i=e.root,c=e.binder,d=t.useContext(u),f=t.useMemo((function(){var e=n.createContainer(i?void 0:d);return null==c||c(e),e}),[c,d,i]);return t.useEffect((function(){return function(){return f.removeAll()}}),[f]),o.default.createElement(u.Provider,{value:f},r)}function c(e){var n=t.useContext(u);if(!n&&"strict"===e)throw new Error("Container is not provided by DependencyContainer component");return n}e.DependencyContainer=i,e.DependencyModule=function(e){var r=e.children,u=e.module,c=e.scope,d=t.useCallback((function(e){return n.bindModule(e,u,{scope:c})}),[u,c]);return o.default.createElement(i,{binder:d},r)},e.useDependency=function(e){var n=c("strict");return t.useMemo((function(){return n.resolve(e)}),[n,e])},e.useDependencyContainer=c,e.useOptionalDependency=function(e){var n=c();return t.useMemo((function(){return null==n?void 0:n.get(e)}),[n,e])},Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
2
|
-
//# sourceMappingURL=index.
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/DependencyContainer.tsx","../../src/hooks.ts","../../src/DependencyModule.tsx"],"sourcesContent":[null,null,null],"names":["DependencyContainerContext","createContext","undefined","DependencyContainer","params","children","root","binder","parentContainer","useContext","container","useMemo","createContainer","useEffect","removeAll","React","Provider","value","useDependencyContainer","mode","Error","module","scope","useCallback","bindModule","token","resolve","get"],"mappings":"2YAWaA,EAA6BC,qBACxCC,YAuDcC,EACdC,GAEO,IAAAC,EAA0BD,WAAhBE,EAAgBF,OAAVG,EAAUH,SAC3BI,EAAkBC,aAAWT,GAE7BU,EAAYC,WAAQ,WACxB,IAAMD,EAAYE,kBAAgBN,OAAOJ,EAAYM,GAGrD,OAFAD,MAAAA,GAAAA,EAASG,GAEFA,IACN,CAACH,EAAQC,EAAiBF,IAM7B,OAJAO,aAAU,WACR,OAAO,WAAM,OAAAH,EAAUI,eACtB,CAACJ,IAGFK,wBAACf,EAA2BgB,UAASC,MAAOP,GACzCL,YCjESa,EACdC,GAEA,IAAMT,EAAYD,aAAWT,GAE7B,IAAKU,GAAsB,WAATS,EAChB,MAAM,IAAIC,MACR,8DAIJ,OAAOV,sDCAwBN,GAKxB,IAAAC,EAA2BD,WAAjBiB,EAAiBjB,SAATkB,EAASlB,QAE5BG,EAAoCgB,eACxC,SAACb,GAAc,OAAAc,aAAWd,EAAWW,EAAQ,CAACC,YAC9C,CAACD,EAAQC,IAGX,OAAOP,wBAACZ,GAAoBI,OAAQA,GAASF,6BDJdoB,GAC/B,IAAMf,EAAYQ,EAAuB,UAEzC,OADcP,WAAQ,WAAM,OAAAD,EAAUgB,QAAQD,KAAQ,CAACf,EAAWe,iEAS3BA,GACvC,IAAMf,EAAYQ,IAElB,OADcP,WAAQ,WAAM,OAAAD,MAAAA,SAAAA,EAAWiB,IAAIF,KAAQ,CAACf,EAAWe"}
|
package/docs/.nojekyll
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false.
|
package/docs/README.md
CHANGED
|
@@ -44,15 +44,7 @@ Returns a dependency by token, or fails with an error. Functions
|
|
|
44
44
|
|
|
45
45
|
- [useDependency](README.md#usedependency)
|
|
46
46
|
|
|
47
|
-
###
|
|
48
|
-
|
|
49
|
-
Returns a dependency container, or `undefined` in case the container is not provided. Functions
|
|
50
|
-
|
|
51
|
-
- [useDependencyContainer](README.md#usedependencycontainer)
|
|
52
|
-
|
|
53
|
-
### Hook
|
|
54
|
-
|
|
55
|
-
Returns a dependency container. Throws an error in case the container is not provided. Functions
|
|
47
|
+
### Other Functions
|
|
56
48
|
|
|
57
49
|
- [useDependencyContainer](README.md#usedependencycontainer)
|
|
58
50
|
|
|
@@ -80,7 +72,7 @@ A callback for binding dependencies to a container
|
|
|
80
72
|
|
|
81
73
|
#### Defined in
|
|
82
74
|
|
|
83
|
-
[DependencyContainer.tsx:19](https://github.com/mnasyrov/ditox/blob/
|
|
75
|
+
[DependencyContainer.tsx:19](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox-react/src/DependencyContainer.tsx#L19)
|
|
84
76
|
|
|
85
77
|
___
|
|
86
78
|
|
|
@@ -98,13 +90,13 @@ Specifies an existed container or options for a new container:
|
|
|
98
90
|
|
|
99
91
|
| Name | Type |
|
|
100
92
|
| :------ | :------ |
|
|
101
|
-
| `binder?` | [DependencyContainerBinder](README.md#dependencycontainerbinder) |
|
|
93
|
+
| `binder?` | [`DependencyContainerBinder`](README.md#dependencycontainerbinder) |
|
|
102
94
|
| `children` | `ReactNode` |
|
|
103
95
|
| `root?` | `boolean` |
|
|
104
96
|
|
|
105
97
|
#### Defined in
|
|
106
98
|
|
|
107
|
-
[DependencyContainer.tsx:26](https://github.com/mnasyrov/ditox/blob/
|
|
99
|
+
[DependencyContainer.tsx:26](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox-react/src/DependencyContainer.tsx#L26)
|
|
108
100
|
|
|
109
101
|
## Component
|
|
110
102
|
|
|
@@ -136,7 +128,7 @@ function App() {
|
|
|
136
128
|
| :------ | :------ | :------ |
|
|
137
129
|
| `params` | `Object` | - |
|
|
138
130
|
| `params.children` | `ReactNode` | - |
|
|
139
|
-
| `params.module` | `ModuleDeclaration
|
|
131
|
+
| `params.module` | `ModuleDeclaration`<`Module`<`Record`<`string`, `unknown`\>\>\> | Module declaration for binding |
|
|
140
132
|
| `params.scope?` | ``"scoped"`` \| ``"singleton"`` | Optional scope for binding: `singleton` (default) or `scoped`. |
|
|
141
133
|
|
|
142
134
|
#### Returns
|
|
@@ -145,7 +137,7 @@ function App() {
|
|
|
145
137
|
|
|
146
138
|
#### Defined in
|
|
147
139
|
|
|
148
|
-
[DependencyModule.tsx:33](https://github.com/mnasyrov/ditox/blob/
|
|
140
|
+
[DependencyModule.tsx:33](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox-react/src/DependencyModule.tsx#L33)
|
|
149
141
|
|
|
150
142
|
___
|
|
151
143
|
|
|
@@ -188,7 +180,7 @@ function App() {
|
|
|
188
180
|
|
|
189
181
|
| Name | Type |
|
|
190
182
|
| :------ | :------ |
|
|
191
|
-
| `params` | [DependencyContainerParams](README.md#dependencycontainerparams) |
|
|
183
|
+
| `params` | [`DependencyContainerParams`](README.md#dependencycontainerparams) |
|
|
192
184
|
|
|
193
185
|
#### Returns
|
|
194
186
|
|
|
@@ -196,7 +188,7 @@ function App() {
|
|
|
196
188
|
|
|
197
189
|
#### Defined in
|
|
198
190
|
|
|
199
|
-
[DependencyContainer.tsx:68](https://github.com/mnasyrov/ditox/blob/
|
|
191
|
+
[DependencyContainer.tsx:68](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox-react/src/DependencyContainer.tsx#L68)
|
|
200
192
|
|
|
201
193
|
___
|
|
202
194
|
|
|
@@ -206,7 +198,7 @@ Returns a dependency by token, or `undefined` in case the dependency i
|
|
|
206
198
|
|
|
207
199
|
### useOptionalDependency
|
|
208
200
|
|
|
209
|
-
▸ **useOptionalDependency
|
|
201
|
+
▸ **useOptionalDependency**<`T`\>(`token`): `T` \| `undefined`
|
|
210
202
|
|
|
211
203
|
#### Type parameters
|
|
212
204
|
|
|
@@ -218,7 +210,7 @@ Returns a dependency by token, or `undefined` in case the dependency i
|
|
|
218
210
|
|
|
219
211
|
| Name | Type |
|
|
220
212
|
| :------ | :------ |
|
|
221
|
-
| `token` | `Token
|
|
213
|
+
| `token` | `Token`<`T`\> |
|
|
222
214
|
|
|
223
215
|
#### Returns
|
|
224
216
|
|
|
@@ -226,7 +218,7 @@ Returns a dependency by token, or `undefined` in case the dependency i
|
|
|
226
218
|
|
|
227
219
|
#### Defined in
|
|
228
220
|
|
|
229
|
-
[hooks.ts:52](https://github.com/mnasyrov/ditox/blob/
|
|
221
|
+
[hooks.ts:52](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox-react/src/hooks.ts#L52)
|
|
230
222
|
|
|
231
223
|
___
|
|
232
224
|
|
|
@@ -236,7 +228,7 @@ Returns a dependency by token, or fails with an error. Functions
|
|
|
236
228
|
|
|
237
229
|
### useDependency
|
|
238
230
|
|
|
239
|
-
▸ **useDependency
|
|
231
|
+
▸ **useDependency**<`T`\>(`token`): `T`
|
|
240
232
|
|
|
241
233
|
#### Type parameters
|
|
242
234
|
|
|
@@ -248,7 +240,7 @@ Returns a dependency by token, or fails with an error. Functions
|
|
|
248
240
|
|
|
249
241
|
| Name | Type |
|
|
250
242
|
| :------ | :------ |
|
|
251
|
-
| `token` | `Token
|
|
243
|
+
| `token` | `Token`<`T`\> |
|
|
252
244
|
|
|
253
245
|
#### Returns
|
|
254
246
|
|
|
@@ -256,57 +248,19 @@ Returns a dependency by token, or fails with an error. Functions
|
|
|
256
248
|
|
|
257
249
|
#### Defined in
|
|
258
250
|
|
|
259
|
-
[hooks.ts:41](https://github.com/mnasyrov/ditox/blob/
|
|
251
|
+
[hooks.ts:41](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox-react/src/hooks.ts#L41)
|
|
260
252
|
|
|
261
253
|
___
|
|
262
254
|
|
|
263
|
-
##
|
|
264
|
-
|
|
265
|
-
Returns a dependency container, or `undefined` in case the container is not provided. Functions
|
|
255
|
+
## Other Functions
|
|
266
256
|
|
|
267
257
|
### useDependencyContainer
|
|
268
258
|
|
|
269
259
|
▸ **useDependencyContainer**(`mode`): `Container`
|
|
270
260
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
| Name | Type |
|
|
274
|
-
| :------ | :------ |
|
|
275
|
-
| `mode` | ``"strict"`` |
|
|
276
|
-
|
|
277
|
-
#### Returns
|
|
278
|
-
|
|
279
|
-
`Container`
|
|
280
|
-
|
|
281
|
-
#### Defined in
|
|
282
|
-
|
|
283
|
-
[hooks.ts:10](https://github.com/mnasyrov/ditox/blob/153c602/packages/ditox-react/src/hooks.ts#L10)
|
|
284
|
-
|
|
285
|
-
▸ **useDependencyContainer**(`mode?`): `Container` \| `undefined`
|
|
286
|
-
|
|
287
|
-
#### Parameters
|
|
288
|
-
|
|
289
|
-
| Name | Type |
|
|
290
|
-
| :------ | :------ |
|
|
291
|
-
| `mode?` | ``"optional"`` |
|
|
292
|
-
|
|
293
|
-
#### Returns
|
|
294
|
-
|
|
295
|
-
`Container` \| `undefined`
|
|
296
|
-
|
|
297
|
-
#### Defined in
|
|
261
|
+
**`category`** Hook
|
|
298
262
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
___
|
|
302
|
-
|
|
303
|
-
## Hook
|
|
304
|
-
|
|
305
|
-
Returns a dependency container. Throws an error in case the container is not provided. Functions
|
|
306
|
-
|
|
307
|
-
### useDependencyContainer
|
|
308
|
-
|
|
309
|
-
▸ **useDependencyContainer**(`mode`): `Container`
|
|
263
|
+
Returns a dependency container. Throws an error in case the container is not provided.
|
|
310
264
|
|
|
311
265
|
#### Parameters
|
|
312
266
|
|
|
@@ -320,10 +274,14 @@ Returns a dependency container. Throws an error in case the container is not pro
|
|
|
320
274
|
|
|
321
275
|
#### Defined in
|
|
322
276
|
|
|
323
|
-
[hooks.ts:10](https://github.com/mnasyrov/ditox/blob/
|
|
277
|
+
[hooks.ts:10](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox-react/src/hooks.ts#L10)
|
|
324
278
|
|
|
325
279
|
▸ **useDependencyContainer**(`mode?`): `Container` \| `undefined`
|
|
326
280
|
|
|
281
|
+
**`category`** Hook
|
|
282
|
+
|
|
283
|
+
Returns a dependency container, or `undefined` in case the container is not provided.
|
|
284
|
+
|
|
327
285
|
#### Parameters
|
|
328
286
|
|
|
329
287
|
| Name | Type |
|
|
@@ -336,4 +294,4 @@ Returns a dependency container. Throws an error in case the container is not pro
|
|
|
336
294
|
|
|
337
295
|
#### Defined in
|
|
338
296
|
|
|
339
|
-
[hooks.ts:16](https://github.com/mnasyrov/ditox/blob/
|
|
297
|
+
[hooks.ts:16](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox-react/src/hooks.ts#L16)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ditox-react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Ditox.js tooling for React.js",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -26,44 +26,43 @@
|
|
|
26
26
|
"engines": {
|
|
27
27
|
"node": ">=12"
|
|
28
28
|
},
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"types": "dist/index.d.ts",
|
|
29
|
+
"main": "dist/cjs/index.js",
|
|
30
|
+
"module": "dist/esm/index.js",
|
|
31
|
+
"jsnext:main": "dist/esm/index.js",
|
|
32
|
+
"unpkg": "dist/umd/index.js",
|
|
33
|
+
"umd:main": "dist/umd/index.js",
|
|
34
|
+
"browser": "dist/browser/index.js",
|
|
35
|
+
"react-native": "dist/browser/index.js",
|
|
36
|
+
"types": "dist/esm/index.d.ts",
|
|
38
37
|
"source": "src/index.ts",
|
|
39
38
|
"sideEffects": false,
|
|
40
39
|
"files": [
|
|
41
40
|
"dist",
|
|
42
41
|
"docs",
|
|
43
|
-
"lib",
|
|
44
42
|
"src",
|
|
45
43
|
"LICENSE",
|
|
46
|
-
"mod.ts",
|
|
47
44
|
"README.md"
|
|
48
45
|
],
|
|
49
46
|
"scripts": {
|
|
50
47
|
"clean": "shx rm -rf dist lib",
|
|
51
|
-
"build": "rollup
|
|
52
|
-
"
|
|
48
|
+
"build": "npm run build:cjs && npm run build:esm && npm run build:rollup",
|
|
49
|
+
"build:cjs": "tsc -p tsconfig.build.json --outDir dist/cjs --module commonjs",
|
|
50
|
+
"build:esm": "tsc -p tsconfig.build.json --outDir dist/esm --module es2015",
|
|
51
|
+
"build:rollup": "rollup -c"
|
|
53
52
|
},
|
|
54
53
|
"dependencies": {
|
|
55
|
-
"ditox": "
|
|
54
|
+
"ditox": "2.2.0"
|
|
56
55
|
},
|
|
57
56
|
"peerDependencies": {
|
|
58
57
|
"react": "^16.8.0 || ^17.0.0"
|
|
59
58
|
},
|
|
60
59
|
"devDependencies": {
|
|
61
|
-
"@testing-library/react": "
|
|
62
|
-
"@testing-library/react-hooks": "
|
|
63
|
-
"@types/react": "17.0.
|
|
64
|
-
"react": "17.0.
|
|
65
|
-
"react-dom": "17.0.
|
|
66
|
-
"react-test-renderer": "17.0.
|
|
60
|
+
"@testing-library/react": "12.1.2",
|
|
61
|
+
"@testing-library/react-hooks": "7.0.2",
|
|
62
|
+
"@types/react": "17.0.38",
|
|
63
|
+
"react": "17.0.2",
|
|
64
|
+
"react-dom": "17.0.2",
|
|
65
|
+
"react-test-renderer": "17.0.2"
|
|
67
66
|
},
|
|
68
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "f9d1e2d369a00fb12ad62cbb9aa6039104c4cbe3"
|
|
69
68
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
# Change Log
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
-
|
|
6
|
-
## [1.4.1](https://github.com/mnasyrov/ditox/compare/v1.4.0...v1.4.1) (2021-11-11)
|
|
7
|
-
|
|
8
|
-
**Note:** Version bump only for package ditox-react
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
# [1.4.0](https://github.com/mnasyrov/ditox/compare/v1.3.0...v1.4.0) (2021-10-30)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
### Features
|
|
18
|
-
|
|
19
|
-
* `ModuleDeclaration.imports` property takes module entries for binding with the module. ([6757bdc](https://github.com/mnasyrov/ditox/commit/6757bdc87a02d2336ca07661c50812a5823ca844))
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
# [1.3.0](https://github.com/mnasyrov/ditox/compare/v1.2.0...v1.3.0) (2021-08-04)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
### Features
|
|
29
|
-
|
|
30
|
-
* `declareModule()` and `declareModuleBindings()` utility functions ([990ffe7](https://github.com/mnasyrov/ditox/commit/990ffe79af37c6ee56738b6ac7e9c071818d10f7))
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
# [1.2.0](https://github.com/mnasyrov/ditox/compare/v1.1.0...v1.2.0) (2021-06-20)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
### Features
|
|
40
|
-
|
|
41
|
-
* DependencyModule component ([e5836b8](https://github.com/mnasyrov/ditox/commit/e5836b89f4506cabe0303a91501c43f732455fe1))
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
# [1.1.0](https://github.com/mnasyrov/ditox/compare/v1.0.2...v1.1.0) (2021-04-17)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
### Features
|
|
51
|
-
|
|
52
|
-
* Utilities for resolving object properties by tokens ([d4a41e8](https://github.com/mnasyrov/ditox/commit/d4a41e8d777540905a4bc15fc22bcb06a85cf90a))
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
## [1.0.2](https://github.com/mnasyrov/ditox/compare/v1.0.1...v1.0.2) (2021-03-04)
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
### Bug Fixes
|
|
62
|
-
|
|
63
|
-
* Fixed flow typings ([60bc7e7](https://github.com/mnasyrov/ditox/commit/60bc7e76c987d713edb61ee967b4dc88ad1f0f8e))
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
## [1.0.1](https://github.com/mnasyrov/ditox/compare/v1.0.0...v1.0.1) (2021-03-04)
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
### Bug Fixes
|
|
73
|
-
|
|
74
|
-
* Fixed bundled typings for Typescript ([7b1499e](https://github.com/mnasyrov/ditox/commit/7b1499e7cf1506f24f72387d83a055e6a4d3c336))
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
# [1.0.0](https://github.com/mnasyrov/ditox/compare/v0.5.4...v1.0.0) (2021-02-28)
|
|
81
|
-
|
|
82
|
-
**Note:** Version bump only for package @ditox/react
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
## [0.5.4](https://github.com/mnasyrov/ditox/compare/v0.5.3...v0.5.4) (2021-02-28)
|
|
89
|
-
|
|
90
|
-
**Note:** Version bump only for package @ditox/react
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
## [0.5.3](https://github.com/mnasyrov/ditox/compare/v0.5.2...v0.5.3) (2021-02-25)
|
|
97
|
-
|
|
98
|
-
**Note:** Version bump only for package @ditox/react
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
## [0.5.2](https://github.com/mnasyrov/ditox/compare/v0.5.1...v0.5.2) (2021-02-25)
|
|
105
|
-
|
|
106
|
-
**Note:** Version bump only for package @ditox/react
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
## [0.5.1](https://github.com/mnasyrov/ditox/compare/v0.5.0...v0.5.1) (2021-02-25)
|
|
113
|
-
|
|
114
|
-
**Note:** Version bump only for package @ditox/react
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
# [0.5.0](https://github.com/mnasyrov/ditox/compare/v0.4.1...v0.5.0) (2021-02-24)
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
### Features
|
|
124
|
-
|
|
125
|
-
* Introduced @ditox/react - tooling for React apps ([cd9c9db](https://github.com/mnasyrov/ditox/commit/cd9c9db9d65fda468f0e740c49e090757f1ac73a))
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.browser.js","sources":["../src/DependencyContainer.tsx","../src/hooks.ts","../src/DependencyModule.tsx"],"sourcesContent":[null,null,null],"names":["DependencyContainerContext","createContext","undefined","DependencyContainer","params","children","root","binder","parentContainer","useContext","container","useMemo","createContainer","useEffect","removeAll","React","Provider","value","useDependencyContainer","mode","Error","useDependency","token","resolve","useOptionalDependency","get","DependencyModule","module","scope","useCallback","bindModule"],"mappings":"8JAWO,IAAMA,EAA6BC,OACxCC,YAuDcC,EACdC,GAEO,IAAAC,EAA0BD,WAAhBE,EAAgBF,OAAVG,EAAUH,SAC3BI,EAAkBC,EAAWT,GAE7BU,EAAYC,GAAQ,WACxB,IAAMD,EAAYE,EAAgBN,OAAOJ,EAAYM,GAGrD,OAFAD,MAAAA,GAAAA,EAASG,GAEFA,IACN,CAACH,EAAQC,EAAiBF,IAM7B,OAJAO,GAAU,WACR,OAAO,WAAM,OAAAH,EAAUI,eACtB,CAACJ,IAGFK,gBAACf,EAA2BgB,UAASC,MAAOP,GACzCL,YCjESa,EACdC,GAEA,IAAMT,EAAYD,EAAWT,GAE7B,IAAKU,GAAsB,WAATS,EAChB,MAAM,IAAIC,MACR,8DAIJ,OAAOV,WAQOW,EAAiBC,GAC/B,IAAMZ,EAAYQ,EAAuB,UAEzC,OADcP,GAAQ,WAAM,OAAAD,EAAUa,QAAQD,KAAQ,CAACZ,EAAWY,aASpDE,EAAyBF,GACvC,IAAMZ,EAAYQ,IAElB,OADcP,GAAQ,WAAM,OAAAD,MAAAA,SAAAA,EAAWe,IAAIH,KAAQ,CAACZ,EAAWY,aCrBjDI,EAAiBtB,GAKxB,IAAAC,EAA2BD,WAAjBuB,EAAiBvB,SAATwB,EAASxB,QAE5BG,EAAoCsB,GACxC,SAACnB,GAAc,OAAAoB,EAAWpB,EAAWiB,EAAQ,CAACC,YAC9C,CAACD,EAAQC,IAGX,OAAOb,gBAACZ,GAAoBI,OAAQA,GAASF"}
|
package/dist/index.js
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var ditox = require('ditox');
|
|
6
|
-
var React = require('react');
|
|
7
|
-
|
|
8
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
9
|
-
|
|
10
|
-
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
11
|
-
|
|
12
|
-
const DependencyContainerContext = React.createContext(undefined);
|
|
13
|
-
/**
|
|
14
|
-
* @category Component
|
|
15
|
-
*
|
|
16
|
-
* Provides a new dependency container to React app
|
|
17
|
-
*
|
|
18
|
-
* This component creates a new container and provides it down to React children.
|
|
19
|
-
*
|
|
20
|
-
* If `binder` callback is specified, it will be called for a new container
|
|
21
|
-
* to binds it with dependencies.
|
|
22
|
-
*
|
|
23
|
-
* If a parent container is exist, it is connected to the current one by default.
|
|
24
|
-
* For making a new root container specify `root` parameter as `true`,
|
|
25
|
-
* and the container will not depend on any parent container.
|
|
26
|
-
*
|
|
27
|
-
* @param params.binder - A callback which setup bindings to the container.
|
|
28
|
-
* @param params.root - If `true` then a new container does not depend on any parent containers
|
|
29
|
-
*
|
|
30
|
-
* @example
|
|
31
|
-
*
|
|
32
|
-
* ```tsx
|
|
33
|
-
* const TOKEN = token();
|
|
34
|
-
*
|
|
35
|
-
* function appDependencyBinder(container: Container) {
|
|
36
|
-
* container.bindValue(TOKEN, 'value');
|
|
37
|
-
* }
|
|
38
|
-
*
|
|
39
|
-
* function App() {
|
|
40
|
-
* return (
|
|
41
|
-
* <DependencyContainer root binder={appDependencyBinder}>
|
|
42
|
-
* <NestedComponent />
|
|
43
|
-
* </DependencyContainer>
|
|
44
|
-
* );
|
|
45
|
-
* }
|
|
46
|
-
* ```
|
|
47
|
-
*
|
|
48
|
-
*/
|
|
49
|
-
function DependencyContainer(params) {
|
|
50
|
-
const { children, root, binder } = params;
|
|
51
|
-
const parentContainer = React.useContext(DependencyContainerContext);
|
|
52
|
-
const container = React.useMemo(() => {
|
|
53
|
-
const container = ditox.createContainer(root ? undefined : parentContainer);
|
|
54
|
-
binder === null || binder === void 0 ? void 0 : binder(container);
|
|
55
|
-
return container;
|
|
56
|
-
}, [binder, parentContainer, root]);
|
|
57
|
-
React.useEffect(() => {
|
|
58
|
-
return () => container.removeAll();
|
|
59
|
-
}, [container]);
|
|
60
|
-
return (React__default['default'].createElement(DependencyContainerContext.Provider, { value: container }, children));
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* @internal
|
|
65
|
-
*/
|
|
66
|
-
function useDependencyContainer(mode) {
|
|
67
|
-
const container = React.useContext(DependencyContainerContext);
|
|
68
|
-
if (!container && mode === 'strict') {
|
|
69
|
-
throw new Error('Container is not provided by DependencyContainer component');
|
|
70
|
-
}
|
|
71
|
-
return container;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* @category Hook
|
|
75
|
-
*
|
|
76
|
-
* Returns a dependency by token, or fails with an error.
|
|
77
|
-
*/
|
|
78
|
-
function useDependency(token) {
|
|
79
|
-
const container = useDependencyContainer('strict');
|
|
80
|
-
const value = React.useMemo(() => container.resolve(token), [container, token]);
|
|
81
|
-
return value;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* @category Hook
|
|
85
|
-
*
|
|
86
|
-
* Returns a dependency by token, or `undefined` in case the dependency is not provided.
|
|
87
|
-
*/
|
|
88
|
-
function useOptionalDependency(token) {
|
|
89
|
-
const container = useDependencyContainer();
|
|
90
|
-
const value = React.useMemo(() => container === null || container === void 0 ? void 0 : container.get(token), [container, token]);
|
|
91
|
-
return value;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* @category Component
|
|
96
|
-
*
|
|
97
|
-
* Binds the module to a new dependency container.
|
|
98
|
-
*
|
|
99
|
-
* If a parent container is exist, it is connected to the current one by default.
|
|
100
|
-
*
|
|
101
|
-
* @param params.module - Module declaration for binding
|
|
102
|
-
* @param params.scope - Optional scope for binding: `singleton` (default) or `scoped`.
|
|
103
|
-
*
|
|
104
|
-
* @example
|
|
105
|
-
*
|
|
106
|
-
* ```tsx
|
|
107
|
-
* const LOGGER_MODULE: ModuleDeclaration<LoggerModule> = {
|
|
108
|
-
*
|
|
109
|
-
* function App() {
|
|
110
|
-
* return (
|
|
111
|
-
* <DependencyModule module={LOGGER_MODULE}>
|
|
112
|
-
* <NestedComponent />
|
|
113
|
-
* </DependencyModule>
|
|
114
|
-
* );
|
|
115
|
-
* }
|
|
116
|
-
* ```
|
|
117
|
-
*/
|
|
118
|
-
function DependencyModule(params) {
|
|
119
|
-
const { children, module, scope } = params;
|
|
120
|
-
const binder = React.useCallback((container) => ditox.bindModule(container, module, { scope }), [module, scope]);
|
|
121
|
-
return React__default['default'].createElement(DependencyContainer, { binder: binder }, children);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
exports.DependencyContainer = DependencyContainer;
|
|
125
|
-
exports.DependencyModule = DependencyModule;
|
|
126
|
-
exports.useDependency = useDependency;
|
|
127
|
-
exports.useDependencyContainer = useDependencyContainer;
|
|
128
|
-
exports.useOptionalDependency = useOptionalDependency;
|
|
129
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.flow
DELETED
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/DependencyContainer.tsx","../src/hooks.ts","../src/DependencyModule.tsx"],"sourcesContent":[null,null,null],"names":["createContext","useContext","useMemo","createContainer","useEffect","React","useCallback","bindModule"],"mappings":";;;;;;;;;;;AAWO,MAAM,0BAA0B,GAAGA,mBAAa,CACrD,SAAS,CACV,CAAC;AAkBF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SAoCgB,mBAAmB,CACjC,MAAiC;IAEjC,MAAM,EAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAC,GAAG,MAAM,CAAC;IACxC,MAAM,eAAe,GAAGC,gBAAU,CAAC,0BAA0B,CAAC,CAAC;IAE/D,MAAM,SAAS,GAAGC,aAAO,CAAC;QACxB,MAAM,SAAS,GAAGC,qBAAe,CAAC,IAAI,GAAG,SAAS,GAAG,eAAe,CAAC,CAAC;QACtE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAG,SAAS,CAAC,CAAC;QAEpB,OAAO,SAAS,CAAC;KAClB,EAAE,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,CAAC,CAAC,CAAC;IAEpCC,eAAS,CAAC;QACR,OAAO,MAAM,SAAS,CAAC,SAAS,EAAE,CAAC;KACpC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;IAEhB,QACEC,wCAAC,0BAA0B,CAAC,QAAQ,IAAC,KAAK,EAAE,SAAS,IAClD,QAAQ,CAC2B,EACtC;AACJ;;ACvEA;;;SAGgB,sBAAsB,CACpC,IAA4B;IAE5B,MAAM,SAAS,GAAGJ,gBAAU,CAAC,0BAA0B,CAAC,CAAC;IAEzD,IAAI,CAAC,SAAS,IAAI,IAAI,KAAK,QAAQ,EAAE;QACnC,MAAM,IAAI,KAAK,CACb,4DAA4D,CAC7D,CAAC;KACH;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;SAKgB,aAAa,CAAI,KAAe;IAC9C,MAAM,SAAS,GAAG,sBAAsB,CAAC,QAAQ,CAAC,CAAC;IACnD,MAAM,KAAK,GAAGC,aAAO,CAAC,MAAM,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC;IAC1E,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;SAKgB,qBAAqB,CAAI,KAAe;IACtD,MAAM,SAAS,GAAG,sBAAsB,EAAE,CAAC;IAC3C,MAAM,KAAK,GAAGA,aAAO,CAAC,MAAM,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC;IACvE,OAAO,KAAK,CAAC;AACf;;AC/CA;;;;;;;;;;;;;;;;;;;;;;;;SAwBgB,gBAAgB,CAAC,MAIhC;IACC,MAAM,EAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAC,GAAG,MAAM,CAAC;IAEzC,MAAM,MAAM,GAA8BI,iBAAW,CACnD,CAAC,SAAS,KAAKC,gBAAU,CAAC,SAAS,EAAE,MAAM,EAAE,EAAC,KAAK,EAAC,CAAC,EACrD,CAAC,MAAM,EAAE,KAAK,CAAC,CAChB,CAAC;IAEF,OAAOF,wCAAC,mBAAmB,IAAC,MAAM,EAAE,MAAM,IAAG,QAAQ,CAAuB,CAAC;AAC/E;;;;;;;;"}
|