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

Logging use of objects as maps for children

Let's start logging objects as maps for children. We may want to deprecate this and replace it with ImmutableMap and Map data structures instead. This should ideally be logged in the recursive function but since that loses the scope of where these children are passed it's easier to start tracking them here to get an idea of how frequently and where it's used.

Sebastian Markbage committed Mar 18, 2014 at 14:55 UTC e0c487649d2f5e8d4d430529a346bd4cdeb6785f
1 file changed +21
src/core/ReactComponent.js
+21
@@ -50,6 +50,7 @@ var ComponentLifeCycle = keyMirror({
50
51 var ownerHasExplicitKeyWarning = {};
52 var ownerHasPropertyWarning = {};
53 +var ownerHasMonitoredObjectMap = {};
54
55 var NUMERIC_PROPERTY_REGEX = /^\d+$/;
56
@@ -152,6 +153,25 @@ function validatePropertyKey(name) {
153 }
154 }
155
156 +/**
157 + * Log that we're using an object map. We're considering deprecating this
158 + * feature and replace it with proper Map and ImmutableMap data structures.
159 + *
160 + * @internal
161 + */
162 +function monitorUseOfObjectMap() {
163 + // Name of the component whose render method tried to pass children.
164 + // We only use this to avoid spewing the logs. We lose additional
165 + // owner stacks but hopefully one level is enough to trace the source.
166 + var currentName = (ReactCurrentOwner.current &&
167 + ReactCurrentOwner.current.constructor.displayName) || '';
168 + if (ownerHasMonitoredObjectMap.hasOwnProperty(currentName)) {
169 + return;
170 + }
171 + ownerHasMonitoredObjectMap[currentName] = true;
172 + monitorCodeUse('react_object_map_children');
173 +}
174 +
175 /**
176 * Ensure that every component either is passed in a static location, in an
177 * array with an explicit keys property defined, or in an object literal
@@ -173,6 +193,7 @@ function validateChildKeys(component) {
193 // This component was passed in a valid location.
194 component.__keyValidated__ = true;
195 } else if (component && typeof component === 'object') {
196 + monitorUseOfObjectMap();
197 for (var name in component) {
198 validatePropertyKey(name, component);
199 }