1 import * as React from 'react';
2 import applicationService from '../services/applicationManager';
3 export type WithComponents<T extends { [name: string]: string }> = {
4 components: { [prop in keyof T]: React.ComponentType }
7 export function withComponents<TProps,TMap extends { [name: string]: string }>(mapping: TMap) {
8 return (component: React.ComponentType<TProps & WithComponents<TMap>>): React.ComponentType<TProps> => {
9 const components = {} as any;
10 Object.keys(mapping).forEach(name => {
11 const [appKey, componentKey] = mapping[name].split('.');
12 const reg = applicationService.applications[appKey];
13 components[name] = reg && reg.exportedComponents && reg.exportedComponents[componentKey] || (() => null);
15 return (props: TProps) => (
16 React.createElement(component, Object.assign({ components }, props))
20 export default withComponents;