Skip to content

Commit

Permalink
Release: 3.0.0
Browse files Browse the repository at this point in the history
Merge pull request #12 from vovaspace/development
  • Loading branch information
vovaspace committed May 1, 2021
2 parents a03fa7e + 741bada commit bd395fa
Show file tree
Hide file tree
Showing 76 changed files with 14,761 additions and 29,925 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
15
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ Additionally, we provide builds precompiled to **ESNext** by `esnext`, `esnext:m

The core library.

[![License](https://img.shields.io/badge/license-ISC-blue.svg)](https://github.com/vovaspace/brandi/blob/main/packages/brandi/LICENSE)
[![NPM Version](https://img.shields.io/npm/v/brandi.svg?style=flat)](https://www.npmjs.com/package/brandi)
[![Minzipped Size](https://badgen.net/bundlephobia/minzip/brandi)](https://bundlephobia.com/result?p=brandi)
[![License](https://img.shields.io/npm/l/brandi.svg)](https://github.com/vovaspace/brandi/blob/main/packages/brandi/LICENSE)
[![NPM Version](https://img.shields.io/npm/v/brandi.svg)](https://www.npmjs.com/package/brandi)
[![Minzipped Size](https://img.shields.io/bundlephobia/minzip/brandi.svg)](https://bundlephobia.com/result?p=brandi)

```bash
# NPM
Expand All @@ -39,9 +39,9 @@ yarn add brandi

The React bindings layer. It lets your React components get dependencies from Brandi containers.

