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 KNOWN_STATICS = {
|
19 | name: true,
|
20 | length: true,
|
21 | prototype: true,
|
22 | caller: true,
|
23 | callee: true,
|
24 | arguments: true,
|
25 | arity: true
|
26 | };
|
27 |
|
28 | var getOwnPropertySymbols = Object.getOwnPropertySymbols;
|
29 | var hasOwnProperty = Object.prototype.hasOwnProperty;
|
30 | var propIsEnumerable = Object.prototype.propertyIsEnumerable;
|
31 | var getPrototypeOf = Object.getPrototypeOf;
|
32 | var objectPrototype = getPrototypeOf && getPrototypeOf(Object);
|
33 | var getOwnPropertyNames = Object.getOwnPropertyNames;
|
34 |
|
35 | module.exports = function hoistNonReactStatics(targetComponent, sourceComponent, blacklist) {
|
36 | if (typeof sourceComponent !== 'string') {
|
37 |
|
38 | if (objectPrototype) {
|
39 | var inheritedComponent = getPrototypeOf(sourceComponent);
|
40 | if (inheritedComponent && inheritedComponent !== objectPrototype) {
|
41 | hoistNonReactStatics(targetComponent, inheritedComponent, blacklist);
|
42 | }
|
43 | }
|
44 |
|
45 | var keys = getOwnPropertyNames(sourceComponent);
|
46 |
|
47 | if (getOwnPropertySymbols) {
|
48 | keys = keys.concat(getOwnPropertySymbols(sourceComponent));
|
49 | }
|
50 |
|
51 | for (var i = 0; i < keys.length; ++i) {
|
52 | var key = keys[i];
|
53 | if (!REACT_STATICS[key] && !KNOWN_STATICS[key] && (!blacklist || !blacklist[key])) {
|
54 |
|
55 | if(propIsEnumerable.call(sourceComponent, key) || typeof sourceComponent[key] === 'function') {
|
56 | try {
|
57 | targetComponent[key] = sourceComponent[key];
|
58 | } catch (e) {}
|
59 | }
|
60 | }
|
61 | }
|
62 |
|
63 | return targetComponent;
|
64 | }
|
65 |
|
66 | return targetComponent;
|
67 | };
|