source: imaps-frontend/node_modules/react-universal-interface/src/createEnhancer.ts

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.2 KB
Line 
1import * as React from 'react';
2import addClassDecoratorSupport from './addClassDecoratorSupport';
3
4const h = React.createElement;
5
6const noWrap = (Comp, propName, props, state) => h(Comp, propName ?
7 {[propName]: state, ...props} :
8 {...state, ...props}
9);
10
11export const divWrapper = (Comp, propName, props, state) =>
12 h('div', null, noWrap(Comp, propName, props, state)) as any;
13
14const createEnhancer = (Facc, prop?: string, wrapper = noWrap) => {
15 const enhancer = (Comp, propName: any = prop, faccProps: object = null) => {
16 const isClassDecoratorMethodCall = typeof Comp === 'string';
17
18 if (isClassDecoratorMethodCall) {
19 return (Klass) => enhancer(Klass, Comp as any || prop, propName as any);
20 }
21
22 const Enhanced = (props) =>
23 h(Facc, faccProps, (state) => wrapper(Comp, propName, props, state));
24
25 if (process.env.NODE_ENV !== 'production') {
26 (Enhanced as any).displayName = `${Facc.displayName || Facc.name}(${Comp.displayName || Comp.name})`;
27 }
28
29 return isClassDecoratorMethodCall ? addClassDecoratorSupport(Enhanced) : Enhanced;
30 };
31
32 return enhancer;
33}
34
35export default createEnhancer;
Note: See TracBrowser for help on using the repository browser.