@semcore/core 1.11.7 → 1.11.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/README.md +69 -0
- package/lib/cjs/Component.js.map +1 -1
- package/lib/cjs/enhancement/Children.js +1 -1
- package/lib/cjs/enhancement/Children.js.map +1 -1
- package/lib/cjs/enhancement/Root.js +2 -2
- package/lib/cjs/enhancement/Root.js.map +1 -1
- package/lib/cjs/enhancement/bindHandler.js.map +1 -1
- package/lib/cjs/enhancement/dataName.js.map +1 -1
- package/lib/cjs/enhancement/enhance.js.map +1 -1
- package/lib/cjs/enhancement/functionDefaultProps.js.map +1 -1
- package/lib/cjs/enhancement/hoistProps.js +3 -3
- package/lib/cjs/enhancement/hoistProps.js.map +1 -1
- package/lib/cjs/enhancement/inheritedName.js.map +1 -1
- package/lib/cjs/enhancement/staticChildren.js.map +1 -1
- package/lib/cjs/enhancement/style.js +1 -1
- package/lib/cjs/enhancement/style.js.map +1 -1
- package/lib/cjs/enhancement/uncontrolledProps.js +2 -2
- package/lib/cjs/enhancement/uncontrolledProps.js.map +1 -1
- package/lib/cjs/index.js +4 -4
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/register.js.map +1 -1
- package/lib/cjs/styled/index.js.map +1 -1
- package/lib/cjs/styled/sstyled.js +4 -2
- package/lib/cjs/styled/sstyled.js.map +1 -1
- package/lib/es6/Component.js.map +1 -1
- package/lib/es6/enhancement/Children.js +1 -1
- package/lib/es6/enhancement/Children.js.map +1 -1
- package/lib/es6/enhancement/Root.js +2 -2
- package/lib/es6/enhancement/Root.js.map +1 -1
- package/lib/es6/enhancement/bindHandler.js.map +1 -1
- package/lib/es6/enhancement/dataName.js.map +1 -1
- package/lib/es6/enhancement/enhance.js.map +1 -1
- package/lib/es6/enhancement/functionDefaultProps.js.map +1 -1
- package/lib/es6/enhancement/hoistProps.js +3 -3
- package/lib/es6/enhancement/hoistProps.js.map +1 -1
- package/lib/es6/enhancement/inheritedName.js.map +1 -1
- package/lib/es6/enhancement/staticChildren.js.map +1 -1
- package/lib/es6/enhancement/style.js +1 -1
- package/lib/es6/enhancement/style.js.map +1 -1
- package/lib/es6/enhancement/uncontrolledProps.js +2 -2
- package/lib/es6/enhancement/uncontrolledProps.js.map +1 -1
- package/lib/es6/index.js +4 -4
- package/lib/es6/index.js.map +1 -1
- package/lib/es6/register.js.map +1 -1
- package/lib/es6/styled/index.js.map +1 -1
- package/lib/es6/styled/sstyled.js +4 -2
- package/lib/es6/styled/sstyled.js.map +1 -1
- package/package.json +3 -3
- package/src/Component.tsx +0 -108
- package/src/enhancement/Children.tsx +0 -103
- package/src/enhancement/Root.tsx +0 -78
- package/src/enhancement/bindHandler.tsx +0 -45
- package/src/enhancement/dataName.tsx +0 -12
- package/src/enhancement/enhance.tsx +0 -12
- package/src/enhancement/functionDefaultProps.tsx +0 -29
- package/src/enhancement/hoistProps.tsx +0 -88
- package/src/enhancement/inheritedName.tsx +0 -18
- package/src/enhancement/staticChildren.tsx +0 -128
- package/src/enhancement/style.tsx +0 -47
- package/src/enhancement/uncontrolledProps.tsx +0 -134
- package/src/index.tsx +0 -381
- package/src/register.tsx +0 -18
- package/src/styled/index.tsx +0 -9
- package/src/styled/sstyled.tsx +0 -150
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
function Enhancement() {
|
|
2
|
-
return {
|
|
3
|
-
condition: function (Component) {
|
|
4
|
-
return Boolean(Component.enhance && Component.enhance.length);
|
|
5
|
-
},
|
|
6
|
-
wrapperProps: function (props, WrapperComponent) {
|
|
7
|
-
return WrapperComponent.enhance.reduce((acc, enhance) => enhance(acc), props);
|
|
8
|
-
},
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export default Enhancement;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
function Enhancement() {
|
|
2
|
-
let defaultProps = {};
|
|
3
|
-
return {
|
|
4
|
-
condition: function (Component) {
|
|
5
|
-
if (!Component.defaultProps) {
|
|
6
|
-
return false;
|
|
7
|
-
}
|
|
8
|
-
if (typeof Component.defaultProps === 'function') {
|
|
9
|
-
return true;
|
|
10
|
-
}
|
|
11
|
-
return Boolean(Object.keys(Component.defaultProps).length);
|
|
12
|
-
},
|
|
13
|
-
static: function (WrapperComponent) {
|
|
14
|
-
defaultProps = WrapperComponent.defaultProps;
|
|
15
|
-
return {
|
|
16
|
-
defaultProps: {},
|
|
17
|
-
};
|
|
18
|
-
},
|
|
19
|
-
wrapperProps: function (props) {
|
|
20
|
-
if (typeof defaultProps === 'function') {
|
|
21
|
-
// TODO: optimization
|
|
22
|
-
return Object.assign({}, defaultProps(props), props);
|
|
23
|
-
}
|
|
24
|
-
return Object.assign({}, defaultProps, props);
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export default Enhancement;
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { useContext, useState } from 'react';
|
|
2
|
-
// @ts-ignore
|
|
3
|
-
import assignProps from '@semcore/utils/lib/assignProps';
|
|
4
|
-
// @ts-ignore
|
|
5
|
-
import useEnhancedEffect from '@semcore/utils/lib/use/useEnhancedEffect';
|
|
6
|
-
// @ts-ignore
|
|
7
|
-
import pick from '@semcore/utils/lib/pick';
|
|
8
|
-
|
|
9
|
-
export const HOIST_CONTEXT = Symbol('HOIST_CONTEXT');
|
|
10
|
-
const HOIST_SELF = Symbol('HOIST_SELF');
|
|
11
|
-
const HOIST_SET = Symbol('HOIST_SET');
|
|
12
|
-
|
|
13
|
-
function flatChildComponent(childComponents) {
|
|
14
|
-
return Object.values(childComponents).reduce<unknown[]>((acc, Component) => {
|
|
15
|
-
if (Array.isArray(Component)) {
|
|
16
|
-
acc = [...acc, Component[0], ...flatChildComponent(Component[1])];
|
|
17
|
-
} else {
|
|
18
|
-
acc.push(Component);
|
|
19
|
-
}
|
|
20
|
-
return acc;
|
|
21
|
-
}, []);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function Enhancement(childComponents, Context) {
|
|
25
|
-
return {
|
|
26
|
-
condition: function (Component) {
|
|
27
|
-
return [Component, ...flatChildComponent(childComponents)].some((Component) =>
|
|
28
|
-
Boolean(Component.hoistProps && Component.hoistProps.length),
|
|
29
|
-
);
|
|
30
|
-
},
|
|
31
|
-
init: function (props, WrapperComponent, isFunction) {
|
|
32
|
-
if (isFunction) {
|
|
33
|
-
// TODO: use может вызываться не ровное количество раз
|
|
34
|
-
this[HOIST_SELF] = useState({});
|
|
35
|
-
} else {
|
|
36
|
-
this[HOIST_SELF] = [
|
|
37
|
-
{},
|
|
38
|
-
(obj) => {
|
|
39
|
-
this[HOIST_SELF][0] = obj;
|
|
40
|
-
this.forceUpdate();
|
|
41
|
-
},
|
|
42
|
-
];
|
|
43
|
-
}
|
|
44
|
-
// For optimization render
|
|
45
|
-
this[HOIST_SET] = (obj) => {
|
|
46
|
-
this[HOIST_SELF][1](obj);
|
|
47
|
-
};
|
|
48
|
-
},
|
|
49
|
-
context: function (context) {
|
|
50
|
-
// TODO: оптимизировать создание контекста
|
|
51
|
-
// WrapperComponent.hoistProps
|
|
52
|
-
return {
|
|
53
|
-
...context,
|
|
54
|
-
[HOIST_CONTEXT]: this[HOIST_SET],
|
|
55
|
-
};
|
|
56
|
-
},
|
|
57
|
-
asProps: function (props) {
|
|
58
|
-
// TODO добавить проверку на уникальность филда на руте
|
|
59
|
-
return assignProps(this[HOIST_SELF][0], props);
|
|
60
|
-
},
|
|
61
|
-
wrapperProps: function (props, WrapperComponent) {
|
|
62
|
-
if (WrapperComponent.hoistProps && WrapperComponent.hoistProps.length) {
|
|
63
|
-
const context = useContext(Context);
|
|
64
|
-
const renameProps = WrapperComponent.hoistProps.reduce((acc, propName) => {
|
|
65
|
-
const [name, rename] = propName.split(':');
|
|
66
|
-
acc[name] = rename || name;
|
|
67
|
-
return acc;
|
|
68
|
-
}, {});
|
|
69
|
-
const hoistProps = Object.entries(pick(props, Object.keys(renameProps))).reduce(
|
|
70
|
-
(acc, [name, value]) => {
|
|
71
|
-
acc[renameProps[name]] = value;
|
|
72
|
-
return acc;
|
|
73
|
-
},
|
|
74
|
-
{},
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
useEnhancedEffect(() => {
|
|
78
|
-
if (context[HOIST_CONTEXT]) {
|
|
79
|
-
context[HOIST_CONTEXT](hoistProps);
|
|
80
|
-
}
|
|
81
|
-
}, Object.values(hoistProps));
|
|
82
|
-
}
|
|
83
|
-
return props;
|
|
84
|
-
},
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export default Enhancement;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export const INHERITED_NAME = Symbol('INHERITED_NAME');
|
|
2
|
-
|
|
3
|
-
function Enhancement() {
|
|
4
|
-
return {
|
|
5
|
-
condition: function (Component) {
|
|
6
|
-
return Boolean(Component.displayName);
|
|
7
|
-
},
|
|
8
|
-
static: function (WrapperComponent) {
|
|
9
|
-
return {
|
|
10
|
-
[INHERITED_NAME]: [
|
|
11
|
-
...new Set([...(WrapperComponent[INHERITED_NAME] || []), WrapperComponent.displayName]),
|
|
12
|
-
],
|
|
13
|
-
};
|
|
14
|
-
},
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export default Enhancement;
|
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import { useContext } from 'react';
|
|
2
|
-
// @ts-ignore
|
|
3
|
-
import assignProps from '@semcore/utils/lib/assignProps';
|
|
4
|
-
// @ts-ignore
|
|
5
|
-
import pick from '@semcore/utils/lib/pick';
|
|
6
|
-
// @ts-ignore
|
|
7
|
-
import logger from '@semcore/utils/lib/logger';
|
|
8
|
-
|
|
9
|
-
function assign(target, source) {
|
|
10
|
-
return Object.defineProperties(
|
|
11
|
-
target,
|
|
12
|
-
Object.keys(source).reduce((descriptors, key) => {
|
|
13
|
-
descriptors[key] = Object.getOwnPropertyDescriptor(source, key);
|
|
14
|
-
return descriptors;
|
|
15
|
-
}, {}),
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function getterMethodName(name) {
|
|
20
|
-
return `get${name}Props`;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function getterMethodNameByDisplayName(displayName) {
|
|
24
|
-
const displayNames = displayName.split('.');
|
|
25
|
-
const name = displayNames.slice(-(displayNames.length - 1)).join('');
|
|
26
|
-
return getterMethodName(name);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function flatGetterMethodNames(childComponents, parentName?: string) {
|
|
30
|
-
return Object.entries(childComponents).reduce<string[]>((acc, [name, value]) => {
|
|
31
|
-
if (Array.isArray(value)) {
|
|
32
|
-
acc = [...acc, ...flatGetterMethodNames(value[1], name)];
|
|
33
|
-
}
|
|
34
|
-
name = parentName ? `${parentName}${name}` : name;
|
|
35
|
-
acc.push(getterMethodName(name));
|
|
36
|
-
return acc;
|
|
37
|
-
}, []);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export const STATIC_COMPONENT = Symbol('STATIC_COMPONENT');
|
|
41
|
-
const SELF_GETTER_METHOD = Symbol('SELF_GETTER_METHOD');
|
|
42
|
-
|
|
43
|
-
function Enhancement(childComponents, createComponent, options) {
|
|
44
|
-
const getterMethodNames = flatGetterMethodNames(childComponents);
|
|
45
|
-
return {
|
|
46
|
-
condition: function (Component) {
|
|
47
|
-
return Boolean(Component[STATIC_COMPONENT] || Object.keys(childComponents).length);
|
|
48
|
-
},
|
|
49
|
-
init: function (props, WrapperComponent) {
|
|
50
|
-
const getterMethods = pick(this, getterMethodNames);
|
|
51
|
-
this[SELF_GETTER_METHOD] = () => {
|
|
52
|
-
const selfGetterMethod = getterMethodNameByDisplayName(WrapperComponent.displayName);
|
|
53
|
-
logger.warn(
|
|
54
|
-
true,
|
|
55
|
-
`Getter \`${selfGetterMethod}\` can't be fired as it is a getter of static component`,
|
|
56
|
-
props['data-ui-name'] || WrapperComponent.displayName,
|
|
57
|
-
);
|
|
58
|
-
};
|
|
59
|
-
assign(
|
|
60
|
-
this,
|
|
61
|
-
getterMethodNames.reduce((acc, name) => {
|
|
62
|
-
const getterMethod = getterMethods[name];
|
|
63
|
-
if (!getterMethod) return acc;
|
|
64
|
-
acc[name] = (childrenProps = {}) => {
|
|
65
|
-
const getterProps = getterMethod.call(this, childrenProps, acc[name].index);
|
|
66
|
-
acc[name].index++;
|
|
67
|
-
return assignProps(childrenProps, getterProps);
|
|
68
|
-
};
|
|
69
|
-
acc[name].index = 0;
|
|
70
|
-
return acc;
|
|
71
|
-
}, {}),
|
|
72
|
-
);
|
|
73
|
-
},
|
|
74
|
-
static: function (WrapperComponent) {
|
|
75
|
-
if (Object.keys(childComponents).length && !WrapperComponent.displayName) {
|
|
76
|
-
throw new Error('"displayName" is not defined');
|
|
77
|
-
}
|
|
78
|
-
return Object.entries(childComponents).reduce((acc, [name, value]) => {
|
|
79
|
-
let childComponents = {};
|
|
80
|
-
|
|
81
|
-
if (Array.isArray(value)) {
|
|
82
|
-
childComponents = value[1];
|
|
83
|
-
value = value[0];
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const prevStaticComponent = value[STATIC_COMPONENT];
|
|
87
|
-
// @ts-ignore
|
|
88
|
-
const prevDisplayName = value.displayName;
|
|
89
|
-
// @ts-ignore
|
|
90
|
-
value.displayName = WrapperComponent.displayName + '.' + name;
|
|
91
|
-
value[STATIC_COMPONENT] = true;
|
|
92
|
-
acc[name] = createComponent(value, childComponents, options);
|
|
93
|
-
// @ts-ignore
|
|
94
|
-
value.displayName = prevDisplayName;
|
|
95
|
-
value[STATIC_COMPONENT] = prevStaticComponent;
|
|
96
|
-
return acc;
|
|
97
|
-
}, {});
|
|
98
|
-
},
|
|
99
|
-
context: function (context /*, WrapperComponent*/) {
|
|
100
|
-
// const getterMethod = getterMethodNameByDisplayName(WrapperComponent.displayName);
|
|
101
|
-
|
|
102
|
-
return {
|
|
103
|
-
...context,
|
|
104
|
-
// [getterMethod]: this[SELF_GETTER_METHOD],
|
|
105
|
-
...pick(this, getterMethodNames),
|
|
106
|
-
};
|
|
107
|
-
},
|
|
108
|
-
wrapperProps: function (props, WrapperComponent) {
|
|
109
|
-
if (!WrapperComponent[STATIC_COMPONENT]) return props;
|
|
110
|
-
|
|
111
|
-
const context = useContext(options.context);
|
|
112
|
-
const getterMethod = context[getterMethodNameByDisplayName(WrapperComponent.displayName)];
|
|
113
|
-
if (getterMethod) {
|
|
114
|
-
return getterMethod(props);
|
|
115
|
-
}
|
|
116
|
-
return props;
|
|
117
|
-
},
|
|
118
|
-
render: function (render) {
|
|
119
|
-
getterMethodNames.forEach((name) => {
|
|
120
|
-
if (this[name] === undefined) return;
|
|
121
|
-
this[name].index = 0;
|
|
122
|
-
});
|
|
123
|
-
return render;
|
|
124
|
-
},
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export default Enhancement;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { useContext } from 'react';
|
|
2
|
-
// @ts-ignore
|
|
3
|
-
import { sstyled } from '../styled';
|
|
4
|
-
import { STATIC_COMPONENT } from './staticChildren';
|
|
5
|
-
|
|
6
|
-
export const STYLES_CONTEXT = Symbol('STYLES_CONTEXT');
|
|
7
|
-
const STYLES_SELF = Symbol('STYLES_SELF');
|
|
8
|
-
|
|
9
|
-
function Enhancement(childComponents, Context) {
|
|
10
|
-
return {
|
|
11
|
-
condition: function (Component) {
|
|
12
|
-
return Boolean(Component.style || Component[STATIC_COMPONENT]);
|
|
13
|
-
},
|
|
14
|
-
init: function (props, WrapperComponent) {
|
|
15
|
-
if (WrapperComponent.style) {
|
|
16
|
-
this[STYLES_SELF] = sstyled.merge(WrapperComponent.style, props._styles);
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
context: function (context) {
|
|
20
|
-
// для оптимизации, если нет детей, то не надо создавать контекст
|
|
21
|
-
if (!this[STYLES_SELF] || !Object.keys(childComponents).length) {
|
|
22
|
-
return context;
|
|
23
|
-
}
|
|
24
|
-
return {
|
|
25
|
-
...context,
|
|
26
|
-
[STYLES_CONTEXT]: this[STYLES_SELF],
|
|
27
|
-
};
|
|
28
|
-
},
|
|
29
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
30
|
-
asProps: function ({ _styles, styles, ...props }) {
|
|
31
|
-
return {
|
|
32
|
-
...props,
|
|
33
|
-
styles: styles || this[STYLES_SELF],
|
|
34
|
-
};
|
|
35
|
-
},
|
|
36
|
-
wrapperProps: function ({ styles, ...props }) {
|
|
37
|
-
const context = useContext(Context);
|
|
38
|
-
return {
|
|
39
|
-
...props,
|
|
40
|
-
_styles: styles,
|
|
41
|
-
styles: context[STYLES_CONTEXT],
|
|
42
|
-
};
|
|
43
|
-
},
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export default Enhancement;
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
// @ts-ignore
|
|
2
|
-
import { callAllEventHandlers } from '@semcore/utils/lib/assignProps';
|
|
3
|
-
// @ts-ignore
|
|
4
|
-
import capitalizeFirstLetter from '@semcore/utils/lib/capitalizeFirstLetter';
|
|
5
|
-
|
|
6
|
-
function assign(target, source) {
|
|
7
|
-
return Object.defineProperties(
|
|
8
|
-
target,
|
|
9
|
-
Object.keys(source).reduce((descriptors, key) => {
|
|
10
|
-
descriptors[key] = Object.getOwnPropertyDescriptor(source, key);
|
|
11
|
-
return descriptors;
|
|
12
|
-
}, {}),
|
|
13
|
-
);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function defaultProp(prop) {
|
|
17
|
-
return 'default' + capitalizeFirstLetter(prop);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function handlerProp(prop) {
|
|
21
|
-
if (prop === 'value') prop = '';
|
|
22
|
-
if (prop === 'checked') prop = '';
|
|
23
|
-
return `on${capitalizeFirstLetter(prop)}Change`;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function isControlled(propValue) {
|
|
27
|
-
return propValue !== undefined;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function uncontrolledProp(self, propName, propValue, propDefaultValue, propHandler, chainHandler) {
|
|
31
|
-
function getValue() {
|
|
32
|
-
return isControlled(propValue)
|
|
33
|
-
? propValue
|
|
34
|
-
: propName in self.state
|
|
35
|
-
? self.state[propName]
|
|
36
|
-
: propDefaultValue;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return [
|
|
40
|
-
getValue(),
|
|
41
|
-
(value, ...args) => {
|
|
42
|
-
const oldValue = getValue();
|
|
43
|
-
if (oldValue === value) return false;
|
|
44
|
-
if (!isControlled(propValue)) self.setState({ [propName]: value });
|
|
45
|
-
return callAllEventHandlers(propHandler, ...chainHandler)(value, ...args);
|
|
46
|
-
},
|
|
47
|
-
];
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function uncontrolledUniversal(props, config, uncontrolledProp) {
|
|
51
|
-
const handlerProps = {};
|
|
52
|
-
const uncontrolledProps = Object.keys(config).reduce((result, propName) => {
|
|
53
|
-
const handlerName = handlerProp(propName);
|
|
54
|
-
const defaultPropName = defaultProp(propName);
|
|
55
|
-
const {
|
|
56
|
-
[defaultPropName]: propDefaultValue,
|
|
57
|
-
[propName]: propValue,
|
|
58
|
-
[handlerName]: propHandler,
|
|
59
|
-
...other
|
|
60
|
-
} = result;
|
|
61
|
-
|
|
62
|
-
if (propDefaultValue === undefined) {
|
|
63
|
-
// eslint-disable-next-line no-console
|
|
64
|
-
console.warn(defaultPropName, 'must be installed in "defaultProps"');
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// if (typeof propDefaultValue === 'function' && propDefaultValue.defaultInit) {
|
|
68
|
-
// propDefaultValue = propDefaultValue(result);
|
|
69
|
-
// }
|
|
70
|
-
|
|
71
|
-
let setter = config[propName];
|
|
72
|
-
let chainHandler = [];
|
|
73
|
-
|
|
74
|
-
if (Array.isArray(setter)) [setter, ...chainHandler] = setter;
|
|
75
|
-
setter = setter || ((v) => v);
|
|
76
|
-
|
|
77
|
-
const [value, handler] = uncontrolledProp(
|
|
78
|
-
propName,
|
|
79
|
-
propValue,
|
|
80
|
-
propDefaultValue,
|
|
81
|
-
propHandler,
|
|
82
|
-
chainHandler,
|
|
83
|
-
);
|
|
84
|
-
// TODO: предупреждение из-за циклических вызовов
|
|
85
|
-
handlerProps[propName] = handler;
|
|
86
|
-
|
|
87
|
-
return {
|
|
88
|
-
...other,
|
|
89
|
-
[propName]: value,
|
|
90
|
-
[handlerName]: (eventOrValue, ...args) => {
|
|
91
|
-
const result = [setter(eventOrValue, ...args), ...args];
|
|
92
|
-
if (eventOrValue && eventOrValue.target) {
|
|
93
|
-
result.push(eventOrValue);
|
|
94
|
-
}
|
|
95
|
-
return handler(...result);
|
|
96
|
-
},
|
|
97
|
-
};
|
|
98
|
-
}, props);
|
|
99
|
-
return [uncontrolledProps, handlerProps];
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function uncontrolled(self, props, config) {
|
|
103
|
-
return uncontrolledUniversal(props, config, uncontrolledProp.bind(undefined, self));
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function Enhancement() {
|
|
107
|
-
return {
|
|
108
|
-
condition: function (Component) {
|
|
109
|
-
return Boolean(Component.prototype.uncontrolledProps);
|
|
110
|
-
},
|
|
111
|
-
init: function () {
|
|
112
|
-
this.state = this.state || {};
|
|
113
|
-
assign(this, {
|
|
114
|
-
get handlers() {
|
|
115
|
-
const [, uncontrolledHandlers] = uncontrolled(this, this.props, this.uncontrolledProps());
|
|
116
|
-
return uncontrolledHandlers;
|
|
117
|
-
},
|
|
118
|
-
});
|
|
119
|
-
},
|
|
120
|
-
context: function (context) {
|
|
121
|
-
return {
|
|
122
|
-
...context,
|
|
123
|
-
handlers: this.handlers,
|
|
124
|
-
};
|
|
125
|
-
},
|
|
126
|
-
asProps: function (props) {
|
|
127
|
-
// TODO возвращать только нужные свойства
|
|
128
|
-
const [uncontrolledProps] = uncontrolled(this, props, this.uncontrolledProps());
|
|
129
|
-
return uncontrolledProps;
|
|
130
|
-
},
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export default Enhancement;
|