mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Find cases where shouldUpdateReactComponent is determined by the owner.
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user