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

Find cases where shouldUpdateReactComponent is determined by the owner.

Jim committed Nov 26, 2014 at 16:56 UTC a463191bb26eeb888c15c6b01fa2fa42d636e1be
1 file changed +37 -6
src/core/shouldUpdateReactComponent.js
+37 -6
@@ -12,6 +12,8 @@
12
13 "use strict";
14
15 +var monitorCodeUse = require('monitorCodeUse');
16 +
17 /**
18 * Given a `prevElement` and `nextElement`, determines if the existing
19 * instance should be updated as opposed to being destroyed or replaced by a new
@@ -30,12 +32,41 @@ function shouldUpdateReactComponent(prevElement, nextElement) {
32 if (prevType === 'string' || prevType === 'number') {
33 return (nextType === 'string' || nextType === 'number');
34 } else {
33 - return (
34 - nextType === 'object' &&
35 - prevElement.type === nextElement.type &&
36 - prevElement.key === nextElement.key &&
37 - prevElement._owner === nextElement._owner
38 - );
35 + if (nextType === 'object' &&
36 + prevElement.type === nextElement.type &&
37 + prevElement.key === nextElement.key) {
38 + var ownersMatch = prevElement._owner === nextElement._owner;
39 + var prevName = null;
40 + var nextName = null;
41 + var nextDisplayName = null;
42 + if(__DEV__) {
43 + if (!ownersMatch) {
44 + if (prevElement._owner != null &&
45 + prevElement._owner.getPublicInstance() != null &&
46 + prevElement._owner.getPublicInstance().constructor != null) {
47 + prevName = prevElement._owner.getPublicInstance().constructor.displayName;
48 + }
49 + if (nextElement._owner != null &&
50 + nextElement._owner.getPublicInstance() != null &&
51 + nextElement._owner.getPublicInstance().constructor != null) {
52 + nextName = nextElement._owner.getPublicInstance().constructor.displayName;
53 + }
54 + if(nextElement.type != null && nextElement.type.displayName != null) {
55 + nextDisplayName = nextElement.type.displayName;
56 + }
57 + monitorCodeUse(
58 + 'react_should_update_owner_is_useful',
59 + {
60 + key: prevElement.key,
61 + prevOwner: prevName,
62 + nextOwner: nextName,
63 + nextDisplayName: nextDisplayName
64 + }
65 + );
66 + }
67 + }
68 + return ownersMatch;
69 + }
70 }
71 }
72 return false;