[![License](https://img.shields.io/badge/license-ISC-blue.svg)](https://github.com/vovaspace/brandi/blob/main/packages/brandi-react/LICENSE)
[![NPM Version](https://img.shields.io/npm/v/brandi-react.svg?style=flat)](https://www.npmjs.com/package/brandi-react)
[![Minzipped Size](https://badgen.net/bundlephobia/minzip/brandi-react)](https://bundlephobia.com/result?p=brandi-react)
[![License](https://img.shields.io/npm/l/brandi-react.svg)](https://github.com/vovaspace/brandi/blob/main/packages/brandi-react/LICENSE)
[![NPM Version](https://img.shields.io/npm/v/brandi-react.svg)](https://www.npmjs.com/package/brandi-react)
[![Minzipped Size](https://img.shields.io/bundlephobia/minzip/brandi-react.svg)](https://bundlephobia.com/result?p=brandi-react)

Brandi-React requires **React 16.8 or later**.
You'll also need to [install](https://brandi.js.org/getting-started/installation) Brandi.
Expand Down Expand Up @@ -81,10 +81,11 @@ The documentation is divided into several sections:
- Reference
- [API Reference](https://brandi.js.org/reference)
- [Pointers and Registrators](https://brandi.js.org/reference/pointers-and-registrators)
- [Container API](https://brandi.js.org/reference/container-api)
- [Container](https://brandi.js.org/reference/container)
- [Binding Types](https://brandi.js.org/reference/binding-types)
- [Binding Scopes](https://brandi.js.org/reference/binding-scopes)
- [Optional Dependencies](https://brandi.js.org/reference/optional-dependencies)
- [Dependency Modules](https://brandi.js.org/reference/dependency-modules)
- [Hierarchical Containers](https://brandi.js.org/reference/hierarchical-containers)
- [Conditional Bindings](https://brandi.js.org/reference/conditional-bindings)
- Brandi-React
Expand Down Expand Up @@ -169,7 +170,7 @@ expect(originalKey).toBe('#key9428');
<!-- prettier-ignore-end -->

Other `Container` methods are detailed
in [Container API](https://brandi.js.org/reference/container-api) section of the documentation.
in [Container](https://brandi.js.org/reference/container) section of the documentation.

### Hierarchical Containers

Expand All @@ -193,7 +194,7 @@ parentContainer
.inTransientScope();

/* ↓ Creates a container with the parent. */
const childContainer = new Container(parentContainer);
const childContainer = new Container().extend(parentContainer);

/** ↓ That container can't satisfy the getting request,
* it passes it along to its parent container.
Expand Down
24 changes: 12 additions & 12 deletions docs/brandi-react/container-provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ hide_title: true

The `ContainerProvider` component makes the Brandi container available to any nested components that need to use injections.

The [`useInjection`](./use-injection.md) hook can then access the provided container via React's Context mechanism.
The [`useInjection`](./use-injection.md) hook can then access the provided container via React's Context.

## Props

1. `container`: [`Container`](../reference/container-api.md#container) — the provider will not pass the orginal container,
but its clone received from the [`Container.clone()`](../reference/container-api.md#clone) method
(This can be useful together with using the [container scope](../reference/binding-scopes.md#incontainerscope)).
This behavior is implemented so that the provider can safely set the container
received from the upstream provider to the `Container.parent`.
In this way, we can implement a [hierarchical DI system](../reference/hierarchical-containers.md)
based on a hierarchy of React components.
2. `isolated?`: `boolean` — as mentioned above, the provider sets the container
received from the upstream provider to the `Container.parent`.
`isolated` prop disables this behavior and saves original `Container.parent` value.
3. `children`: `ReactNode`.
- `container`: [`Container`](../reference/container.md#container) — the provider will not pass the orginal container,
but its clone received from the [`Container.clone()`](../reference/container.md#clone) method
(This can be useful together with using the [container scope](../reference/binding-scopes.md#incontainerscope)).
This behavior is implemented so that the provider can safely [extends](../reference/container#extendcontainer) the container
with a container received from the upstream provider.
In this way, we can implement a [hierarchical DI system](../reference/hierarchical-containers.md)
based on a hierarchy of React components.
- `[isolated]`: `boolean` — as mentioned above, the provider extends the container
with a container received from the upstream provider.
`isolated` prop disables this behavior.
- `children`: `ReactNode`.

## Examples

Expand Down
2 changes: 1 addition & 1 deletion docs/brandi-react/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ Additionally, we provide builds precompiled to **ESNext** by `esnext`, `esnext:m
makes the Brandi container available to any nested components that need to use injections.
- [`useInjection(token)`](./use-injection.md) — allows you to get a dependency from a container.
- [`createInjectionHooks(...tokens)`](./create-injection-hooks.md) — creates hooks for getting dependencies more easily.
- [`tagged(...tags)(Component, [isolated])`](./tagged.md) — attaches tags to the component and all nested components.
- [`tagged(...tags)(Component, [options])`](./tagged.md) — attaches tags to the component and all nested components.
7 changes: 4 additions & 3 deletions docs/brandi-react/tagged.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ hide_title: true

# `tagged`

The `tagged(...tags)(Component, [isolated])` HoC attaches tags to the component and its child components.
The `tagged(...tags)(Component, [options])` HoC attaches tags to the component and its child components.

Conditional Bindings are detailed
in [Conditional Bindings](../reference/conditional-bindings.md) section of the documentation.
Expand All @@ -21,8 +21,9 @@ in [Conditional Bindings](../reference/conditional-bindings.md) section of the d
### tagged(...tags)(Component, [isolated])

1. `Component`: `React.ComponentType` — component to be wrapped.
2. `isolated?`: `boolean` — by default, the wrapped component and its child components inherit tags
from from the upstream tagged components. You can use `isolated` option to disable this behavior.
2. `[options]`: `TaggedOptions`
- `isolated`: `boolean` — by default, the wrapped component and its child components inherit tags
from from the upstream tagged components. You can use `isolated` option to disable this behavior.

## Returns

Expand Down
4 changes: 2 additions & 2 deletions docs/examples/basic-examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ expect(originalKey).toBe('#key9428');
<!-- prettier-ignore-end -->

Other `Container` methods are detailed
in [Container API](../reference/container-api.md) section of the documentation.
in [Container](../reference/container.md) section of the documentation.

## Hierarchical Containers

Expand All @@ -98,7 +98,7 @@ parentContainer
.inTransientScope();

/* ↓ Creates a container with the parent. */
const childContainer = new Container(parentContainer);
const childContainer = new Container().extend(parentContainer);

/** ↓ That container can't satisfy the getting request,
* it passes it along to its parent container.
Expand Down
42 changes: 21 additions & 21 deletions docs/reference/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,32 @@ This section documents the complete Brandi API.

## Container

- [`Container`](./container-api.md)
- [`createContainer`](./container-api.md#createcontainerparent)
- [`Container`](./container.md)
- [`createContainer()`](./container.md#createcontainer)

### Container Methods
### `Container` Methods

- [`bind(token)`](./container-api.md#bindtoken)
- [`bind(token)`](./container.md#bindtoken)
- [`toConstant(value)`](./binding-types.md#toconstantvalue)
- [`toInstance(ctor)`](./binding-types.md#toinstancector)
- [`toFactory(creator, [initializer])`](./binding-types.md#tofactorycreator-initializer)
- [`toInstance(creator)`](./binding-types.md#toinstancecreator)
- [`inContainerScope()`](./binding-scopes.md#incontainerscope)
- [`inGlobalScope()`](./binding-scopes.md#inglobalscope)
- [`inResolutionScope()`](./binding-scopes.md#inresolutionscope)
- [`inSingletonScope()`](./binding-scopes.md#insingletonscope)
- [`inTransientScope()`](./binding-scopes.md#intransientscope)
- [`toCall(func)`](./binding-types.md#tocallfunc)
- [`inContainerScope()`](./binding-scopes.md#incontainerscope)
- [`inGlobalScope()`](./binding-scopes.md#inglobalscope)
- [`inResolutionScope()`](./binding-scopes.md#inresolutionscope)
- [`inSingletonScope()`](./binding-scopes.md#insingletonscope)
- [`inTransientScope()`](./binding-scopes.md#intransientscope)
- [`toFactory(ctor, [initializer])`](./binding-types.md#tofactoryctor-initializer)
- [`toCreator(func, [initializer])`](./binding-types.md#tocreatorfunc-initializer)
- [`capture()`](./container-api.md#capture)
- [`clone()`](./container-api.md#clone)
- [`get(token)`](./container-api.md#gettoken)
- [`restore()`](./container-api.md#restore)
- [`when(condition)`](./container-api.md#whencondition)
- [`capture()`](./container.md#capture)
- [`clone()`](./container.md#clone)
- [`extend(container)`](./container.md#extendcontainer)
- [`get(token)`](./container.md#gettoken)
- [`restore()`](./container.md#restore)
- [`use(...tokens)`](./container.md#usetokensfrommodule)
- [`from(module)`](./container.md#usetokensfrommodule)
- [`when(condition)`](./container.md#whencondition)

## Dependency Modules

- [`DependencyModule`](./dependency-modules.md)
- [`createDependencyModule()`](./dependency-modules.md#createdependencymodule)

## Pointers

Expand All @@ -45,5 +45,5 @@ This section documents the complete Brandi API.

## Registrators

- [`injected(target, ...tokens)`](./pointers-and-registrators.md#injectedtargettokens)
- [`tagged(target, ...tags)`](./pointers-and-registrators.md#taggedtargettags)
- [`injected(target, ...tokens)`](./pointers-and-registrators.md#injectedtarget-tokens)
- [`tagged(target, ...tags)`](./pointers-and-registrators.md#taggedtarget-tags)
42 changes: 1 addition & 41 deletions docs/reference/binding-scopes.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ expect(apiServiceFirst).not.toBe(apiServiceSecond);

The container will return the same instance with each getting.
This is similar to being a singleton,
however if the container has a [child container](./hierarchical-containers.md) or a [clone](./container-api#clone),
however if the container has a [child container](./hierarchical-containers.md) or a [clone](./container#clone),
that child container or clone will get an instance unique to it.

#### Example
Expand Down Expand Up @@ -126,43 +126,3 @@ const userService = container.get(TOKENS.userService);
/* `EmailService` instances are the same for this resolution chain. */
expect(userService.emailService).toBe(userService.settingsService.emailService);
```

---

## `inGlobalScope()`

Each getting from any container will return the same instance.

#### Example

<!-- prettier-ignore-start -->
```typescript
const parentContainer = new Container();
const childContainer = new Container(parentContainer);
const independentContainer = new Container();

parentContainer
.bind(TOKENS.apiService)
.toInstance(ApiService)
.inGlobalScope();

childContainer
.bind(TOKENS.apiService)
.toInstance(ApiService)
.inGlobalScope();

independentContainer
.bind(TOKENS.apiService)
.toInstance(ApiService)
.inGlobalScope();

const apiServiceParent = parentContainer.get(TOKENS.apiService);
const apiServiceChild = childContainer.get(TOKENS.apiService);
const apiServiceIndependent = independentContainer.get(TOKENS.apiService);

/* The instances are the same. */
expect(apiServiceParent).toBe(apiServiceChild);
expect(apiServiceParent).toBe(apiServiceIndependent);
expect(apiServiceChild).toBe(apiServiceIndependent);
```
<!-- prettier-ignore-end -->
Loading

1 comment on commit bd395fa

@vercel
Copy link

@vercel vercel bot commented on bd395fa May 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.