UNPKG

2.65 kBJavaScriptView Raw
1"use strict";
2
3exports.__esModule = true;
4exports.copyRefs = copyRefs;
5
6var React = _interopRequireWildcard(require("react"));
7
8function _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
10var 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
12function copyRefs(TargetComponent, SourceComponent) {
13 // $FlowFixMe
14 if (!SourceComponent.prototype) {
15 return TargetComponent;
16 } // $FlowFixMe
17
18
19 Object.getOwnPropertyNames(SourceComponent.prototype).filter(function (prop) {
20 return !(REACT_METHODS.includes(prop) || // React specific methods and properties
21 prop in React.Component.prototype || // Properties from React's prototype such as `setState`
22 // $FlowFixMe
23 prop in TargetComponent.prototype || // Properties from enhanced component's prototype
24 // Private methods
25 prop.startsWith('_'));
26 }).forEach(function (prop) {
27 // $FlowFixMe
28 if (typeof SourceComponent.prototype[prop] === 'function') {
29 /* eslint-disable func-names, no-param-reassign */
30 // $FlowFixMe
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 // Make sure the function is called with correct context
37 // $FlowFixMe
38 return SourceComponent.prototype[prop].apply(this.getWrappedInstance(), args);
39 };
40 } else {
41 // Copy properties as getters and setters
42 // This make sure dynamic properties always stay up-to-date
43 // $FlowFixMe
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//# sourceMappingURL=utils.js.map
\No newline at end of file