From 91194126d87c6165edf7d33ac67dd2fae86cf08f Mon Sep 17 00:00:00 2001 From: Sebastian Markbage Date: Tue, 17 Feb 2015 11:23:12 -0800 Subject: [PATCH] Warn if using Maps as children We're not sure if this is the way we want to support this API. It creates two ways of doing things. It is convenient to avoid needing to explicitly redefine the key of Maps. However, this use case isn't as common as having an iterable where the key is on the value, not the key. --- src/utils/__tests__/traverseAllChildren-test.js | 9 +++++++++ src/utils/traverseAllChildren.js | 12 ++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/utils/__tests__/traverseAllChildren-test.js b/src/utils/__tests__/traverseAllChildren-test.js index 91b51f0292..d998443b72 100644 --- a/src/utils/__tests__/traverseAllChildren-test.js +++ b/src/utils/__tests__/traverseAllChildren-test.js @@ -396,6 +396,8 @@ describe('traverseAllChildren', function() { }); it('should use keys from entry iterables', function() { + spyOn(console, 'warn'); + var threeDivEntryIterable = { '@@iterator': function() { var i = 0; @@ -445,6 +447,13 @@ describe('traverseAllChildren', function() { '.$#3:0', 2 ); + + expect(console.warn.argsForCall.length).toBe(1); + expect(console.warn.argsForCall[0][0]).toContain( + 'Warning: Using Maps as children is not yet fully supported. It is an ' + + 'experimental feature that might be removed. Convert it to a sequence ' + + '/ iterable of keyed ReactElements instead.' + ); }); }); diff --git a/src/utils/traverseAllChildren.js b/src/utils/traverseAllChildren.js index da8fd53bb9..e547237a5a 100644 --- a/src/utils/traverseAllChildren.js +++ b/src/utils/traverseAllChildren.js @@ -17,6 +17,7 @@ var ReactInstanceHandles = require('ReactInstanceHandles'); var getIteratorFn = require('getIteratorFn'); var invariant = require('invariant'); +var warning = require('warning'); var SEPARATOR = ReactInstanceHandles.SEPARATOR; var SUBSEPARATOR = ':'; @@ -34,6 +35,8 @@ var userProvidedKeyEscaperLookup = { var userProvidedKeyEscapeRegex = /[=.:]/g; +var didWarnAboutMaps = false; + function userProvidedKeyEscaper(match) { return userProvidedKeyEscaperLookup[match]; } @@ -158,6 +161,15 @@ function traverseAllChildrenImpl( ); } } else { + if (__DEV__) { + warning( + didWarnAboutMaps, + 'Using Maps as children is not yet fully supported. It is an ' + + 'experimental feature that might be removed. Convert it to a ' + + 'sequence / iterable of keyed ReactElements instead.' + ); + didWarnAboutMaps = true; + } // Iterator will provide entry [k,v] tuples rather than values. while (!(step = iterator.next()).done) { var entry = step.value;