1 |
|
2 |
|
3 |
|
4 |
|
5 | 'use strict';
|
6 |
|
7 | var REACT_STATICS = {
|
8 | childContextTypes: true,
|
9 | contextTypes: true,
|
10 | defaultProps: true,
|
11 | displayName: true,
|
12 | getDefaultProps: true,
|
13 | mixins: true,
|
14 | propTypes: true,
|
15 | type: true
|
16 | };
|
17 |
|
18 | var getOwnPropertySymbols = Object.getOwnPropertySymbols;
|
19 | var hasOwnProperty = Object.prototype.hasOwnProperty;
|
20 | var propIsEnumerable = Object.prototype.propertyIsEnumerable;
|
21 | var getPrototypeOf = Object.getPrototypeOf;
|
22 | var objectPrototype = getPrototypeOf && getPrototypeOf(Object);
|
23 |
|
24 | module.exports = function hoistNonReactStatics(targetComponent, sourceComponent, blacklist) {
|
25 | if (typeof sourceComponent !== 'string') {
|
26 |
|
27 | if (objectPrototype) {
|
28 | var inheritedComponent = getPrototypeOf(sourceComponent);
|
29 | if (inheritedComponent && inheritedComponent !== objectPrototype) {
|
30 | hoistNonReactStatics(targetComponent, inheritedComponent, blacklist);
|
31 | }
|
32 | }
|
33 |
|
34 | for (var key in sourceComponent) {
|
35 | if (!REACT_STATICS[key] && (!blacklist || !blacklist[key])) {
|
36 | if (hasOwnProperty.call(sourceComponent, key)) {
|
37 | try {
|
38 | targetComponent[key] = sourceComponent[key];
|
39 | } catch (e) {}
|
40 | }
|
41 | }
|
42 | }
|
43 |
|
44 | if (getOwnPropertySymbols) {
|
45 | var symbols = getOwnPropertySymbols(sourceComponent);
|
46 | for (var i = 0; i < symbols.length; i++) {
|
47 | if (!REACT_STATICS[symbols[i]] && (!blacklist || !blacklist[symbols[i]])) {
|
48 | if (propIsEnumerable.call(sourceComponent, symbols[i])) {
|
49 | try {
|
50 | targetComponent[symbols[i]] = sourceComponent[symbols[i]];
|
51 | } catch(e) {}
|
52 | }
|
53 | }
|
54 | }
|
55 | }
|
56 |
|
57 | return targetComponent;
|
58 | }
|
59 |
|
60 | return targetComponent;
|
61 | };
|