Skip to content

Commit 2c1c177

Browse files
committed
Exposes a 'reactAsyncBootstrapperRunning' to the component tree when executing.
1 parent 21848a8 commit 2c1c177

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/__tests__/asyncBootstrapper.test.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('asyncBootstrapper()', () => {
2222
class NewAPI extends Component {
2323
bootstrap() {
2424
values.push(this.props.id)
25-
actualContext = this.context.isBootstrapping
25+
actualContext = this.context
2626
return true
2727
}
2828

@@ -53,8 +53,11 @@ describe('asyncBootstrapper()', () => {
5353
))
5454

5555
it('new API', () =>
56-
asyncBootstrapper(app(NewAPI), null, { isBootstrapping: true }).then(() => {
56+
asyncBootstrapper(app(NewAPI), null, { bespokeContext: true }).then(() => {
5757
expect(values).toEqual([1, 2, 4, 3])
58-
expect(actualContext).toBe(true)
58+
expect(actualContext).toEqual({
59+
bespokeContext: true,
60+
reactAsyncBootstrapperRunning: true,
61+
})
5962
}))
6063
})

src/index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import reactTreeWalker from 'react-tree-walker'
55
const warnmsg =
66
'"react-async-bootstrapper" deprecation notice: please rename your "asyncBootsrap" methods to "bootstrap"'
77

8+
const defaultContext = {
9+
reactAsyncBootstrapperRunning: true,
10+
}
11+
812
export default function asyncBootstrapper(app, options, context = {}) {
913
const visitor = (element, instance) => {
1014
if (
@@ -19,5 +23,10 @@ export default function asyncBootstrapper(app, options, context = {}) {
1923
return undefined
2024
}
2125

22-
return reactTreeWalker(app, visitor, context, options)
26+
return reactTreeWalker(
27+
app,
28+
visitor,
29+
Object.assign({}, context, defaultContext),
30+
options,
31+
)
2332
}

0 commit comments

Comments
 (0)