Find cases where shouldUpdateReactComponent is determined by the owner.

This commit is contained in:
Jim
2014-11-26 16:56:42 -08:00
parent c63de4b79b
commit a463191bb2
+37 -6
View File
@@ -12,6 +12,8 @@
"use strict";
var monitorCodeUse = require('monitorCodeUse');
/**
* Given a `prevElement` and `nextElement`, determines if the existing
* instance should be updated as opposed to being destroyed or replaced by a new
@@ -30,12 +32,41 @@ function shouldUpdateReactComponent(prevElement, nextElement) {
if (prevType === 'string' || prevType === 'number') {
return (nextType === 'string' || nextType === 'number');
} else {
return (
nextType === 'object' &&
prevElement.type === nextElement.type &&
prevElement.key === nextElement.key &&
prevElement._owner === nextElement._owner
);
if (nextType === 'object' &&
prevElement.type === nextElement.type &&
prevElement.key === nextElement.key) {
var ownersMatch = prevElement._owner === nextElement._owner;
var prevName = null;
var nextName = null;
var nextDisplayName = null;
if(__DEV__) {
if (!ownersMatch) {
if (prevElement._owner != null &&
prevElement._owner.getPublicInstance() != null &&
prevElement._owner.getPublicInstance().constructor != null) {
prevName = prevElement._owner.getPublicInstance().constructor.displayName;
}
if (nextElement._owner != null &&
nextElement._owner.getPublicInstance() != null &&
nextElement._owner.getPublicInstance().constructor != null) {
nextName = nextElement._owner.getPublicInstance().constructor.displayName;
}
if(nextElement.type != null && nextElement.type.displayName != null) {
nextDisplayName = nextElement.type.displayName;
}
monitorCodeUse(
'react_should_update_owner_is_useful',
{
key: prevElement.key,
prevOwner: prevName,
nextOwner: nextName,
nextDisplayName: nextDisplayName
}
);
}
}
return ownersMatch;
}
}
}
return false;