Skip to content

Latest commit

 

History

History
353 lines (209 loc) · 8.15 KB

README.md

File metadata and controls

353 lines (209 loc) · 8.15 KB

ditox-react

ditox-react

Table of contents

Type Aliases

Component

Binds the module to a new dependency container.

If a parent container is exist, it is connected to the current one by default. Functions

Component

Provides a new dependency container to React app

This component creates a new container and provides it down to React children.

If `binder` callback is specified, it will be called for a new container to binds it with dependencies.

If a parent container is exist, it is connected to the current one by default. For making a new root container specify `root` parameter as `true`, and the container will not depend on any parent container. Functions

Hook

Returns a dependency by token, or `undefined` in case the dependency is not provided. Functions

Hook

Returns a dependency by token, or fails with an error. Functions

Hook

Returns a dependency container, or `undefined` in case the container is not provided. Functions

Hook

Returns a dependency container. Throws an error in case the container is not provided. Functions

Type Aliases

DependencyContainerBinder

Ƭ DependencyContainerBinder: (container: Container) => unknown

Type declaration

▸ (container): unknown

A callback for binding dependencies to a container

Parameters
Name Type
container Container
Returns

unknown

Defined in

DependencyContainer.tsx:19


DependencyContainerParams

Ƭ DependencyContainerParams: Object

Specifies an existed container or options for a new container:

Property

A callback which setup bindings to the container.

Property

If true then a new container does not depend on any parent containers

Type declaration

Name Type
binder? DependencyContainerBinder
children ReactNode
root? boolean

Defined in

DependencyContainer.tsx:26

Component

Binds the module to a new dependency container.

If a parent container is exist, it is connected to the current one by default. Functions

DependencyModule

DependencyModule(params): ReactElement

Example

const LOGGER_MODULE: ModuleDeclaration<LoggerModule> = {

function App() {
  return (
    <DependencyModule module={LOGGER_MODULE}>
      <NestedComponent />
    </DependencyModule>
  );
}

Parameters

Name Type Description
params Object -
params.children ReactNode -
params.module ModuleDeclaration<Module<Record<string, unknown>>> Module declaration for binding
params.scope? "scoped" | "singleton" Optional scope for binding: singleton (default) or scoped.

Returns

ReactElement

Defined in

DependencyModule.tsx:33


Component

Provides a new dependency container to React app

This component creates a new container and provides it down to React children.

If `binder` callback is specified, it will be called for a new container to binds it with dependencies.

If a parent container is exist, it is connected to the current one by default. For making a new root container specify `root` parameter as `true`, and the container will not depend on any parent container. Functions

DependencyContainer

DependencyContainer(params): ReactElement

Example

const TOKEN = token();

function appDependencyBinder(container: Container) {
  container.bindValue(TOKEN, 'value');
}

function App() {
  return (
    <DependencyContainer root binder={appDependencyBinder}>
      <NestedComponent />
    </DependencyContainer>
  );
}

Parameters

Name Type
params DependencyContainerParams

Returns

ReactElement

Defined in

DependencyContainer.tsx:68


Hook

Returns a dependency by token, or `undefined` in case the dependency is not provided. Functions

useOptionalDependency

useOptionalDependency<T>(token): T | undefined

Type parameters

Name
T

Parameters

Name Type
token Token<T>

Returns

T | undefined

Defined in

hooks.ts:52


Hook

Returns a dependency by token, or fails with an error. Functions

useDependency

useDependency<T>(token): T

Type parameters

Name
T

Parameters

Name Type
token Token<T>

Returns

T

Defined in

hooks.ts:41


Hook

Returns a dependency container, or `undefined` in case the container is not provided. Functions

useDependencyContainer

useDependencyContainer(mode): Container

Parameters

Name Type
mode "strict"

Returns

Container

Defined in

hooks.ts:10

useDependencyContainer(mode?): Container | undefined

Parameters

Name Type
mode? "optional"

Returns

Container | undefined

Defined in

hooks.ts:16


Hook

Returns a dependency container. Throws an error in case the container is not provided. Functions

useDependencyContainer

useDependencyContainer(mode): Container

Parameters

Name Type
mode "strict"

Returns

Container

Defined in

hooks.ts:10

useDependencyContainer(mode?): Container | undefined

Parameters

Name Type
mode? "optional"

Returns

Container | undefined

Defined in

hooks.ts:16