@@ -91,8 +91,19 @@ exports.default = reactTreeWalker;
91
91
92
92
var _react = __webpack_require__ ( 2 ) ;
93
93
94
+ var defaultOptions = {
95
+ componentWillUnmount : false
96
+ } ;
97
+
94
98
// Lifted from https://github.com/sindresorhus/p-reduce
95
99
// 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
96
107
var pReduce = function pReduce ( iterable , reducer , initVal ) {
97
108
return new Promise ( function ( resolve , reject ) {
98
109
var iterator = iterable [ Symbol . iterator ] ( ) ;
@@ -118,13 +129,6 @@ var pReduce = function pReduce(iterable, reducer, initVal) {
118
129
119
130
// Lifted from https://github.com/sindresorhus/p-map-series
120
131
// 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
128
132
var pMapSeries = function pMapSeries ( iterable , iterator ) {
129
133
var ret = [ ] ;
130
134
@@ -145,6 +149,8 @@ var isPromise = exports.isPromise = function isPromise(x) {
145
149
// If visitor returns `false`, don't call the element's render function
146
150
// or recurse into its child elements
147
151
function reactTreeWalker ( element , visitor , context ) {
152
+ var options = arguments . length > 3 && arguments [ 3 ] !== undefined ? arguments [ 3 ] : defaultOptions ;
153
+
148
154
return new Promise ( function ( resolve ) {
149
155
var doVisit = function doVisit ( getChildren , visitorResult , childContext , isChildren ) {
150
156
var doTraverse = function doTraverse ( shouldContinue ) {
@@ -223,7 +229,21 @@ function reactTreeWalker(element, visitor, context) {
223
229
instance . componentWillMount ( ) ;
224
230
}
225
231
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 ;
227
247
} , visitor ( element , instance , context ) , function ( ) {
228
248
return (
229
249
// Ensure the child context is initialised if it is available. We will
@@ -268,15 +288,15 @@ var _reactTreeWalker2 = _interopRequireDefault(_reactTreeWalker);
268
288
269
289
function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { default : obj } ; }
270
290
271
- function asyncBootstrapper ( app ) {
291
+ function asyncBootstrapper ( app , options ) {
272
292
var visitor = function visitor ( element , instance ) {
273
293
if ( instance && typeof instance . asyncBootstrap === 'function' ) {
274
294
return instance . asyncBootstrap ( ) ;
275
295
}
276
296
return true ;
277
297
} ;
278
298
279
- return ( 0 , _reactTreeWalker2 . default ) ( app , visitor , { } ) ;
299
+ return ( 0 , _reactTreeWalker2 . default ) ( app , visitor , { } , options ) ;
280
300
}
281
301
282
302
/***/ } ) ,
0 commit comments