diesis-electrician
v2.0.0
Published
Adapter to use electrician components in diesis
Downloads
12
Maintainers
Readme
diesis-electrician
This is an adapter for using electrician components with Diesis.
How it works
You import the adapter like this:
const diesisElectrician = require('diesis-electrician')
Then you pass a map of electric components:
const deps = diesisElectrician(components)
You get back an object with startAll/stopAll methods:
const deps = diesisElectrician({
config: new Conflab(),
endpoints: new Endpoints(),
metrics: new ElectricMetrics(),
refdata: new Refdata(),
server: new Server(),
})
deps.startAll() // ... starts all components
.then(obj => {
// obj is a map with all components
})
deps.stopAll() // ... stops all components
.then(() => {
})
Every dependency not declared in the components is intended as additional argument that can be sent in the startAll/stopAll method:
deps.startAll({ value: 5 })
startAll/stopAll are convenience methods build on top of run
:
run([config, endpoints, metrics, refdata, server], { value: 5 })
deps contains also 2 registries (startRegistry and stopRegistry) with all dependencies that you can export and use:
const getConfig = deps.startRegistry.config
const getRefdata = deps.startRegistry.refdata
const { dependency } = require('diesis')
const doSomething = dependency([getConfig, getRefdata], (config, refdata) => {
// ...
})
If you want get the same API of electrician you can call getSystem:
const system = deps.getSystem(obj) // you inject some argument if required
system.start((err) => {
// ...
})
system.stop((err) => {
// ...
})