@produck/kit
Advanced tools
Comparing version 0.0.3 to 0.1.0
@@ -23,2 +23,5 @@ interface KitProvider { | ||
/** | ||
* Any new `Kit` MUST be created by the `global Kit`. | ||
*/ | ||
export const global: GlobalKit; |
{ | ||
"name": "@produck/kit", | ||
"version": "0.0.3", | ||
"version": "0.1.0", | ||
"description": "A useful dependency injection module.", | ||
@@ -53,3 +53,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "d91b66b1ca6af10c48108210a37cc0cec5a45f3d" | ||
"gitHead": "555d9a6f12dc04c988b17b211ead3b8652979dae" | ||
} |
@@ -5,14 +5,71 @@ # @produck/kit | ||
[![npm (scoped)](https://img.shields.io/npm/v/@produck/kit)](https://www.npmjs.com/package/@produck/kit) | ||
[![npm](https://img.shields.io/npm/dw/@produck/koa-forker)](https://www.npmjs.com/package/@produck/kit) | ||
[![npm](https://img.shields.io/npm/dw/@produck/kit)](https://www.npmjs.com/package/@produck/kit) | ||
[![lerna](https://img.shields.io/badge/maintained%20with-lerna-cc00ff.svg?style=flat-square)](https://lerna.js.org/) | ||
[![NPM](https://img.shields.io/npm/l/@produck/kit)](https://opensource.org/licenses/MIT) | ||
> TODO: description | ||
A module to create a injection for implemention of DI, IoC. It can easily build injection prototype chain. Each injection represents a job space, a problem scope. Child injection can access dependencis of its prototype injection. | ||
It has been published as a "[Dual CommonJS/ES module](https://nodejs.org/dist/latest-v16.x/docs/api/packages.html#dual-commonjses-module-packages)" package but ESM first. It can work in "node.js" and browsers. It is also very friendly with "tree shaking", using "[Rollup](https://rollupjs.org/guide/en/)". | ||
A Kit, the injection is ``IMMUTABLE``. | ||
## Installation | ||
``` | ||
$ npm install @produck/kit | ||
``` | ||
## Usage | ||
### Import / require | ||
As esModule, | ||
```js | ||
import * as Kit from '@produck/kit'; | ||
``` | ||
As CommonJs, | ||
```js | ||
const Kit = require('@produck/kit'); | ||
``` | ||
### Prepare / Inject / Spread | ||
The chain is like ``[Child] --|> [Base] --|> [Global]``. | ||
* Inject ``[Child]`` to ``FooProvider()``. | ||
* Inject ``[Base]`` to ``BarProvider()``. | ||
```js | ||
import * as Kit from '@produck/kit'; | ||
function BarProvider(Kit) { | ||
console.log(Kit.Kit); // => Child Kit | ||
console.log(Kit.version); // => @produck/kit version | ||
console.log(Kit.foo); // => 'bar' | ||
console.log(Kit.baz); // => 'qux' | ||
} | ||
function FooProvider({ Kit, version, foo }) { | ||
// Spread | ||
console.log(version); // => @produck/kit version. | ||
console.log(foo); // => 'bar' | ||
// Create a child Kit by `Base Kit` | ||
const child = Kit('Child'); | ||
child.baz = 'qux'; | ||
// Inject | ||
BarProvider(child); | ||
} | ||
// Prepare | ||
const base = Kit.global('Base'); | ||
base.foo = 'bar'; | ||
// Inject | ||
AnyProvider(base); | ||
``` | ||
const kit = require('@produck/kit'); | ||
## API | ||
### .global | ||
// TODO: DEMONSTRATE API | ||
``` | ||
### .global.version | ||
### .Kit([name: string]): Kit | ||
## License | ||
[MIT](https://github.com/produck/kit/blob/main/LICENSE) |
Sorry, the diff of this file is not supported yet
7106
78
74