├── .github
└── workflows
│ ├── main.yml
│ └── size.yml
├── .gitignore
├── .npmrc
├── .nvmrc
├── LICENSE
├── README.md
├── example
├── .npmignore
├── index.html
├── index.tsx
├── package.json
└── tsconfig.json
├── jest.config.js
├── package.json
├── setupTests.js
├── src
└── index.tsx
├── test
├── di.test.tsx
└── registry.test.ts
├── tsconfig.json
└── yarn.lock
/.github/workflows/main.yml:
--------------------------------------------------------------------------------
1 | name: CI
2 | on: [push]
3 | jobs:
4 | build:
5 | name: Build, lint, and test on Node ${{ matrix.node }} and ${{ matrix.os }}
6 |
7 | runs-on: ubuntu-latest
8 | strategy:
9 | matrix:
10 | node: ['16.x']
11 |
12 | steps:
13 | - name: Checkout repo
14 | uses: actions/checkout@v2
15 |
16 | - name: Use Node ${{ matrix.node }}
17 | uses: actions/setup-node@v1
18 | with:
19 | node-version: ${{ matrix.node }}
20 |
21 | - name: Install deps and build (with cache)
22 | uses: bahmutov/npm-install@v1
23 |
24 | - name: Lint
25 | run: yarn lint
26 |
27 | - name: Test
28 | run: yarn test --ci --coverage --maxWorkers=2
29 |
30 | - name: Build
31 | run: yarn build
32 |
--------------------------------------------------------------------------------
/.github/workflows/size.yml:
--------------------------------------------------------------------------------
1 | name: size
2 | on: [pull_request]
3 | jobs:
4 | size:
5 | runs-on: ubuntu-latest
6 | env:
7 | CI_JOB_NUMBER: 1
8 | steps:
9 | - uses: actions/checkout@v1
10 | - uses: andresz1/size-limit-action@v1
11 | with:
12 | github_token: ${{ secrets.GITHUB_TOKEN }}
13 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.log
2 | .DS_Store
3 | node_modules
4 | .cache
5 | dist
6 | *.code-workspace
7 |
--------------------------------------------------------------------------------
/.npmrc:
--------------------------------------------------------------------------------
1 | registry=https://registry.npmjs.org
--------------------------------------------------------------------------------
/.nvmrc:
--------------------------------------------------------------------------------
1 | v16.2.0
2 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 Roman
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # EZ-DI
2 |
3 | ## ALPHA VERSION. NOT FOR PRODUCTION USAGE
4 |
5 | Proof of concept tiny dependency injection React library.
6 |
7 | - Small (< 0.5 Kb)
8 | - Easy to use
9 |
10 | ```typescript
11 | // some components in project
12 | const ButtonBase = () =>
13 | const RedButton = () =>
14 |
15 | // import diBlock and DiProvider
16 | import { DiProvider, diBlock } from '@vanilla-wave/ez-di';
17 |
18 | // 1. in target component. Make component swapable
19 | const Button = diBlock('Button')(ButtonBase)
20 |
21 | // 2. Wrap in provider and set desired component in registry
22 | const App = () => (
23 |
( 52 | Component: React.ComponentType
53 | ) => (props: P) => { 54 | const registry = useContext(DiContext) as R; 55 | const ComponentFromRegistry = (registry[ 56 | name 57 | ] as unknown) as React.ComponentType
;
58 |
59 | if (ComponentFromRegistry) {
60 | return