@samitouri / QOS-React-2 / commits / 91194126d8

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.

Sebastian Markbage committed Feb 17, 2015 at 11:23 UTC 91194126d87c6165edf7d33ac67dd2fae86cf08f
2 files changed +21
src/utils/__tests__/traverseAllChildren-test.js
+9
@@ -396,6 +396,8 @@ describe('traverseAllChildren', function() {
396 });
397
398 it('should use keys from entry iterables', function() {
399 + spyOn(console, 'warn');
400 +
401 var threeDivEntryIterable = {
402 '@@iterator': function() {
403 var i = 0;
@@ -445,6 +447,13 @@ describe('traverseAllChildren', function() {
447 '.$#3:0',
448 2
449 );
450 +
451 + expect(console.warn.argsForCall.length).toBe(1);
452 + expect(console.warn.argsForCall[0][0]).toContain(
453 + 'Warning: Using Maps as children is not yet fully supported. It is an ' +
454 + 'experimental feature that might be removed. Convert it to a sequence ' +
455 + '/ iterable of keyed ReactElements instead.'
456 + );
457 });
458
459 });
src/utils/traverseAllChildren.js
+12
@@ -17,6 +17,7 @@ var ReactInstanceHandles = require('ReactInstanceHandles');
17
18 var getIteratorFn = require('getIteratorFn');
19 var invariant = require('invariant');
20 +var warning = require('warning');
21
22 var SEPARATOR = ReactInstanceHandles.SEPARATOR;
23 var SUBSEPARATOR = ':';
@@ -34,6 +35,8 @@ var userProvidedKeyEscaperLookup = {
35
36 var userProvidedKeyEscapeRegex = /[=.:]/g;
37
38 +var didWarnAboutMaps = false;
39 +
40 function userProvidedKeyEscaper(match) {
41 return userProvidedKeyEscaperLookup[match];
42 }
@@ -158,6 +161,15 @@ function traverseAllChildrenImpl(
161 );
162 }
163 } else {
164 + if (__DEV__) {
165 + warning(
166 + didWarnAboutMaps,
167 + 'Using Maps as children is not yet fully supported. It is an ' +
168 + 'experimental feature that might be removed. Convert it to a ' +
169 + 'sequence / iterable of keyed ReactElements instead.'
170 + );
171 + didWarnAboutMaps = true;
172 + }
173 // Iterator will provide entry [k,v] tuples rather than values.
174 while (!(step = iterator.next()).done) {
175 var entry = step.value;