You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.4 KiB
50 lines
1.4 KiB
/** |
|
* Copyright 2015, Yahoo! Inc. |
|
* Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms. |
|
*/ |
|
'use strict'; |
|
|
|
var REACT_STATICS = { |
|
childContextTypes: true, |
|
contextTypes: true, |
|
defaultProps: true, |
|
displayName: true, |
|
getDefaultProps: true, |
|
mixins: true, |
|
propTypes: true, |
|
type: true |
|
}; |
|
|
|
var KNOWN_STATICS = { |
|
name: true, |
|
length: true, |
|
prototype: true, |
|
caller: true, |
|
arguments: true, |
|
arity: true |
|
}; |
|
|
|
var isGetOwnPropertySymbolsAvailable = typeof Object.getOwnPropertySymbols === 'function'; |
|
|
|
module.exports = function hoistNonReactStatics(targetComponent, sourceComponent, customStatics) { |
|
if (typeof sourceComponent !== 'string') { // don't hoist over string (html) components |
|
var keys = Object.getOwnPropertyNames(sourceComponent); |
|
|
|
/* istanbul ignore else */ |
|
if (isGetOwnPropertySymbolsAvailable) { |
|
keys = keys.concat(Object.getOwnPropertySymbols(sourceComponent)); |
|
} |
|
|
|
for (var i = 0; i < keys.length; ++i) { |
|
if (!REACT_STATICS[keys[i]] && !KNOWN_STATICS[keys[i]] && (!customStatics || !customStatics[keys[i]])) { |
|
try { |
|
targetComponent[keys[i]] = sourceComponent[keys[i]]; |
|
} catch (error) { |
|
|
|
} |
|
} |
|
} |
|
} |
|
|
|
return targetComponent; |
|
};
|
|
|