@@ -91,8 +91,19 @@ exports.default = reactTreeWalker;
9191
9292var _react = __webpack_require__ ( 2 ) ;
9393
94+ var defaultOptions = {
95+ componentWillUnmount : false
96+ } ;
97+
9498// Lifted from https://github.com/sindresorhus/p-reduce
9599// Thanks @sindresorhus !
100+ /* eslint-disable no-console */
101+
102+ // Inspired by the awesome work done by the Apollo team.
103+ // See https://github.com/apollostack/react-apollo/blob/master/src/server.ts
104+ // This version has been adapted to be promise based.
105+
106+ // eslint-disable-next-line import/no-extraneous-dependencies
96107var pReduce = function pReduce ( iterable , reducer , initVal ) {
97108 return new Promise ( function ( resolve , reject ) {
98109 var iterator = iterable [ Symbol . iterator ] ( ) ;
@@ -118,13 +129,6 @@ var pReduce = function pReduce(iterable, reducer, initVal) {
118129
119130// Lifted from https://github.com/sindresorhus/p-map-series
120131// Thanks @sindresorhus !
121- /* eslint-disable no-console */
122-
123- // Inspired by the awesome work done by the Apollo team.
124- // See https://github.com/apollostack/react-apollo/blob/master/src/server.ts
125- // This version has been adapted to be promise based.
126-
127- // eslint-disable-next-line import/no-extraneous-dependencies
128132var pMapSeries = function pMapSeries ( iterable , iterator ) {
129133 var ret = [ ] ;
130134
@@ -145,6 +149,8 @@ var isPromise = exports.isPromise = function isPromise(x) {
145149// If visitor returns `false`, don't call the element's render function
146150// or recurse into its child elements
147151function reactTreeWalker ( element , visitor , context ) {
152+ var options = arguments . length > 3 && arguments [ 3 ] !== undefined ? arguments [ 3 ] : defaultOptions ;
153+
148154 return new Promise ( function ( resolve ) {
149155 var doVisit = function doVisit ( getChildren , visitorResult , childContext , isChildren ) {
150156 var doTraverse = function doTraverse ( shouldContinue ) {
@@ -223,7 +229,21 @@ function reactTreeWalker(element, visitor, context) {
223229 instance . componentWillMount ( ) ;
224230 }
225231
226- return instance . render ( ) ;
232+ var children = instance . render ( ) ;
233+
234+ if ( options . componentWillUnmount && instance . componentWillUnmount ) {
235+ try {
236+ instance . componentWillUnmount ( ) ;
237+ } catch ( err ) {
238+ // This is an experimental feature, we don't want to break
239+ // the bootstrapping process, but lets warn the user it
240+ // occurred.
241+ console . warn ( 'Error calling componentWillUnmount whilst walking your react tree' ) ;
242+ console . warn ( err ) ;
243+ }
244+ }
245+
246+ return children ;
227247 } , visitor ( element , instance , context ) , function ( ) {
228248 return (
229249 // Ensure the child context is initialised if it is available. We will
@@ -268,15 +288,15 @@ var _reactTreeWalker2 = _interopRequireDefault(_reactTreeWalker);
268288
269289function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { default : obj } ; }
270290
271- function asyncBootstrapper ( app ) {
291+ function asyncBootstrapper ( app , options ) {
272292 var visitor = function visitor ( element , instance ) {
273293 if ( instance && typeof instance . asyncBootstrap === 'function' ) {
274294 return instance . asyncBootstrap ( ) ;
275295 }
276296 return true ;
277297 } ;
278298
279- return ( 0 , _reactTreeWalker2 . default ) ( app , visitor , { } ) ;
299+ return ( 0 , _reactTreeWalker2 . default ) ( app , visitor , { } , options ) ;
280300}
281301
282302/***/ } ) ,
0 commit comments