@@ -97,8 +97,19 @@ exports.default = reactTreeWalker;
97
97
98
98
var _react = __webpack_require__ ( 0 ) ;
99
99
100
+ var defaultOptions = {
101
+ componentWillUnmount : false
102
+ } ;
103
+
100
104
// Lifted from https://github.com/sindresorhus/p-reduce
101
105
// Thanks @sindresorhus !
106
+ /* eslint-disable no-console */
107
+
108
+ // Inspired by the awesome work done by the Apollo team.
109
+ // See https://github.com/apollostack/react-apollo/blob/master/src/server.ts
110
+ // This version has been adapted to be promise based.
111
+
112
+ // eslint-disable-next-line import/no-extraneous-dependencies
102
113
var pReduce = function pReduce ( iterable , reducer , initVal ) {
103
114
return new Promise ( function ( resolve , reject ) {
104
115
var iterator = iterable [ Symbol . iterator ] ( ) ;
@@ -124,13 +135,6 @@ var pReduce = function pReduce(iterable, reducer, initVal) {
124
135
125
136
// Lifted from https://github.com/sindresorhus/p-map-series
126
137
// Thanks @sindresorhus !
127
- /* eslint-disable no-console */
128
-
129
- // Inspired by the awesome work done by the Apollo team.
130
- // See https://github.com/apollostack/react-apollo/blob/master/src/server.ts
131
- // This version has been adapted to be promise based.
132
-
133
- // eslint-disable-next-line import/no-extraneous-dependencies
134
138
var pMapSeries = function pMapSeries ( iterable , iterator ) {
135
139
var ret = [ ] ;
136
140
@@ -151,6 +155,8 @@ var isPromise = exports.isPromise = function isPromise(x) {
151
155
// If visitor returns `false`, don't call the element's render function
152
156
// or recurse into its child elements
153
157
function reactTreeWalker ( element , visitor , context ) {
158
+ var options = arguments . length > 3 && arguments [ 3 ] !== undefined ? arguments [ 3 ] : defaultOptions ;
159
+
154
160
return new Promise ( function ( resolve ) {
155
161
var doVisit = function doVisit ( getChildren , visitorResult , childContext , isChildren ) {
156
162
var doTraverse = function doTraverse ( shouldContinue ) {
@@ -229,7 +235,21 @@ function reactTreeWalker(element, visitor, context) {
229
235
instance . componentWillMount ( ) ;
230
236
}
231
237
232
- return instance . render ( ) ;
238
+ var children = instance . render ( ) ;
239
+
240
+ if ( options . componentWillUnmount && instance . componentWillUnmount ) {
241
+ try {
242
+ instance . componentWillUnmount ( ) ;
243
+ } catch ( err ) {
244
+ // This is an experimental feature, we don't want to break
245
+ // the bootstrapping process, but lets warn the user it
246
+ // occurred.
247
+ console . warn ( 'Error calling componentWillUnmount whilst walking your react tree' ) ;
248
+ console . warn ( err ) ;
249
+ }
250
+ }
251
+
252
+ return children ;
233
253
} , visitor ( element , instance , context ) , function ( ) {
234
254
return (
235
255
// Ensure the child context is initialised if it is available. We will
0 commit comments