ditox-react 2.1.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,13 +4,13 @@ import { ReactNode, ReactElement } from 'react';
4
4
  /**
5
5
  * A callback for binding dependencies to a container
6
6
  */
7
- declare type DependencyContainerBinder = (container: Container) => unknown;
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
- declare type DependencyContainerParams = {
13
+ type DependencyContainerParams = {
14
14
  children: ReactNode;
15
15
  root?: boolean;
16
16
  binder?: DependencyContainerBinder;
@@ -1 +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","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"}
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 declare type DependencyContainerBinder = (container: Container) => unknown;
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 declare type DependencyContainerParams = {
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.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
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":";;;;;;;;;;;;;;;;;;;;;;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
+ {"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.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
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":";;;;;;;;;;;;;;;;;;;;;;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"}
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 declare type DependencyContainerBinder = (container: Container) => unknown;
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 declare type DependencyContainerParams = {
13
+ export type DependencyContainerParams = {
14
14
  children: ReactNode;
15
15
  root?: boolean;
16
16
  binder?: DependencyContainerBinder;
@@ -4,13 +4,13 @@ import { ReactNode, ReactElement } from 'react';
4
4
  /**
5
5
  * A callback for binding dependencies to a container
6
6
  */
7
- declare type DependencyContainerBinder = (container: Container) => unknown;
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
- declare type DependencyContainerParams = {
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";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})}));
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
@@ -1 +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"}
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 aliases
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
- ### Other Functions
47
+ ### Hook
48
+
49
+ Returns a dependency container, or &#x60;undefined&#x60; in case the container is not provided. Functions
48
50
 
49
51
  - [useDependencyContainer](README.md#usedependencycontainer)
50
52
 
51
- ## Type aliases
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 | Type |
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/aea7a8f/packages/ditox-react/src/DependencyContainer.tsx#L19)
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
- **`property`** binder - A callback which setup bindings to the container.
93
+ **`Property`**
94
+
95
+ A callback which setup bindings to the container.
96
+
97
+ **`Property`**
86
98
 
87
- **`property`** root - If `true` then a new container does not depend on any parent containers
99
+ If `true` then a new container does not depend on any parent containers
88
100
 
89
101
  #### Type declaration
90
102
 
91
- | Name | Type |
92
- | :------ | :------ |
93
- | `binder?` | [`DependencyContainerBinder`](README.md#dependencycontainerbinder) |
94
- | `children` | `ReactNode` |
95
- | `root?` | `boolean` |
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/aea7a8f/packages/ditox-react/src/DependencyContainer.tsx#L26)
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
- **`example`**
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 | Type | Description |
128
- | :------ | :------ | :------ |
129
- | `params` | `Object` | - |
130
- | `params.children` | `ReactNode` | - |
131
- | `params.module` | `ModuleDeclaration`<`Module`<`Record`<`string`, `unknown`\>\>\> | Module declaration for binding |
132
- | `params.scope?` | ``"scoped"`` \| ``"singleton"`` | Optional scope for binding: `singleton` (default) or `scoped`. |
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/aea7a8f/packages/ditox-react/src/DependencyModule.tsx#L33)
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
- **`example`**
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 | Type |
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/aea7a8f/packages/ditox-react/src/DependencyContainer.tsx#L68)
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 &#x60;undefined&#x60; 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 | Type |
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 &#x60;undefined&#x60; in case the dependency i
218
230
 
219
231
  #### Defined in
220
232
 
221
- [hooks.ts:52](https://github.com/mnasyrov/ditox/blob/aea7a8f/packages/ditox-react/src/hooks.ts#L52)
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 | Type |
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/aea7a8f/packages/ditox-react/src/hooks.ts#L41)
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
- ## Other Functions
269
+ Returns a dependency container, or &#x60;undefined&#x60; 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 | Type |
268
- | :------ | :------ |
269
- | `mode` | ``"strict"`` |
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/aea7a8f/packages/ditox-react/src/hooks.ts#L10)
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
- **`category`** Hook
291
+ #### Parameters
292
+
293
+ | Name | Type |
294
+ | :------ | :----------- |
295
+ | `mode?` | `"optional"` |
296
+
297
+ #### Returns
298
+
299
+ `Container` \| `undefined`
300
+
301
+ #### Defined in
282
302
 
283
- Returns a dependency container, or `undefined` in case the container is not provided.
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 | Type |
288
- | :------ | :------ |
289
- | `mode?` | ``"optional"`` |
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/aea7a8f/packages/ditox-react/src/hooks.ts#L16)
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.1.0",
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.1.0"
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": "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"
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": "8e8e4d79b6aaf3fa8662e51ecce0511f53e10ea8"
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 {
@@ -1,4 +1,4 @@
1
- import {renderHook} from '@testing-library/react-hooks';
1
+ import {renderHook} from '@testing-library/react';
2
2
  import {
3
3
  bindModule,
4
4
  createContainer,
@@ -1,4 +1,4 @@
1
- import {renderHook} from '@testing-library/react-hooks';
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
- const {result} = renderHook(() => useDependencyContainer('strict'));
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
- const {result} = renderHook(() => useDependency(TOKEN));
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
- throw result.error;
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
  });