Skip to content

Commit

Permalink
[Fiber] Support iterables (facebook#8446)
Browse files Browse the repository at this point in the history
* Add iterable cases to MultiChildReconcile test

Stack currently supports rendering iterables, but Fiber does not.

Previously we didn't have any public API tests for iterables. We have tests for traverseAllChildren() which is shared between React.Children and Stack. However Fiber doesn't currently use it, and likely won't. So this commit is a first step towards actually testing iterable support via public API. The next step will be to port traverseAllChildren() tests to test React.Children API instead.

* Implement iterable reconciliation in Fiber

This uses the same exact algorithm as array reconciliation but uses iterator to step through.

This gets reconcile tests to pass again but introduces a regression in ReactMultiChildText case which uses Maps as children. It passed before because Maps were ignored, but now it's failing because this actually runs the Map code path in Fiber. We can throw early in this case when we want to follow up on this.

* Rewrite traverseAllChildren() tests against React.Children API

This function was used in React.Children and Stack.

The corresponding reconciliation functionality is being tested by ReactMultiChild tests.

So we can move these tests to ReactChildren and test its public API.
  • Loading branch information
gaearon authored and acusti committed Mar 15, 2017
1 parent 46f77b7 commit 2a9b09a
Show file tree
Hide file tree
Showing 9 changed files with 745 additions and 640 deletions.
1 change: 1 addition & 0 deletions scripts/fiber/tests-failing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ src/renderers/shared/shared/__tests__/ReactEmptyComponent-test.js

src/renderers/shared/shared/__tests__/ReactMultiChildText-test.js
* should correctly handle all possible children for render and update
* should reorder keyed text nodes

src/renderers/shared/shared/__tests__/ReactStatelessComponent-test.js
* should warn when stateless component returns array
Expand Down
7 changes: 1 addition & 6 deletions scripts/fiber/tests-passing-except-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,9 @@ src/renderers/shared/shared/__tests__/ReactCompositeComponent-test.js

src/renderers/shared/shared/__tests__/ReactMultiChild-test.js
* should warn for duplicated keys with component stack info

src/renderers/shared/shared/__tests__/ReactMultiChildText-test.js
* should reorder keyed text nodes
* should warn for using maps as children with owner info

src/renderers/shared/shared/__tests__/ReactStatelessComponent-test.js
* should warn for childContextTypes on a functional component
* should warn when given a ref
* should use correct name in key warning

src/shared/utils/__tests__/traverseAllChildren-test.js
* should warn for using maps as children with owner info
30 changes: 13 additions & 17 deletions scripts/fiber/tests-passing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@ src/isomorphic/children/__tests__/ReactChildren-test.js
* should support identity for simple
* should treat single arrayless child as being in array
* should treat single child in array as expected
* should be called for each child
* should traverse children of different kinds
* should be called for each child in nested structure
* should retain key across two mappings
* should be called for each child in an iterable without keys
* should be called for each child in an iterable with keys
* should use keys from entry iterables
* should not enumerate enumerable numbers (#4776)
* should allow extension of native prototypes
* should pass key to returned component
* should invoke callback with the right context
* should be called for each child
Expand All @@ -122,6 +131,8 @@ src/isomorphic/children/__tests__/ReactChildren-test.js
* should count the number of children in flat structure
* should count the number of children in nested structure
* should flatten children to an array
* should throw on object
* should throw on regex

src/isomorphic/children/__tests__/onlyChild-test.js
* should fail when passed two children
Expand Down Expand Up @@ -1335,7 +1346,8 @@ src/renderers/shared/shared/__tests__/ReactMultiChild-test.js
* should replace children with different keys

src/renderers/shared/shared/__tests__/ReactMultiChildReconcile-test.js
* should reset internal state if removed then readded
* should reset internal state if removed then readded in an array
* should reset internal state if removed then readded in an iterable
* should create unique identity
* should preserve order if children order has not changed
* should transition from zero to one children correctly
Expand Down Expand Up @@ -1536,22 +1548,6 @@ src/shared/utils/__tests__/PooledClass-test.js
src/shared/utils/__tests__/reactProdInvariant-test.js
* should throw with the correct number of `%s`s in the URL

src/shared/utils/__tests__/traverseAllChildren-test.js
* should support identity for simple
* should treat single arrayless child as being in array
* should treat single child in array as expected
* should be called for each child
* should traverse children of different kinds
* should be called for each child in nested structure
* should retain key across two mappings
* should be called for each child in an iterable without keys
* should be called for each child in an iterable with keys
* should use keys from entry iterables
* should not enumerate enumerable numbers (#4776)
* should allow extension of native prototypes
* should throw on object
* should throw on regex

src/test/__tests__/ReactTestUtils-test.js
* should have shallow rendering
* should shallow render a functional component
Expand Down
Loading

0 comments on commit 2a9b09a

Please sign in to comment.