Skip to content

Dependency free micro framework for dependency injection

License

Notifications You must be signed in to change notification settings

konkonam/prepatch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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!

About

Dependency free micro framework for dependency injection

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published