-
Notifications
You must be signed in to change notification settings - Fork 0
/
fromRenderProps.js
42 lines (29 loc) · 1.43 KB
/
fromRenderProps.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.default = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _createFactory = _interopRequireDefault(require("./utils/createFactory"));
var _setDisplayName = _interopRequireDefault(require("./setDisplayName"));
var _wrapDisplayName = _interopRequireDefault(require("./wrapDisplayName"));
var fromRenderProps = function fromRenderProps(RenderPropsComponent, propsMapper, renderPropName) {
if (renderPropName === void 0) {
renderPropName = 'children';
}
return function (BaseComponent) {
var baseFactory = (0, _createFactory.default)(BaseComponent);
var renderPropsFactory = (0, _createFactory.default)(RenderPropsComponent);
var FromRenderProps = function FromRenderProps(ownerProps) {
var _renderPropsFactory;
return renderPropsFactory((_renderPropsFactory = {}, _renderPropsFactory[renderPropName] = function () {
return baseFactory((0, _extends2.default)({}, ownerProps, propsMapper.apply(void 0, arguments)));
}, _renderPropsFactory));
};
if (process.env.NODE_ENV !== 'production') {
return (0, _setDisplayName.default)((0, _wrapDisplayName.default)(BaseComponent, 'fromRenderProps'))(FromRenderProps);
}
return FromRenderProps;
};
};
var _default = fromRenderProps;
exports.default = _default;