File tree Expand file tree Collapse file tree 4 files changed +58
-4
lines changed
Expand file tree Collapse file tree 4 files changed +58
-4
lines changed Original file line number Diff line number Diff line change 6060 "pretty-bytes" : " 4.0.2" ,
6161 "prop-types" : " ^15.6.0" ,
6262 "ramda" : " ^0.25.0" ,
63- "react" : " ^16.0 .0" ,
63+ "react" : " ^16.4 .0" ,
6464 "react-addons-test-utils" : " ^15.6.2" ,
6565 "react-dom" : " ^16.0.0" ,
6666 "readline-sync" : " 1.4.7" ,
Original file line number Diff line number Diff line change @@ -339,6 +339,46 @@ describe('reactTreeWalker', () => {
339339 } )
340340
341341 describe ( 'react' , ( ) => {
342+ it ( 'supports new context API' , ( ) => {
343+ const { Provider, Consumer } = React . createContext ( )
344+
345+ class SomeInstance extends React . Component {
346+ render ( ) {
347+ return < div > { this . props . text } </ div >
348+ }
349+ }
350+
351+ const tree = (
352+ < Provider
353+ value = { {
354+ message : 'This is a provider message' ,
355+ handler : io => io ,
356+ } }
357+ >
358+ < Consumer >
359+ { ( { message, handler } ) => (
360+ < strong >
361+ < i > { `${ message } : ${ handler } ` } </ i >
362+ </ strong >
363+ ) }
364+ </ Consumer >
365+ Next
366+ < SomeInstance text = "Dynamic text" />
367+ </ Provider >
368+ )
369+
370+ const elements = [ ]
371+ reactTreeWalker ( tree , element => {
372+ elements . push ( element )
373+ } ) . then ( ( ) => {
374+ expect ( elements . pop ( ) ) . toBe ( 'Dynamic text' )
375+ elements . pop ( ) // Pop the div element
376+ elements . pop ( ) // Pop the class instance
377+ expect ( elements . pop ( ) ) . toBe ( 'Next' )
378+ expect ( elements . pop ( ) ) . toBe ( 'This is a provider message: io => io' )
379+ } )
380+ } )
381+
342382 it ( 'supports portals' , ( ) => {
343383 class Foo extends ReactComponent {
344384 getData ( ) {
Original file line number Diff line number Diff line change @@ -113,6 +113,20 @@ export default function reactTreeWalker(
113113 return Promise . resolve ( )
114114 }
115115
116+ if ( currentElement . type ) {
117+ if ( currentElement . type . _context ) {
118+ // eslint-disable-next-line no-param-reassign
119+ currentElement . type . _context . _currentValue =
120+ currentElement . props . value
121+ }
122+ if ( currentElement . type . Provider && currentElement . type . Consumer ) {
123+ const el = currentElement . props . children (
124+ currentElement . type . Provider . _context . _currentValue ,
125+ )
126+ return recursive ( el )
127+ }
128+ }
129+
116130 if ( isReactElement ( currentElement ) ) {
117131 return new Promise ( innerResolve => {
118132 const visitCurrentElement = (
Original file line number Diff line number Diff line change @@ -4197,9 +4197,9 @@ react-dom@^16.0.0:
41974197 object-assign "^4.1.1"
41984198 prop-types "^15.6.0"
41994199
4200- react@^16.0 .0 :
4201- version "16.2 .0"
4202- resolved "https://registry.yarnpkg.com/react/-/react-16.2 .0.tgz#a31bd2dab89bff65d42134fa187f24d054c273ba "
4200+ react@^16.4 .0 :
4201+ version "16.4 .0"
4202+ resolved "https://registry.yarnpkg.com/react/-/react-16.4 .0.tgz#402c2db83335336fba1962c08b98c6272617d585 "
42034203 dependencies :
42044204 fbjs "^0.8.16"
42054205 loose-envify "^1.1.0"
You can’t perform that action at this time.
0 commit comments