From f846edcbea793370caceb59659fcc4091a9c310f Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Wed, 25 May 2016 23:17:20 +0100 Subject: [PATCH] Remove indirection when determining valid config and ref --- .../classic/element/ReactElement.js | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/isomorphic/classic/element/ReactElement.js b/src/isomorphic/classic/element/ReactElement.js index fe3c6b6a2c..49039be3df 100644 --- a/src/isomorphic/classic/element/ReactElement.js +++ b/src/isomorphic/classic/element/ReactElement.js @@ -32,17 +32,20 @@ var RESERVED_PROPS = { var specialPropKeyWarningShown, specialPropRefWarningShown; -function isValidConfigRefOrKey(config, name) { +function hasValidRef(config) { if (__DEV__) { - return hasOwnProperty.call(config, name) && - !Object.getOwnPropertyDescriptor(config, name).get; + return hasOwnProperty.call(config, 'ref') && + !Object.getOwnPropertyDescriptor(config, 'ref').get; } - - return config[name] !== undefined; + return config.ref !== undefined; } -function getConfigKey(config) { - return '' + config.key; +function hasValidKey(config) { + if (__DEV__) { + return hasOwnProperty.call(config, 'key') && + !Object.getOwnPropertyDescriptor(config, 'key').get; + } + return config.key !== undefined; } /** @@ -153,12 +156,11 @@ ReactElement.createElement = function(type, config, children) { ); } - if (isValidConfigRefOrKey(config, 'ref')) { + if (hasValidRef(config)) { ref = config.ref; } - - if (isValidConfigRefOrKey(config, 'key')) { - key = getConfigKey(config); + if (hasValidKey(config)) { + key = '' + config.key; } self = config.__self === undefined ? null : config.__self; @@ -313,14 +315,13 @@ ReactElement.cloneElement = function(element, config, children) { ); } - if (isValidConfigRefOrKey(config, 'ref')) { + if (hasValidRef(config)) { // Silently steal the ref from the parent. ref = config.ref; owner = ReactCurrentOwner.current; } - - if (isValidConfigRefOrKey(config, 'key')) { - key = getConfigKey(config); + if (hasValidKey(config)) { + key = '' + config.key; } // Remaining properties override existing props