ditox-react 2.3.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 Mikhail Nasyrov
3
+ Copyright (c) 2023 Mikhail Nasyrov
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
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
- React.js tooling for [Ditox.js](https://github.com/mnasyrov/ditox) DI container.
5
+ **Dependency injection container for React.js**
6
6
 
7
- [![npm](https://img.shields.io/npm/v/ditox.svg)](https://www.npmjs.com/package/ditox)
8
- [![downloads](https://img.shields.io/npm/dt/ditox.svg)](https://www.npmjs.com/package/ditox)
9
- [![types](https://img.shields.io/npm/types/ditox.svg)](https://www.npmjs.com/package/ditox)
10
- [![licence](https://img.shields.io/github/license/mnasyrov/ditox.svg)](https://github.com/mnasyrov/ditox/blob/master/LICENSE)
11
- [![Coverage Status](https://coveralls.io/repos/github/mnasyrov/ditox/badge.svg)](https://coveralls.io/github/mnasyrov/ditox)
7
+ Please see the documentation at [ditox.js.org](https://ditox.js.org)
12
8
 
13
- ## Table of Contents
14
-
15
- <!-- toc -->
16
-
17
- - [Features](#features)
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
+ [![npm](https://img.shields.io/npm/v/ditox)](https://www.npmjs.com/package/ditox)
10
+ [![stars](https://img.shields.io/github/stars/mnasyrov/ditox)](https://github.com/mnasyrov/ditox/stargazers)
11
+ [![types](https://img.shields.io/npm/types/ditox)](https://www.npmjs.com/package/ditox)
12
+ [![licence](https://img.shields.io/github/license/mnasyrov/ditox)](https://github.com/mnasyrov/ditox/blob/master/LICENSE)
13
+ [![coverage](https://coveralls.io/repos/github/mnasyrov/ditox/badge)](https://coveralls.io/github/mnasyrov/ditox)
33
14
 
34
15
  ## Installation
35
16
 
36
- Install with `npm`
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
- yarn add ditox ditox-react
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
- ## Usage
37
+ ## Overview
49
38
 
50
- `ditox-react` is a set of helpers for providing and using a dependency container in React apps:
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 components.
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 an error in case a container or value is not found.
59
- - `useOptionalDependency()` - returns a resolved value by a specified token, or returns `undefined` in case a container or value is not found.
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 FOO = token();
75
- const BAR = token();
65
+ const FOO_TOKEN = token();
66
+ const BAR_TOKEN = token();
76
67
 
77
68
  function appDependencyBinder(container) {
78
- container.bindValue(FOO, 'foo');
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(FOO);
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(BAR);
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 modules
98
+ ## Dependency Modules
108
99
 
109
- Dependency modules can be provided to the app with `<DependencyModule />` component:
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
- &copy; 2020-2021 [Mikhail Nasyrov](https://github.com/mnasyrov), [MIT license](./LICENSE)
115
+ This project is licensed under the
116
+ [MIT license](https://github.com/mnasyrov/ditox/blob/master/LICENSE).
@@ -16,8 +16,6 @@ type DependencyContainerParams = {
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.
@@ -16,8 +16,6 @@ export type DependencyContainerParams = {
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 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
@@ -28,8 +28,6 @@ const ditox_1 = require("ditox");
28
28
  const react_1 = __importStar(require("react"));
29
29
  exports.DependencyContainerContext = (0, react_1.createContext)(undefined);
30
30
  /**
31
- * @category Component
32
- *
33
31
  * Provides a new dependency container to React app
34
32
  *
35
33
  * This component creates a new container and provides it down to React children.
@@ -78,8 +76,6 @@ function DependencyContainer(params) {
78
76
  }
79
77
  exports.DependencyContainer = DependencyContainer;
80
78
  /**
81
- * @category Component
82
- *
83
79
  * Provides a custom dependency container to React app
84
80
  *
85
81
  * @param params.container - a custom container
@@ -1 +1 @@
1
- {"version":3,"file":"DependencyContainer.js","sourceRoot":"","sources":["../../src/DependencyContainer.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAC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,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.
@@ -28,8 +28,6 @@ const ditox_1 = require("ditox");
28
28
  const react_1 = __importStar(require("react"));
29
29
  const DependencyContainer_1 = require("./DependencyContainer");
30
30
  /**
31
- * @category Component
32
- *
33
31
  * Binds the module to a new dependency container.
34
32
  *
35
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":";;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;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"}
@@ -16,8 +16,6 @@ export type DependencyContainerParams = {
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 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,CAA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uleDeclaration } 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;;;;;;;;;;;;;;;;;;;;;;;GAuBG;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"}
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"}
@@ -16,8 +16,6 @@ type DependencyContainerParams = {
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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ditox-react",
3
- "version": "2.3.0",
4
- "description": "Ditox.js tooling for React.js",
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
- "dependency-injection",
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,10 +53,11 @@
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.3.0"
60
+ "ditox": "2.3.1"
55
61
  },
56
62
  "peerDependencies": {
57
63
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0"
@@ -63,5 +69,5 @@
63
69
  "react-dom": "18.2.0",
64
70
  "react-test-renderer": "18.2.0"
65
71
  },
66
- "gitHead": "3d34ea7a89e0bb599fa2d9dbfa67e75ec68bfba2"
72
+ "gitHead": "1e10e32350931dba38acc4d00b2cc1cd6d5cffb5"
67
73
  }
@@ -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
@@ -7,8 +7,6 @@ import {
7
7
  } from './DependencyContainer';
8
8
 
9
9
  /**
10
- * @category Component
11
- *
12
10
  * Binds the module to a new dependency container.
13
11
  *
14
12
  * If a parent container is exist, it is connected to the current one by default.
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,343 +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 &#x60;binder&#x60; 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 &#x60;root&#x60; parameter as &#x60;true&#x60;,
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 &#x60;undefined&#x60; 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
- ### Hook
48
-
49
- Returns a dependency container, or &#x60;undefined&#x60; 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
56
-
57
- - [useDependencyContainer](README.md#usedependencycontainer)
58
-
59
- ## Type Aliases
60
-
61
- ### DependencyContainerBinder
62
-
63
- Ƭ **DependencyContainerBinder**: (`container`: `Container`) => `unknown`
64
-
65
- #### Type declaration
66
-
67
- ▸ (`container`): `unknown`
68
-
69
- A callback for binding dependencies to a container
70
-
71
- ##### Parameters
72
-
73
- | Name | Type |
74
- | :---------- | :---------- |
75
- | `container` | `Container` |
76
-
77
- ##### Returns
78
-
79
- `unknown`
80
-
81
- #### Defined in
82
-
83
- [DependencyContainer.tsx:19](https://github.com/mnasyrov/ditox/blob/37f658c/packages/ditox-react/src/DependencyContainer.tsx#L19)
84
-
85
- ---
86
-
87
- ### DependencyContainerParams
88
-
89
- Ƭ **DependencyContainerParams**: `Object`
90
-
91
- Specifies an existed container or options for a new container:
92
-
93
- **`Property`**
94
-
95
- A callback which setup bindings to the container.
96
-
97
- **`Property`**
98
-
99
- If `true` then a new container does not depend on any parent containers
100
-
101
- #### Type declaration
102
-
103
- | Name | Type |
104
- | :--------- | :----------------------------------------------------------------- |
105
- | `binder?` | [`DependencyContainerBinder`](README.md#dependencycontainerbinder) |
106
- | `children` | `ReactNode` |
107
- | `root?` | `boolean` |
108
-
109
- #### Defined in
110
-
111
- [DependencyContainer.tsx:26](https://github.com/mnasyrov/ditox/blob/37f658c/packages/ditox-react/src/DependencyContainer.tsx#L26)
112
-
113
- ## Component
114
-
115
- Binds the module to a new dependency container.
116
-
117
- If a parent container is exist, it is connected to the current one by default. Functions
118
-
119
- ### DependencyModule
120
-
121
- ▸ **DependencyModule**(`params`): `ReactElement`
122
-
123
- **`Example`**
124
-
125
- ```tsx
126
- const LOGGER_MODULE: ModuleDeclaration<LoggerModule> = {
127
-
128
- function App() {
129
- return (
130
- <DependencyModule module={LOGGER_MODULE}>
131
- <NestedComponent />
132
- </DependencyModule>
133
- );
134
- }
135
- ```
136
-
137
- #### Parameters
138
-
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`. |
145
-
146
- #### Returns
147
-
148
- `ReactElement`
149
-
150
- #### Defined in
151
-
152
- [DependencyModule.tsx:33](https://github.com/mnasyrov/ditox/blob/37f658c/packages/ditox-react/src/DependencyModule.tsx#L33)
153
-
154
- ---
155
-
156
- ## Component
157
-
158
- Provides a new dependency container to React app
159
-
160
- This component creates a new container and provides it down to React children.
161
-
162
- If &#x60;binder&#x60; callback is specified, it will be called for a new container
163
- to binds it with dependencies.
164
-
165
- If a parent container is exist, it is connected to the current one by default.
166
- For making a new root container specify &#x60;root&#x60; parameter as &#x60;true&#x60;,
167
- and the container will not depend on any parent container. Functions
168
-
169
- ### DependencyContainer
170
-
171
- ▸ **DependencyContainer**(`params`): `ReactElement`
172
-
173
- **`Example`**
174
-
175
- ```tsx
176
- const TOKEN = token();
177
-
178
- function appDependencyBinder(container: Container) {
179
- container.bindValue(TOKEN, 'value');
180
- }
181
-
182
- function App() {
183
- return (
184
- <DependencyContainer root binder={appDependencyBinder}>
185
- <NestedComponent />
186
- </DependencyContainer>
187
- );
188
- }
189
- ```
190
-
191
- #### Parameters
192
-
193
- | Name | Type |
194
- | :------- | :----------------------------------------------------------------- |
195
- | `params` | [`DependencyContainerParams`](README.md#dependencycontainerparams) |
196
-
197
- #### Returns
198
-
199
- `ReactElement`
200
-
201
- #### Defined in
202
-
203
- [DependencyContainer.tsx:68](https://github.com/mnasyrov/ditox/blob/37f658c/packages/ditox-react/src/DependencyContainer.tsx#L68)
204
-
205
- ---
206
-
207
- ## Hook
208
-
209
- Returns a dependency by token, or &#x60;undefined&#x60; in case the dependency is not provided. Functions
210
-
211
- ### useOptionalDependency
212
-
213
- ▸ **useOptionalDependency**<`T`\>(`token`): `T` \| `undefined`
214
-
215
- #### Type parameters
216
-
217
- | Name |
218
- | :--- |
219
- | `T` |
220
-
221
- #### Parameters
222
-
223
- | Name | Type |
224
- | :------ | :------------ |
225
- | `token` | `Token`<`T`\> |
226
-
227
- #### Returns
228
-
229
- `T` \| `undefined`
230
-
231
- #### Defined in
232
-
233
- [hooks.ts:52](https://github.com/mnasyrov/ditox/blob/37f658c/packages/ditox-react/src/hooks.ts#L52)
234
-
235
- ---
236
-
237
- ## Hook
238
-
239
- Returns a dependency by token, or fails with an error. Functions
240
-
241
- ### useDependency
242
-
243
- ▸ **useDependency**<`T`\>(`token`): `T`
244
-
245
- #### Type parameters
246
-
247
- | Name |
248
- | :--- |
249
- | `T` |
250
-
251
- #### Parameters
252
-
253
- | Name | Type |
254
- | :------ | :------------ |
255
- | `token` | `Token`<`T`\> |
256
-
257
- #### Returns
258
-
259
- `T`
260
-
261
- #### Defined in
262
-
263
- [hooks.ts:41](https://github.com/mnasyrov/ditox/blob/37f658c/packages/ditox-react/src/hooks.ts#L41)
264
-
265
- ---
266
-
267
- ## Hook
268
-
269
- Returns a dependency container, or &#x60;undefined&#x60; in case the container is not provided. Functions
270
-
271
- ### useDependencyContainer
272
-
273
- ▸ **useDependencyContainer**(`mode`): `Container`
274
-
275
- #### Parameters
276
-
277
- | Name | Type |
278
- | :----- | :--------- |
279
- | `mode` | `"strict"` |
280
-
281
- #### Returns
282
-
283
- `Container`
284
-
285
- #### Defined in
286
-
287
- [hooks.ts:10](https://github.com/mnasyrov/ditox/blob/37f658c/packages/ditox-react/src/hooks.ts#L10)
288
-
289
- ▸ **useDependencyContainer**(`mode?`): `Container` \| `undefined`
290
-
291
- #### Parameters
292
-
293
- | Name | Type |
294
- | :------ | :----------- |
295
- | `mode?` | `"optional"` |
296
-
297
- #### Returns
298
-
299
- `Container` \| `undefined`
300
-
301
- #### Defined in
302
-
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`
330
-
331
- #### Parameters
332
-
333
- | Name | Type |
334
- | :------ | :----------- |
335
- | `mode?` | `"optional"` |
336
-
337
- #### Returns
338
-
339
- `Container` \| `undefined`
340
-
341
- #### Defined in
342
-
343
- [hooks.ts:16](https://github.com/mnasyrov/ditox/blob/37f658c/packages/ditox-react/src/hooks.ts#L16)