oly
v1.1.0
Published
Dependency injection, store and event emitter in one place.
Downloads
47
Readme
oly
Dependency injection, store and event emitter in one place.
oly is a module of the oly project.
import { Kernel } from "oly";
Kernel
.create(/* store */)
.with(/* services & providers */)
.start()
.catch(console.error)
Installation
$ npm install oly
Features
Injections
import { inject, Kernel } from "oly";
class A { text = "A" }
class B { text = "B" }
class C { @inject a: A }
Kernel
.create()
.with({provide: A, use: B})
.get(C).a.text // B
Events
import { Kernel, on } from "oly";
class App {
@on say = msg => console.log(msg)
}
Kernel
.create()
.with(App)
.emit("App.say", "hello"); // hello
States
import { Kernel } from "oly";
Kernel
.create({A: "B"})
.on("oly:state:mutate", console.log)
.kernel
.state("A", "C"); // { key: 'A', newValue: 'C', oldValue: 'B' }