prepatch
v1.0.0
Published
Dependency free micro framework for dependency injection
Downloads
20
Readme
Dependency free micro framework for dependency injection
Inspired by mitt
const contributors = [
{ name: 'konkonam', url: 'https://github.com/konkonam' },
{ name: 'freb97', url: 'https://github.com/freb97' },
]
Table of Contents
Installation
npm install prepatch
Usage
import prepatch from 'prepatch';
const mitt = mitt()
mitt.on('greet', console.log)
const container = prepatch({
mitt,
audience: 'World',
});
// use your dependencies
const emitter = container.injectMitt(({ mitt, audience }) => {
// write any logic you want in any style...
const sayHello = () => mitt.emit('greet', `Hello ${audience}!`)
return {
sayHello,
}
})
emitter.sayHello()
// Hello World!
// setup with new dependencies
const newEmitter = emitter._context.setup({
...emitter._context.dependencies,
audience: 'Mars',
})
newEmitter.sayHello()
// Hello Mars!