UNPKG

@macrof/shared

Version:

React MicroFrontend Shared, Typescript, Webpack 5, ModuleFederation

40 lines (39 loc) 1.57 kB
import { Container } from 'inversify'; import { Common, Service, ProductionDebug, Production, Response, Token, LoaderService, IS_DEV, MF_TYPES, } from '../../..'; import { AFactoryStore } from './AFactoryStore'; export class FactoryStore extends AFactoryStore { constructor() { super(...arguments); this.rootContainerFactory = () => { const container = this.createParentDev(); container.parent = new Container(); return container; }; } createParentDev() { const container = new Container(); if (IS_DEV) { container.bind(MF_TYPES.ILogger).to(Common); } else { const { location } = window; const isDebugMode = Boolean(new URLSearchParams(location.search).get('DEBUG')); container .bind(MF_TYPES.ILogger) .to(Production) .when(() => !isDebugMode); container .bind(MF_TYPES.ILogger) .to(ProductionDebug) .when(() => isDebugMode); } container.bind(MF_TYPES.IResponseService).to(Response); container.bind(MF_TYPES.Token).toConstantValue(new Token()); container.bind(MF_TYPES.ILoader).to(LoaderService).inSingletonScope(); container .bind(MF_TYPES.IHttpService) .toDynamicValue((context) => new Service(context.container.get(MF_TYPES.ILogger), context.container.get(MF_TYPES.Token))) .inSingletonScope(); return container; } }