di-tory
Version:
Compose applications with dependency injection
23 lines (22 loc) • 515 B
JavaScript
const diAsyncStore = new WeakMap();
let asyncScopeApi = {
enter() { },
run: (fn) => fn(),
getStore: () => diAsyncStore,
exit() { },
};
export const init = (api) => {
asyncScopeApi = api;
asyncScopeApi.enter();
};
export const enter = () => asyncScopeApi.enter();
export const run = (fn) => asyncScopeApi.run(fn);
export const getStore = () => asyncScopeApi.getStore();
export const exit = () => asyncScopeApi.exit();
export default {
init,
enter,
run,
getStore,
exit,
};