1 | "use strict";
|
2 |
|
3 | exports.__esModule = true;
|
4 | exports.copyRefs = copyRefs;
|
5 |
|
6 | var React = _interopRequireWildcard(require("react"));
|
7 |
|
8 | function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
9 |
|
10 | var REACT_METHODS = ['autobind', 'childContextTypes', 'componentDidMount', 'componentDidUpdate', 'componentWillMount', 'componentWillReceiveProps', 'componentWillUnmount', 'componentWillUpdate', 'contextTypes', 'displayName', 'getChildContext', 'getDefaultProps', 'getDOMNode', 'getInitialState', 'mixins', 'propTypes', 'render', 'replaceProps', 'setProps', 'shouldComponentUpdate', 'statics', 'updateComponent'];
|
11 |
|
12 | function copyRefs(TargetComponent, SourceComponent) {
|
13 |
|
14 | if (!SourceComponent.prototype) {
|
15 | return TargetComponent;
|
16 | }
|
17 |
|
18 |
|
19 | Object.getOwnPropertyNames(SourceComponent.prototype).filter(function (prop) {
|
20 | return !(REACT_METHODS.includes(prop) ||
|
21 | prop in React.Component.prototype ||
|
22 |
|
23 | prop in TargetComponent.prototype ||
|
24 |
|
25 | prop.startsWith('_'));
|
26 | }).forEach(function (prop) {
|
27 |
|
28 | if (typeof SourceComponent.prototype[prop] === 'function') {
|
29 |
|
30 |
|
31 | TargetComponent.prototype[prop] = function () {
|
32 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
33 | args[_key] = arguments[_key];
|
34 | }
|
35 |
|
36 |
|
37 |
|
38 | return SourceComponent.prototype[prop].apply(this.getWrappedInstance(), args);
|
39 | };
|
40 | } else {
|
41 |
|
42 |
|
43 |
|
44 | Object.defineProperty(TargetComponent.prototype, prop, {
|
45 | get: function get() {
|
46 | return this.getWrappedInstance()[prop];
|
47 | },
|
48 | set: function set(value) {
|
49 | this.getWrappedInstance()[prop] = value;
|
50 | }
|
51 | });
|
52 | }
|
53 | });
|
54 | return TargetComponent;
|
55 | }
|
56 |
|
\ | No newline at end of file |