From e0c487649d2f5e8d4d430529a346bd4cdeb6785f Mon Sep 17 00:00:00 2001 From: Sebastian Markbage Date: Tue, 18 Mar 2014 14:55:26 -0700 Subject: [PATCH] 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. --- src/core/ReactComponent.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/core/ReactComponent.js b/src/core/ReactComponent.js index 7a72f84d68..7792001b64 100644 --- a/src/core/ReactComponent.js +++ b/src/core/ReactComponent.js @@ -50,6 +50,7 @@ var ComponentLifeCycle = keyMirror({ var ownerHasExplicitKeyWarning = {}; var ownerHasPropertyWarning = {}; +var ownerHasMonitoredObjectMap = {}; var NUMERIC_PROPERTY_REGEX = /^\d+$/; @@ -152,6 +153,25 @@ function validatePropertyKey(name) { } } +/** + * Log that we're using an object map. We're considering deprecating this + * feature and replace it with proper Map and ImmutableMap data structures. + * + * @internal + */ +function monitorUseOfObjectMap() { + // Name of the component whose render method tried to pass children. + // We only use this to avoid spewing the logs. We lose additional + // owner stacks but hopefully one level is enough to trace the source. + var currentName = (ReactCurrentOwner.current && + ReactCurrentOwner.current.constructor.displayName) || ''; + if (ownerHasMonitoredObjectMap.hasOwnProperty(currentName)) { + return; + } + ownerHasMonitoredObjectMap[currentName] = true; + monitorCodeUse('react_object_map_children'); +} + /** * Ensure that every component either is passed in a static location, in an * array with an explicit keys property defined, or in an object literal @@ -173,6 +193,7 @@ function validateChildKeys(component) { // This component was passed in a valid location. component.__keyValidated__ = true; } else if (component && typeof component === 'object') { + monitorUseOfObjectMap(); for (var name in component) { validatePropertyKey(name, component); }