1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.copyRefs = copyRefs;
|
7 |
|
8 | var _react = require('react');
|
9 |
|
10 | var React = _interopRequireWildcard(_react);
|
11 |
|
12 | 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)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
|
13 |
|
14 | 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'];
|
15 |
|
16 | function copyRefs(TargetComponent, SourceComponent) {
|
17 | if (!SourceComponent.prototype) {
|
18 | return TargetComponent;
|
19 | }
|
20 |
|
21 |
|
22 | Object.getOwnPropertyNames(SourceComponent.prototype).filter(function (prop) {
|
23 | return !(REACT_METHODS.includes(prop) ||
|
24 | prop in React.Component.prototype ||
|
25 |
|
26 | prop in TargetComponent.prototype ||
|
27 |
|
28 | prop.startsWith('_'));
|
29 | }).forEach(function (prop) {
|
30 |
|
31 | if (typeof SourceComponent.prototype[prop] === 'function') {
|
32 |
|
33 |
|
34 | TargetComponent.prototype[prop] = function () {
|
35 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
36 | args[_key] = arguments[_key];
|
37 | }
|
38 |
|
39 |
|
40 |
|
41 | return SourceComponent.prototype[prop].apply(this.getWrappedInstance(), args);
|
42 | };
|
43 | } else {
|
44 |
|
45 |
|
46 |
|
47 | Object.defineProperty(TargetComponent.prototype, prop, {
|
48 | get: function get() {
|
49 | return this.getWrappedInstance()[prop];
|
50 | },
|
51 | set: function set(value) {
|
52 | this.getWrappedInstance()[prop] = value;
|
53 | }
|
54 | });
|
55 | }
|
56 | });
|
57 |
|
58 | return TargetComponent;
|
59 | } |
\ | No newline at end of file |