UNPKG

infrastructure-components

Version:

Infrastructure-Components configure the infrastructure of your React-App as part of your React-Components.

86 lines 3.04 kB
"use strict"; /** * Created by frank.zickert on 05.04.19. */ Object.defineProperty(exports, "__esModule", { value: true }); const index_1 = require("./index"); /** * loads the specified configuration into a Javascript object * * @param configFilePath */ function loadConfiguration(configFilePath, infrastructureMode) { return loadConfigurationFromModule(require(configFilePath), infrastructureMode); } exports.loadConfiguration = loadConfiguration; function loadConfigurationFromModule(configModule, infrastructureMode) { return exports.loadInfrastructureComponent(configModule.default, infrastructureMode); } exports.loadConfigurationFromModule = loadConfigurationFromModule; /** * Modes of loading, make sure that during RUNTIME mode, only things are used that exist in webpack- web-mode! * * @type {{COMPILATION: string, RUNTIME: string}} */ exports.INFRASTRUCTURE_MODES = { /** * When packing the application */ COMPILATION: "COMPILATION", /** * when the app actually runs */ RUNTIME: "RUNTIME" }; /** * Loads an InfrastructureComponent (of any type) */ exports.loadInfrastructureComponent = (component, infrastructureMode) => { try { // first load the children! const children = index_1.getChildrenArray(component.props).reduce((result, child) => { return result.concat(exports.loadInfrastructureComponent(child, infrastructureMode)); }, []); //console.log("parseInfrastructureComponent: ", component, children); // overwrite the children in the props const props = Object.assign({}, component.props, { children: children }); // now load the component at hand const params = Object.assign({ infrastructureMode: infrastructureMode, }, props); const result = component.type(params); //console.log("parsed InfrastructureComponent: ", result); if (result.infrastructureType == undefined) { //console.log("not an infrastructure-component: ", result); return exports.loadInfrastructureComponent(result, infrastructureMode); } //console.log("parsed: ", parsed); return result; } catch (error) { console.error("NOT an infrastructure component --> ", error); return undefined; } ; }; /** * Get the searched object from the configuration, if it exists * * This function runs on the compiled/webpacked bundle (Plugins removed!!) * * @param component */ function extractObject(component, infrastructureType, instanceId) { if (component !== undefined && component.infrastructureType === infrastructureType && component.instanceId === instanceId) { return component; } else { return index_1.getChildrenArray(component).reduce((found, child) => found !== undefined ? found : extractObject(child, infrastructureType, instanceId), undefined); } } exports.extractObject = extractObject; //# sourceMappingURL=loader.js.map