[d565449] | 1 | import * as React from 'react';
|
---|
| 2 | import addClassDecoratorSupport from './addClassDecoratorSupport';
|
---|
| 3 |
|
---|
| 4 | const h = React.createElement;
|
---|
| 5 |
|
---|
| 6 | const noWrap = (Comp, propName, props, state) => h(Comp, propName ?
|
---|
| 7 | {[propName]: state, ...props} :
|
---|
| 8 | {...state, ...props}
|
---|
| 9 | );
|
---|
| 10 |
|
---|
| 11 | export const divWrapper = (Comp, propName, props, state) =>
|
---|
| 12 | h('div', null, noWrap(Comp, propName, props, state)) as any;
|
---|
| 13 |
|
---|
| 14 | const 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 |
|
---|
| 35 | export default createEnhancer;
|
---|