Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6bf7bb9

Browse files
1.1.0 build files
1 parent 9dcafb6 commit 6bf7bb9

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed

‎commonjs/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ var _reactTreeWalker2 = _interopRequireDefault(_reactTreeWalker);
1111

1212
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1313

14-
function asyncBootstrapper(app) {
14+
function asyncBootstrapper(app,options) {
1515
var visitor = function visitor(element, instance) {
1616
if (instance && typeof instance.asyncBootstrap === 'function') {
1717
return instance.asyncBootstrap();
1818
}
1919
return true;
2020
};
2121

22-
return (0, _reactTreeWalker2.default)(app, visitor, {});
22+
return (0, _reactTreeWalker2.default)(app, visitor, {},options);
2323
}

‎umd/react-async-bootstrapper.js

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,19 @@ exports.default = reactTreeWalker;
9191

9292
var _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
96107
var 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
128132
var 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
147151
function 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

269289
function _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
/***/ }),

‎umd/react-async-bootstrapper.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /