npm.io
1.0.0 • Published 9 months ago

async-didi

Licence
MIT
Version
1.0.0
Deps
1
Size
28 kB
Vulns
0
Weekly
0

async-didi

Build Status

An async version of didi, the tiny inversion of control container for JavaScript.

Example

import {
  AsyncInjector
} from 'async-didi';

function Car(engine) {
  this.start = function() {
    return engine.start();
  };
}

async function createEngine(power) {
  return {
    async start() {
      console.log('Starting engine with ' + power + 'hp');
    }
  };
}

const injector = new AsyncInjector([
  {
    'car': ['type', Car],
    'engine': ['factory', createEngine],
    'power': ['value', 1184]
  }
]);

await injector.invoke(async function(car) {
  await car.start();
});

For more examples, check out the tests.

Usage

Refer to didi documentation and enjoy the ability to define async factory functions and module initializers.

See also comparison.

Comparison to didi

  • Same core features
  • Exposes an AsyncInjector
  • Injector API functions get, invoke and instantiate are async
  • Factory functions may be async
  • No support for child injectors and scopes

License

MIT

Keywords