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' },
]
npm install prepatch
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!