0.1.7 • Published 4 months ago

@produck/kit v0.1.7

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

@produck/kit

GitHub Workflow Status Coveralls npm (scoped) npm lerna NPM

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" package but ESM first. It can work in "node.js" and browsers. It is also very friendly with "tree shaking", using "Rollup".

A Kit, the injection is IMMUTABLE.

Installation

$ npm install @produck/kit

Usage

Import / require

As esModule,

import * as Kit from '@produck/kit';

As CommonJs,

const Kit = require('@produck/kit');

Prepare / Inject / Spread

The chain is like [Child] --|> [Base] --|> [Global].

  • Inject [Child] to FooProvider().
  • Inject [Base] to BarProvider().
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
FooProvider(base);

API

.global

.global.version

.Kit(name: string): Kit

License

MIT

0.1.7

4 months ago

0.1.6

4 months ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.3

2 years ago

0.0.1

2 years ago