UNPKG

@macrof/shared

Version:

React MicroFrontend Shared, Typescript, Webpack 5, ModuleFederation

40 lines (39 loc) 1.19 kB
import { AFactoryStore } from "./factory/AFactoryStore"; export class EmployeeStore extends AFactoryStore { constructor(rootContainer) { super(); this.initialStores = []; this.usedStores = {}; this.rootContainer = rootContainer; this.container = AFactoryStore.appContainerFactory(this.rootContainer); } set callableFC(callback) { try { this.usedStores = Object.assign(Object.assign({}, this.usedStores), callback(this.container)); } catch (e) { console.error(e); } } collect({ provider, reBuild }) { if (reBuild) { Object.entries(this.initialStores) .forEach(([, callback]) => { this.callableFC = callback; }); } else if (provider) { this.callableFC = provider; } } inject(provider) { this.initialStores.push(provider); this.collect({ provider }); } reBuild() { this.usedStores = {}; this.container = AFactoryStore.appContainerFactory(this.rootContainer); this.collect({ reBuild: true }); } init() { return this.usedStores; } }