UNPKG

reactant-di

Version:

A dependency injection lib for Reactant

31 lines (28 loc) 1.35 kB
import { __assign } from '../node_modules/tslib/tslib.es6.js'; function lookupServiceIdentifiers(request, ServiceIdentifiers) { // It is used to perform the required dependency collection when dynamically importing modules. if (!ServiceIdentifiers.has(request.serviceIdentifier)) { ServiceIdentifiers.set(request.serviceIdentifier, []); } var depServiceIdentifier = request.childRequests.map(function (childRequest) { return childRequest.serviceIdentifier; }); ServiceIdentifiers.set(request.serviceIdentifier, depServiceIdentifier); if (request.childRequests.length === 0) return; request.childRequests.forEach(function (childRequest) { lookupServiceIdentifiers(childRequest, ServiceIdentifiers); }); } function createCollector(ServiceIdentifiers) { return function (planAndResolve) { return function (args) { var nextContextInterceptor = args.contextInterceptor; var contextInterceptor = function (context) { lookupServiceIdentifiers(context.plan.rootRequest, ServiceIdentifiers); return nextContextInterceptor(context); }; var result = planAndResolve(__assign(__assign({}, args), { contextInterceptor: contextInterceptor })); return result; }; }; } export { createCollector };