ditox-react 2.2.0 → 2.3.1
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/LICENSE +1 -1
- package/README.md +43 -55
- package/dist/browser/index.d.ts +2 -6
- package/dist/browser/index.js.map +1 -1
- package/dist/cjs/DependencyContainer.d.ts +2 -6
- package/dist/cjs/DependencyContainer.js +5 -5
- package/dist/cjs/DependencyContainer.js.map +1 -1
- package/dist/cjs/DependencyModule.d.ts +0 -2
- package/dist/cjs/DependencyModule.js +5 -3
- package/dist/cjs/DependencyModule.js.map +1 -1
- package/dist/esm/DependencyContainer.d.ts +2 -6
- package/dist/esm/DependencyContainer.js +0 -4
- package/dist/esm/DependencyContainer.js.map +1 -1
- package/dist/esm/DependencyModule.d.ts +0 -2
- package/dist/esm/DependencyModule.js +0 -2
- package/dist/esm/DependencyModule.js.map +1 -1
- package/dist/umd/index.d.ts +2 -6
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.js.map +1 -1
- package/package.json +21 -16
- package/src/DependencyContainer.test.tsx +1 -2
- package/src/DependencyContainer.tsx +0 -4
- package/src/DependencyModule.test.tsx +1 -1
- package/src/DependencyModule.tsx +0 -2
- package/src/hooks.test.tsx +14 -20
- package/docs/.nojekyll +0 -1
- package/docs/README.md +0 -297
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,81 +1,72 @@
|
|
|
1
|
-
# ditox-react
|
|
1
|
+
# ditox-react package
|
|
2
2
|
|
|
3
3
|
<img alt="lemon" src="https://raw.githubusercontent.com/mnasyrov/ditox/master/lemon.svg" width="120" />
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
**Dependency injection container for React.js**
|
|
6
6
|
|
|
7
|
-
[
|
|
8
|
-
[](https://www.npmjs.com/package/ditox)
|
|
9
|
-
[](https://www.npmjs.com/package/ditox)
|
|
10
|
-
[](https://github.com/mnasyrov/ditox/blob/master/LICENSE)
|
|
11
|
-
[](https://coveralls.io/github/mnasyrov/ditox)
|
|
7
|
+
Please see the documentation at [ditox.js.org](https://ditox.js.org)
|
|
12
8
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
- [Installation](#installation)
|
|
19
|
-
- [Usage](#usage)
|
|
20
|
-
- [Dependency modules](#dependency-modules)
|
|
21
|
-
- [API References](#api-references)
|
|
22
|
-
|
|
23
|
-
<!-- tocstop -->
|
|
24
|
-
|
|
25
|
-
## Features
|
|
26
|
-
|
|
27
|
-
- Simple and functional API
|
|
28
|
-
- Container hierarchy
|
|
29
|
-
- Scoped containers
|
|
30
|
-
- Multi-value tokens
|
|
31
|
-
- Typescript typings
|
|
32
|
-
- Supports Node.js, Deno and browsers
|
|
9
|
+
[](https://www.npmjs.com/package/ditox)
|
|
10
|
+
[](https://github.com/mnasyrov/ditox/stargazers)
|
|
11
|
+
[](https://www.npmjs.com/package/ditox)
|
|
12
|
+
[](https://github.com/mnasyrov/ditox/blob/master/LICENSE)
|
|
13
|
+
[](https://coveralls.io/github/mnasyrov/ditox)
|
|
33
14
|
|
|
34
15
|
## Installation
|
|
35
16
|
|
|
36
|
-
|
|
17
|
+
You can use the following command to install this package:
|
|
37
18
|
|
|
19
|
+
```shell
|
|
20
|
+
npm install --save ditox-react
|
|
38
21
|
```
|
|
39
|
-
npm install ditox ditox-react --save
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
Or `yarn`
|
|
43
22
|
|
|
44
|
-
|
|
45
|
-
|
|
23
|
+
The packages can be used as [UMD](https://github.com/umdjs/umd) modules. Use
|
|
24
|
+
[jsdelivr.com](https://jsdelivr.com) CDN site to load
|
|
25
|
+
[ditox](https://www.jsdelivr.com/package/npm/ditox) and
|
|
26
|
+
[ditox-react](https://www.jsdelivr.com/package/npm/ditox-react):
|
|
27
|
+
|
|
28
|
+
```html
|
|
29
|
+
<script src="//cdn.jsdelivr.net/npm/ditox/dist/umd/index.js" />
|
|
30
|
+
<script src="//cdn.jsdelivr.net/npm/ditox-react@2.3.0/dist/umd/index.js" />
|
|
31
|
+
<script>
|
|
32
|
+
const container = Ditox.createContainer();
|
|
33
|
+
// DitoxReact.useDependency(SOME_TOKEN);
|
|
34
|
+
</script>
|
|
46
35
|
```
|
|
47
36
|
|
|
48
|
-
##
|
|
37
|
+
## Overview
|
|
49
38
|
|
|
50
|
-
`ditox-react` is a set of helpers for providing and using a dependency container
|
|
39
|
+
`ditox-react` is a set of helpers for providing and using a dependency container
|
|
40
|
+
in React apps:
|
|
51
41
|
|
|
52
42
|
- Components:
|
|
53
|
-
- `DepencencyContainer` - provides a new or existed container to React
|
|
43
|
+
- `DepencencyContainer` - provides a new or existed container to React
|
|
44
|
+
components.
|
|
54
45
|
- `DepencencyModule` - binds a dependency module to a new container.
|
|
55
46
|
- `CustomDepencencyContainer` - provides an existed dependency container.
|
|
56
47
|
- Hooks:
|
|
57
48
|
- `useDependencyContainer()` - returns a provided dependency container.
|
|
58
|
-
- `useDependency()` - returns a resolved value by a specified token. It throws
|
|
59
|
-
|
|
49
|
+
- `useDependency()` - returns a resolved value by a specified token. It throws
|
|
50
|
+
an error in case a container or value is not found.
|
|
51
|
+
- `useOptionalDependency()` - returns a resolved value by a specified token,
|
|
52
|
+
or returns `undefined` in case a container or value is not found.
|
|
60
53
|
|
|
61
|
-
Examples
|
|
54
|
+
## Usage Examples
|
|
62
55
|
|
|
63
56
|
```jsx
|
|
64
57
|
import {token} from 'ditox';
|
|
65
58
|
import {
|
|
66
59
|
DependencyContainer,
|
|
67
|
-
DependencyModule,
|
|
68
60
|
useDependency,
|
|
69
61
|
useDependencyContainer,
|
|
70
62
|
useOptionalDependency,
|
|
71
63
|
} from 'ditox-react';
|
|
72
|
-
import {LOGGER_MODULE} from './logger';
|
|
73
64
|
|
|
74
|
-
const
|
|
75
|
-
const
|
|
65
|
+
const FOO_TOKEN = token();
|
|
66
|
+
const BAR_TOKEN = token();
|
|
76
67
|
|
|
77
68
|
function appDependencyBinder(container) {
|
|
78
|
-
container.bindValue(
|
|
69
|
+
container.bindValue(FOO_TOKEN, 'foo');
|
|
79
70
|
}
|
|
80
71
|
|
|
81
72
|
function App() {
|
|
@@ -91,10 +82,10 @@ function NestedComponent() {
|
|
|
91
82
|
const container = useDependencyContainer();
|
|
92
83
|
|
|
93
84
|
// Use a resolved value
|
|
94
|
-
const foo = useDependency(
|
|
85
|
+
const foo = useDependency(FOO_TOKEN);
|
|
95
86
|
|
|
96
87
|
// Use an optional value. It is not provided in this example.
|
|
97
|
-
const bar = useOptionalDependency(
|
|
88
|
+
const bar = useOptionalDependency(BAR_TOKEN);
|
|
98
89
|
|
|
99
90
|
useEffect(() => {
|
|
100
91
|
console.log({foo, bar}); // {foo: 'foo', bar: undefined}
|
|
@@ -104,9 +95,10 @@ function NestedComponent() {
|
|
|
104
95
|
}
|
|
105
96
|
```
|
|
106
97
|
|
|
107
|
-
## Dependency
|
|
98
|
+
## Dependency Modules
|
|
108
99
|
|
|
109
|
-
Dependency modules can be provided to the app with `<DependencyModule />`
|
|
100
|
+
Dependency modules can be provided to the app with `<DependencyModule />`
|
|
101
|
+
component:
|
|
110
102
|
|
|
111
103
|
```tsx
|
|
112
104
|
function App() {
|
|
@@ -118,11 +110,7 @@ function App() {
|
|
|
118
110
|
}
|
|
119
111
|
```
|
|
120
112
|
|
|
121
|
-
## API References
|
|
122
|
-
|
|
123
|
-
- [`ditox`](https://github.com/mnasyrov/ditox/tree/master/packages/ditox#readme)
|
|
124
|
-
- [`ditox-react`](./docs)
|
|
125
|
-
|
|
126
113
|
---
|
|
127
114
|
|
|
128
|
-
|
|
115
|
+
This project is licensed under the
|
|
116
|
+
[MIT license](https://github.com/mnasyrov/ditox/blob/master/LICENSE).
|
package/dist/browser/index.d.ts
CHANGED
|
@@ -4,20 +4,18 @@ 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;
|
|
17
17
|
};
|
|
18
18
|
/**
|
|
19
|
-
* @category Component
|
|
20
|
-
*
|
|
21
19
|
* Provides a new dependency container to React app
|
|
22
20
|
*
|
|
23
21
|
* This component creates a new container and provides it down to React children.
|
|
@@ -79,8 +77,6 @@ declare function useDependency<T>(token: Token<T>): T;
|
|
|
79
77
|
declare function useOptionalDependency<T>(token: Token<T>): T | undefined;
|
|
80
78
|
|
|
81
79
|
/**
|
|
82
|
-
* @category Component
|
|
83
|
-
*
|
|
84
80
|
* Binds the module to a new dependency container.
|
|
85
81
|
*
|
|
86
82
|
* If a parent container is exist, it is connected to the current one by default.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -4,20 +4,18 @@ 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;
|
|
17
17
|
};
|
|
18
18
|
/**
|
|
19
|
-
* @category Component
|
|
20
|
-
*
|
|
21
19
|
* Provides a new dependency container to React app
|
|
22
20
|
*
|
|
23
21
|
* This component creates a new container and provides it down to React children.
|
|
@@ -53,8 +51,6 @@ export declare type DependencyContainerParams = {
|
|
|
53
51
|
*/
|
|
54
52
|
export declare function DependencyContainer(params: DependencyContainerParams): ReactElement;
|
|
55
53
|
/**
|
|
56
|
-
* @category Component
|
|
57
|
-
*
|
|
58
54
|
* Provides a custom dependency container to React app
|
|
59
55
|
*
|
|
60
56
|
* @param params.container - a custom container
|
|
@@ -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];
|
|
@@ -24,8 +28,6 @@ const ditox_1 = require("ditox");
|
|
|
24
28
|
const react_1 = __importStar(require("react"));
|
|
25
29
|
exports.DependencyContainerContext = (0, react_1.createContext)(undefined);
|
|
26
30
|
/**
|
|
27
|
-
* @category Component
|
|
28
|
-
*
|
|
29
31
|
* Provides a new dependency container to React app
|
|
30
32
|
*
|
|
31
33
|
* This component creates a new container and provides it down to React children.
|
|
@@ -74,8 +76,6 @@ function DependencyContainer(params) {
|
|
|
74
76
|
}
|
|
75
77
|
exports.DependencyContainer = DependencyContainer;
|
|
76
78
|
/**
|
|
77
|
-
* @category Component
|
|
78
|
-
*
|
|
79
79
|
* Provides a custom dependency container to React app
|
|
80
80
|
*
|
|
81
81
|
* @param params.container - a custom container
|
|
@@ -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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;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;;;;;;;;;;;;;;;;;GAiBG;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,8 +1,6 @@
|
|
|
1
1
|
import type { Module, ModuleDeclaration } from 'ditox';
|
|
2
2
|
import { ReactElement, ReactNode } from 'react';
|
|
3
3
|
/**
|
|
4
|
-
* @category Component
|
|
5
|
-
*
|
|
6
4
|
* Binds the module to a new dependency container.
|
|
7
5
|
*
|
|
8
6
|
* If a parent container is exist, it is connected to the current one by default.
|
|
@@ -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];
|
|
@@ -24,8 +28,6 @@ const ditox_1 = require("ditox");
|
|
|
24
28
|
const react_1 = __importStar(require("react"));
|
|
25
29
|
const DependencyContainer_1 = require("./DependencyContainer");
|
|
26
30
|
/**
|
|
27
|
-
* @category Component
|
|
28
|
-
*
|
|
29
31
|
* Binds the module to a new dependency container.
|
|
30
32
|
*
|
|
31
33
|
* If a parent container is exist, it is connected to the current one by default.
|
|
@@ -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;;;;;;;;;;;;;;;;;;;;;GAqBG;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,20 +4,18 @@ 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;
|
|
17
17
|
};
|
|
18
18
|
/**
|
|
19
|
-
* @category Component
|
|
20
|
-
*
|
|
21
19
|
* Provides a new dependency container to React app
|
|
22
20
|
*
|
|
23
21
|
* This component creates a new container and provides it down to React children.
|
|
@@ -53,8 +51,6 @@ export declare type DependencyContainerParams = {
|
|
|
53
51
|
*/
|
|
54
52
|
export declare function DependencyContainer(params: DependencyContainerParams): ReactElement;
|
|
55
53
|
/**
|
|
56
|
-
* @category Component
|
|
57
|
-
*
|
|
58
54
|
* Provides a custom dependency container to React app
|
|
59
55
|
*
|
|
60
56
|
* @param params.container - a custom container
|
|
@@ -2,8 +2,6 @@ import { createContainer } from 'ditox';
|
|
|
2
2
|
import React, { createContext, useContext, useEffect, useMemo, } from 'react';
|
|
3
3
|
export const DependencyContainerContext = createContext(undefined);
|
|
4
4
|
/**
|
|
5
|
-
* @category Component
|
|
6
|
-
*
|
|
7
5
|
* Provides a new dependency container to React app
|
|
8
6
|
*
|
|
9
7
|
* This component creates a new container and provides it down to React children.
|
|
@@ -51,8 +49,6 @@ export function DependencyContainer(params) {
|
|
|
51
49
|
return (React.createElement(DependencyContainerContext.Provider, { value: container }, children));
|
|
52
50
|
}
|
|
53
51
|
/**
|
|
54
|
-
* @category Component
|
|
55
|
-
*
|
|
56
52
|
* Provides a custom dependency container to React app
|
|
57
53
|
*
|
|
58
54
|
* @param params.container - a custom container
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DependencyContainer.js","sourceRoot":"","sources":["../../src/DependencyContainer.tsx"],"names":[],"mappings":"AACA,OAAO,EAAC,eAAe,EAAC,MAAM,OAAO,CAAC;AACtC,OAAO,KAAK,EAAE,EACZ,aAAa,EAGb,UAAU,EACV,SAAS,EACT,OAAO,GACR,MAAM,OAAO,CAAC;AAEf,MAAM,CAAC,MAAM,0BAA0B,GAAG,aAAa,CACrD,SAAS,CACV,CAAC;AAkBF
|
|
1
|
+
{"version":3,"file":"DependencyContainer.js","sourceRoot":"","sources":["../../src/DependencyContainer.tsx"],"names":[],"mappings":"AACA,OAAO,EAAC,eAAe,EAAC,MAAM,OAAO,CAAC;AACtC,OAAO,KAAK,EAAE,EACZ,aAAa,EAGb,UAAU,EACV,SAAS,EACT,OAAO,GACR,MAAM,OAAO,CAAC;AAEf,MAAM,CAAC,MAAM,0BAA0B,GAAG,aAAa,CACrD,SAAS,CACV,CAAC;AAkBF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,UAAU,mBAAmB,CACjC,MAAiC;IAEjC,MAAM,EAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAC,GAAG,MAAM,CAAC;IACxC,MAAM,eAAe,GAAG,UAAU,CAAC,0BAA0B,CAAC,CAAC;IAE/D,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,EAAE;QAC7B,MAAM,SAAS,GAAG,eAAe,CAAC,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,SAAS,CAAC,GAAG,EAAE;QACb,OAAO,GAAG,EAAE,CAAC,SAAS,CAAC,SAAS,EAAE,CAAC;IACrC,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;IAEhB,OAAO,CACL,oBAAC,0BAA0B,CAAC,QAAQ,IAAC,KAAK,EAAE,SAAS,IAClD,QAAQ,CAC2B,CACvC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,yBAAyB,CAAC,MAGzC;IACC,MAAM,EAAC,QAAQ,EAAE,SAAS,EAAC,GAAG,MAAM,CAAC;IAErC,OAAO,CACL,oBAAC,0BAA0B,CAAC,QAAQ,IAAC,KAAK,EAAE,SAAS,IAClD,QAAQ,CAC2B,CACvC,CAAC;AACJ,CAAC"}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { Module, ModuleDeclaration } from 'ditox';
|
|
2
2
|
import { ReactElement, ReactNode } from 'react';
|
|
3
3
|
/**
|
|
4
|
-
* @category Component
|
|
5
|
-
*
|
|
6
4
|
* Binds the module to a new dependency container.
|
|
7
5
|
*
|
|
8
6
|
* If a parent container is exist, it is connected to the current one by default.
|
|
@@ -2,8 +2,6 @@ import { bindModule } from 'ditox';
|
|
|
2
2
|
import React, { useCallback } from 'react';
|
|
3
3
|
import { DependencyContainer, } from './DependencyContainer';
|
|
4
4
|
/**
|
|
5
|
-
* @category Component
|
|
6
|
-
*
|
|
7
5
|
* Binds the module to a new dependency container.
|
|
8
6
|
*
|
|
9
7
|
* If a parent container is exist, it is connected to the current one by default.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DependencyModule.js","sourceRoot":"","sources":["../../src/DependencyModule.tsx"],"names":[],"mappings":"AACA,OAAO,EAAC,UAAU,EAAC,MAAM,OAAO,CAAC;AACjC,OAAO,KAAK,EAAE,EAA0B,WAAW,EAAC,MAAM,OAAO,CAAC;AAClE,OAAO,EACL,mBAAmB,GAEpB,MAAM,uBAAuB,CAAC;AAE/B
|
|
1
|
+
{"version":3,"file":"DependencyModule.js","sourceRoot":"","sources":["../../src/DependencyModule.tsx"],"names":[],"mappings":"AACA,OAAO,EAAC,UAAU,EAAC,MAAM,OAAO,CAAC;AACjC,OAAO,KAAK,EAAE,EAA0B,WAAW,EAAC,MAAM,OAAO,CAAC;AAClE,OAAO,EACL,mBAAmB,GAEpB,MAAM,uBAAuB,CAAC;AAE/B;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAIhC;IACC,MAAM,EAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAC,GAAG,MAAM,CAAC;IAEzC,MAAM,MAAM,GAA8B,WAAW,CACnD,CAAC,SAAS,EAAE,EAAE,CAAC,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,EAAC,KAAK,EAAC,CAAC,EACrD,CAAC,MAAM,EAAE,KAAK,CAAC,CAChB,CAAC;IAEF,OAAO,oBAAC,mBAAmB,IAAC,MAAM,EAAE,MAAM,IAAG,QAAQ,CAAuB,CAAC;AAC/E,CAAC"}
|
package/dist/umd/index.d.ts
CHANGED
|
@@ -4,20 +4,18 @@ 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;
|
|
17
17
|
};
|
|
18
18
|
/**
|
|
19
|
-
* @category Component
|
|
20
|
-
*
|
|
21
19
|
* Provides a new dependency container to React app
|
|
22
20
|
*
|
|
23
21
|
* This component creates a new container and provides it down to React children.
|
|
@@ -79,8 +77,6 @@ declare function useDependency<T>(token: Token<T>): T;
|
|
|
79
77
|
declare function useOptionalDependency<T>(token: Token<T>): T | undefined;
|
|
80
78
|
|
|
81
79
|
/**
|
|
82
|
-
* @category Component
|
|
83
|
-
*
|
|
84
80
|
* Binds the module to a new dependency container.
|
|
85
81
|
*
|
|
86
82
|
* If a parent container is exist, it is connected to the current one by default.
|
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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ditox-react",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.3.1",
|
|
4
|
+
"description": "Dependency injection container for React.js",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -14,14 +14,19 @@
|
|
|
14
14
|
"url": "https://github.com/mnasyrov/ditox.git"
|
|
15
15
|
},
|
|
16
16
|
"keywords": [
|
|
17
|
-
"
|
|
17
|
+
"react",
|
|
18
|
+
"react.js",
|
|
19
|
+
"dependency container",
|
|
20
|
+
"dependency injection",
|
|
21
|
+
"typescript",
|
|
22
|
+
"javascript",
|
|
23
|
+
"npm",
|
|
18
24
|
"dependency",
|
|
19
25
|
"injection",
|
|
20
26
|
"container",
|
|
27
|
+
"module",
|
|
21
28
|
"ioc",
|
|
22
|
-
"di"
|
|
23
|
-
"ditox.js",
|
|
24
|
-
"react"
|
|
29
|
+
"di"
|
|
25
30
|
],
|
|
26
31
|
"engines": {
|
|
27
32
|
"node": ">=12"
|
|
@@ -48,21 +53,21 @@
|
|
|
48
53
|
"build": "npm run build:cjs && npm run build:esm && npm run build:rollup",
|
|
49
54
|
"build:cjs": "tsc -p tsconfig.build.json --outDir dist/cjs --module commonjs",
|
|
50
55
|
"build:esm": "tsc -p tsconfig.build.json --outDir dist/esm --module es2015",
|
|
51
|
-
"build:rollup": "rollup -c"
|
|
56
|
+
"build:rollup": "rollup -c",
|
|
57
|
+
"typedoc": "typedoc"
|
|
52
58
|
},
|
|
53
59
|
"dependencies": {
|
|
54
|
-
"ditox": "2.
|
|
60
|
+
"ditox": "2.3.1"
|
|
55
61
|
},
|
|
56
62
|
"peerDependencies": {
|
|
57
|
-
"react": "^16.8.0 || ^17.0.0"
|
|
63
|
+
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
|
|
58
64
|
},
|
|
59
65
|
"devDependencies": {
|
|
60
|
-
"@testing-library/react": "
|
|
61
|
-
"@
|
|
62
|
-
"
|
|
63
|
-
"react": "
|
|
64
|
-
"react-
|
|
65
|
-
"react-test-renderer": "17.0.2"
|
|
66
|
+
"@testing-library/react": "13.4.0",
|
|
67
|
+
"@types/react": "18.0.26",
|
|
68
|
+
"react": "18.2.0",
|
|
69
|
+
"react-dom": "18.2.0",
|
|
70
|
+
"react-test-renderer": "18.2.0"
|
|
66
71
|
},
|
|
67
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "1e10e32350931dba38acc4d00b2cc1cd6d5cffb5"
|
|
68
73
|
}
|
|
@@ -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 {
|
|
@@ -30,8 +30,6 @@ export type DependencyContainerParams = {
|
|
|
30
30
|
};
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
|
-
* @category Component
|
|
34
|
-
*
|
|
35
33
|
* Provides a new dependency container to React app
|
|
36
34
|
*
|
|
37
35
|
* This component creates a new container and provides it down to React children.
|
|
@@ -90,8 +88,6 @@ export function DependencyContainer(
|
|
|
90
88
|
}
|
|
91
89
|
|
|
92
90
|
/**
|
|
93
|
-
* @category Component
|
|
94
|
-
*
|
|
95
91
|
* Provides a custom dependency container to React app
|
|
96
92
|
*
|
|
97
93
|
* @param params.container - a custom container
|
package/src/DependencyModule.tsx
CHANGED
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
|
});
|
package/docs/.nojekyll
DELETED
|
@@ -1 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,297 +0,0 @@
|
|
|
1
|
-
ditox-react
|
|
2
|
-
|
|
3
|
-
# ditox-react
|
|
4
|
-
|
|
5
|
-
## Table of contents
|
|
6
|
-
|
|
7
|
-
### Type aliases
|
|
8
|
-
|
|
9
|
-
- [DependencyContainerBinder](README.md#dependencycontainerbinder)
|
|
10
|
-
- [DependencyContainerParams](README.md#dependencycontainerparams)
|
|
11
|
-
|
|
12
|
-
### Component
|
|
13
|
-
|
|
14
|
-
Binds the module to a new dependency container.
|
|
15
|
-
|
|
16
|
-
If a parent container is exist, it is connected to the current one by default. Functions
|
|
17
|
-
|
|
18
|
-
- [DependencyModule](README.md#dependencymodule)
|
|
19
|
-
|
|
20
|
-
### Component
|
|
21
|
-
|
|
22
|
-
Provides a new dependency container to React app
|
|
23
|
-
|
|
24
|
-
This component creates a new container and provides it down to React children.
|
|
25
|
-
|
|
26
|
-
If `binder` callback is specified, it will be called for a new container
|
|
27
|
-
to binds it with dependencies.
|
|
28
|
-
|
|
29
|
-
If a parent container is exist, it is connected to the current one by default.
|
|
30
|
-
For making a new root container specify `root` parameter as `true`,
|
|
31
|
-
and the container will not depend on any parent container. Functions
|
|
32
|
-
|
|
33
|
-
- [DependencyContainer](README.md#dependencycontainer)
|
|
34
|
-
|
|
35
|
-
### Hook
|
|
36
|
-
|
|
37
|
-
Returns a dependency by token, or `undefined` in case the dependency is not provided. Functions
|
|
38
|
-
|
|
39
|
-
- [useOptionalDependency](README.md#useoptionaldependency)
|
|
40
|
-
|
|
41
|
-
### Hook
|
|
42
|
-
|
|
43
|
-
Returns a dependency by token, or fails with an error. Functions
|
|
44
|
-
|
|
45
|
-
- [useDependency](README.md#usedependency)
|
|
46
|
-
|
|
47
|
-
### Other Functions
|
|
48
|
-
|
|
49
|
-
- [useDependencyContainer](README.md#usedependencycontainer)
|
|
50
|
-
|
|
51
|
-
## Type aliases
|
|
52
|
-
|
|
53
|
-
### DependencyContainerBinder
|
|
54
|
-
|
|
55
|
-
Ƭ **DependencyContainerBinder**: (`container`: `Container`) => `unknown`
|
|
56
|
-
|
|
57
|
-
#### Type declaration
|
|
58
|
-
|
|
59
|
-
▸ (`container`): `unknown`
|
|
60
|
-
|
|
61
|
-
A callback for binding dependencies to a container
|
|
62
|
-
|
|
63
|
-
##### Parameters
|
|
64
|
-
|
|
65
|
-
| Name | Type |
|
|
66
|
-
| :------ | :------ |
|
|
67
|
-
| `container` | `Container` |
|
|
68
|
-
|
|
69
|
-
##### Returns
|
|
70
|
-
|
|
71
|
-
`unknown`
|
|
72
|
-
|
|
73
|
-
#### Defined in
|
|
74
|
-
|
|
75
|
-
[DependencyContainer.tsx:19](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox-react/src/DependencyContainer.tsx#L19)
|
|
76
|
-
|
|
77
|
-
___
|
|
78
|
-
|
|
79
|
-
### DependencyContainerParams
|
|
80
|
-
|
|
81
|
-
Ƭ **DependencyContainerParams**: `Object`
|
|
82
|
-
|
|
83
|
-
Specifies an existed container or options for a new container:
|
|
84
|
-
|
|
85
|
-
**`property`** binder - A callback which setup bindings to the container.
|
|
86
|
-
|
|
87
|
-
**`property`** root - If `true` then a new container does not depend on any parent containers
|
|
88
|
-
|
|
89
|
-
#### Type declaration
|
|
90
|
-
|
|
91
|
-
| Name | Type |
|
|
92
|
-
| :------ | :------ |
|
|
93
|
-
| `binder?` | [`DependencyContainerBinder`](README.md#dependencycontainerbinder) |
|
|
94
|
-
| `children` | `ReactNode` |
|
|
95
|
-
| `root?` | `boolean` |
|
|
96
|
-
|
|
97
|
-
#### Defined in
|
|
98
|
-
|
|
99
|
-
[DependencyContainer.tsx:26](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox-react/src/DependencyContainer.tsx#L26)
|
|
100
|
-
|
|
101
|
-
## Component
|
|
102
|
-
|
|
103
|
-
Binds the module to a new dependency container.
|
|
104
|
-
|
|
105
|
-
If a parent container is exist, it is connected to the current one by default. Functions
|
|
106
|
-
|
|
107
|
-
### DependencyModule
|
|
108
|
-
|
|
109
|
-
▸ **DependencyModule**(`params`): `ReactElement`
|
|
110
|
-
|
|
111
|
-
**`example`**
|
|
112
|
-
|
|
113
|
-
```tsx
|
|
114
|
-
const LOGGER_MODULE: ModuleDeclaration<LoggerModule> = {
|
|
115
|
-
|
|
116
|
-
function App() {
|
|
117
|
-
return (
|
|
118
|
-
<DependencyModule module={LOGGER_MODULE}>
|
|
119
|
-
<NestedComponent />
|
|
120
|
-
</DependencyModule>
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
#### Parameters
|
|
126
|
-
|
|
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`. |
|
|
133
|
-
|
|
134
|
-
#### Returns
|
|
135
|
-
|
|
136
|
-
`ReactElement`
|
|
137
|
-
|
|
138
|
-
#### Defined in
|
|
139
|
-
|
|
140
|
-
[DependencyModule.tsx:33](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox-react/src/DependencyModule.tsx#L33)
|
|
141
|
-
|
|
142
|
-
___
|
|
143
|
-
|
|
144
|
-
## Component
|
|
145
|
-
|
|
146
|
-
Provides a new dependency container to React app
|
|
147
|
-
|
|
148
|
-
This component creates a new container and provides it down to React children.
|
|
149
|
-
|
|
150
|
-
If `binder` callback is specified, it will be called for a new container
|
|
151
|
-
to binds it with dependencies.
|
|
152
|
-
|
|
153
|
-
If a parent container is exist, it is connected to the current one by default.
|
|
154
|
-
For making a new root container specify `root` parameter as `true`,
|
|
155
|
-
and the container will not depend on any parent container. Functions
|
|
156
|
-
|
|
157
|
-
### DependencyContainer
|
|
158
|
-
|
|
159
|
-
▸ **DependencyContainer**(`params`): `ReactElement`
|
|
160
|
-
|
|
161
|
-
**`example`**
|
|
162
|
-
|
|
163
|
-
```tsx
|
|
164
|
-
const TOKEN = token();
|
|
165
|
-
|
|
166
|
-
function appDependencyBinder(container: Container) {
|
|
167
|
-
container.bindValue(TOKEN, 'value');
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
function App() {
|
|
171
|
-
return (
|
|
172
|
-
<DependencyContainer root binder={appDependencyBinder}>
|
|
173
|
-
<NestedComponent />
|
|
174
|
-
</DependencyContainer>
|
|
175
|
-
);
|
|
176
|
-
}
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
#### Parameters
|
|
180
|
-
|
|
181
|
-
| Name | Type |
|
|
182
|
-
| :------ | :------ |
|
|
183
|
-
| `params` | [`DependencyContainerParams`](README.md#dependencycontainerparams) |
|
|
184
|
-
|
|
185
|
-
#### Returns
|
|
186
|
-
|
|
187
|
-
`ReactElement`
|
|
188
|
-
|
|
189
|
-
#### Defined in
|
|
190
|
-
|
|
191
|
-
[DependencyContainer.tsx:68](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox-react/src/DependencyContainer.tsx#L68)
|
|
192
|
-
|
|
193
|
-
___
|
|
194
|
-
|
|
195
|
-
## Hook
|
|
196
|
-
|
|
197
|
-
Returns a dependency by token, or `undefined` in case the dependency is not provided. Functions
|
|
198
|
-
|
|
199
|
-
### useOptionalDependency
|
|
200
|
-
|
|
201
|
-
▸ **useOptionalDependency**<`T`\>(`token`): `T` \| `undefined`
|
|
202
|
-
|
|
203
|
-
#### Type parameters
|
|
204
|
-
|
|
205
|
-
| Name |
|
|
206
|
-
| :------ |
|
|
207
|
-
| `T` |
|
|
208
|
-
|
|
209
|
-
#### Parameters
|
|
210
|
-
|
|
211
|
-
| Name | Type |
|
|
212
|
-
| :------ | :------ |
|
|
213
|
-
| `token` | `Token`<`T`\> |
|
|
214
|
-
|
|
215
|
-
#### Returns
|
|
216
|
-
|
|
217
|
-
`T` \| `undefined`
|
|
218
|
-
|
|
219
|
-
#### Defined in
|
|
220
|
-
|
|
221
|
-
[hooks.ts:52](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox-react/src/hooks.ts#L52)
|
|
222
|
-
|
|
223
|
-
___
|
|
224
|
-
|
|
225
|
-
## Hook
|
|
226
|
-
|
|
227
|
-
Returns a dependency by token, or fails with an error. Functions
|
|
228
|
-
|
|
229
|
-
### useDependency
|
|
230
|
-
|
|
231
|
-
▸ **useDependency**<`T`\>(`token`): `T`
|
|
232
|
-
|
|
233
|
-
#### Type parameters
|
|
234
|
-
|
|
235
|
-
| Name |
|
|
236
|
-
| :------ |
|
|
237
|
-
| `T` |
|
|
238
|
-
|
|
239
|
-
#### Parameters
|
|
240
|
-
|
|
241
|
-
| Name | Type |
|
|
242
|
-
| :------ | :------ |
|
|
243
|
-
| `token` | `Token`<`T`\> |
|
|
244
|
-
|
|
245
|
-
#### Returns
|
|
246
|
-
|
|
247
|
-
`T`
|
|
248
|
-
|
|
249
|
-
#### Defined in
|
|
250
|
-
|
|
251
|
-
[hooks.ts:41](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox-react/src/hooks.ts#L41)
|
|
252
|
-
|
|
253
|
-
___
|
|
254
|
-
|
|
255
|
-
## Other Functions
|
|
256
|
-
|
|
257
|
-
### useDependencyContainer
|
|
258
|
-
|
|
259
|
-
▸ **useDependencyContainer**(`mode`): `Container`
|
|
260
|
-
|
|
261
|
-
**`category`** Hook
|
|
262
|
-
|
|
263
|
-
Returns a dependency container. Throws an error in case the container is not provided.
|
|
264
|
-
|
|
265
|
-
#### Parameters
|
|
266
|
-
|
|
267
|
-
| Name | Type |
|
|
268
|
-
| :------ | :------ |
|
|
269
|
-
| `mode` | ``"strict"`` |
|
|
270
|
-
|
|
271
|
-
#### Returns
|
|
272
|
-
|
|
273
|
-
`Container`
|
|
274
|
-
|
|
275
|
-
#### Defined in
|
|
276
|
-
|
|
277
|
-
[hooks.ts:10](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox-react/src/hooks.ts#L10)
|
|
278
|
-
|
|
279
|
-
▸ **useDependencyContainer**(`mode?`): `Container` \| `undefined`
|
|
280
|
-
|
|
281
|
-
**`category`** Hook
|
|
282
|
-
|
|
283
|
-
Returns a dependency container, or `undefined` in case the container is not provided.
|
|
284
|
-
|
|
285
|
-
#### Parameters
|
|
286
|
-
|
|
287
|
-
| Name | Type |
|
|
288
|
-
| :------ | :------ |
|
|
289
|
-
| `mode?` | ``"optional"`` |
|
|
290
|
-
|
|
291
|
-
#### Returns
|
|
292
|
-
|
|
293
|
-
`Container` \| `undefined`
|
|
294
|
-
|
|
295
|
-
#### Defined in
|
|
296
|
-
|
|
297
|
-
[hooks.ts:16](https://github.com/mnasyrov/ditox/blob/a821171/packages/ditox-react/src/hooks.ts#L16)
|