@samitouri / QOS-React-2 / commits / f846edcbea

Remove indirection when determining valid config and ref

Dan Abramov committed May 25, 2016 at 23:17 UTC f846edcbea793370caceb59659fcc4091a9c310f
1 file changed +16 -15
src/isomorphic/classic/element/ReactElement.js
+16 -15
@@ -32,17 +32,20 @@ var RESERVED_PROPS = {
32
33 var specialPropKeyWarningShown, specialPropRefWarningShown;
34
35 -function isValidConfigRefOrKey(config, name) {
35 +function hasValidRef(config) {
36 if (__DEV__) {
37 - return hasOwnProperty.call(config, name) &&
38 - !Object.getOwnPropertyDescriptor(config, name).get;
37 + return hasOwnProperty.call(config, 'ref') &&
38 + !Object.getOwnPropertyDescriptor(config, 'ref').get;
39 }
40 -
41 - return config[name] !== undefined;
40 + return config.ref !== undefined;
41 }
42
44 -function getConfigKey(config) {
45 - return '' + config.key;
43 +function hasValidKey(config) {
44 + if (__DEV__) {
45 + return hasOwnProperty.call(config, 'key') &&
46 + !Object.getOwnPropertyDescriptor(config, 'key').get;
47 + }
48 + return config.key !== undefined;
49 }
50
51 /**
@@ -153,12 +156,11 @@ ReactElement.createElement = function(type, config, children) {
156 );
157 }
158
156 - if (isValidConfigRefOrKey(config, 'ref')) {
159 + if (hasValidRef(config)) {
160 ref = config.ref;
161 }
159 -
160 - if (isValidConfigRefOrKey(config, 'key')) {
161 - key = getConfigKey(config);
162 + if (hasValidKey(config)) {
163 + key = '' + config.key;
164 }
165
166 self = config.__self === undefined ? null : config.__self;
@@ -313,14 +315,13 @@ ReactElement.cloneElement = function(element, config, children) {
315 );
316 }
317
316 - if (isValidConfigRefOrKey(config, 'ref')) {
318 + if (hasValidRef(config)) {
319 // Silently steal the ref from the parent.
320 ref = config.ref;
321 owner = ReactCurrentOwner.current;
322 }
321 -
322 - if (isValidConfigRefOrKey(config, 'key')) {
323 - key = getConfigKey(config);
323 + if (hasValidKey(config)) {
324 + key = '' + config.key;
325 }
326
327 // Remaining properties override existing props