UNPKG

@macrof/shared

Version:

React MicroFrontend Shared, Typescript, Webpack 5, ModuleFederation

44 lines (43 loc) 1.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EmployeeStore = void 0; const AFactoryStore_1 = require("./factory/AFactoryStore"); class EmployeeStore extends AFactoryStore_1.AFactoryStore { constructor(rootContainer) { super(); this.initialStores = []; this.usedStores = {}; this.rootContainer = rootContainer; this.container = AFactoryStore_1.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_1.AFactoryStore.appContainerFactory(this.rootContainer); this.collect({ reBuild: true }); } init() { return this.usedStores; } } exports.EmployeeStore = EmployeeStore;