1 | import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
2 | import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
3 | import React from 'react';
|
4 |
|
5 | var cache = new Map();
|
6 | export var filterProps = function filterProps() {
|
7 | var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
8 | var blacklist = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
9 | return Object.entries(props).reduce(function (r, _ref) {
|
10 | var _ref2 = _slicedToArray(_ref, 2),
|
11 | k = _ref2[0],
|
12 | v = _ref2[1];
|
13 |
|
14 | if (!blacklist.includes(k)) {
|
15 | r[k] = v;
|
16 | }
|
17 |
|
18 | return r;
|
19 | }, {});
|
20 | };
|
21 |
|
22 | var fromRenderProp = function fromRenderProp(elementType) {
|
23 | var customProps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
24 | var isComposite = typeof elementType === 'function';
|
25 |
|
26 | if (isComposite) {
|
27 | return elementType;
|
28 | }
|
29 |
|
30 |
|
31 | var uniqueCustomProps = Array.from(new Set(_toConsumableArray(customProps).sort()));
|
32 |
|
33 | var key = "".concat(elementType, "//").concat(uniqueCustomProps.join(','));
|
34 |
|
35 |
|
36 | if (!cache.has(key)) {
|
37 |
|
38 |
|
39 | var Component = function Component(props) {
|
40 | return React.createElement(elementType, filterProps(props, uniqueCustomProps));
|
41 | };
|
42 |
|
43 | Component.displayName = "fromRenderProp(".concat(elementType, ")");
|
44 | cache.set(key, Component);
|
45 | }
|
46 |
|
47 | return cache.get(key);
|
48 | };
|
49 |
|
50 | export default fromRenderProp;
|
51 |
|
\ | No newline at end of file |