Skip to content

Add options to callbacks #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion commonjs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
function asyncBootstrapper(app, options) {
var visitor = function visitor(element, instance) {
if (instance && typeof instance.asyncBootstrap === 'function') {
return instance.asyncBootstrap();
return instance.asyncBootstrap(options);
}
return true;
};
Expand Down
36 changes: 36 additions & 0 deletions src/__tests__/asyncBootstrapper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,40 @@ describe('asyncBootstrapper()', () => {
expect(values).toEqual([1, 2, 4, 3]),
)
})

it('passes options through if given', () => {
const values = []

class Foo extends Component {
asyncBootstrap(options) {
values.push({ ...options, id: this.props.id })
return true
}

render() {
return <div>{this.props.children}</div>
}
}

const app = (
<Foo id={1}>
<div>
<h1>Test</h1>
</div>
<Foo id={2}>
<Foo id={4} />
</Foo>
<Foo id={3} />
</Foo>
)

return asyncBootstrapper(app, { key1: 'val1' }).then(() =>
expect(values).toEqual([
{ id: 1, key1: 'val1' },
{ id: 2, key1: 'val1' },
{ id: 4, key1: 'val1' },
{ id: 3, key1: 'val1' },
]),
)
})
})
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import reactTreeWalker from 'react-tree-walker'
export default function asyncBootstrapper(app, options) {
const visitor = (element, instance) => {
if (instance && typeof instance.asyncBootstrap === 'function') {
return instance.asyncBootstrap()
return instance.asyncBootstrap(options)
}
return true
}
Expand Down
2 changes: 1 addition & 1 deletion umd/react-async-bootstrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
function asyncBootstrapper(app, options) {
var visitor = function visitor(element, instance) {
if (instance && typeof instance.asyncBootstrap === 'function') {
return instance.asyncBootstrap();
return instance.asyncBootstrap(options);
}
return true;
};
Expand Down
2 changes: 1 addition & 1 deletion umd/react-async-bootstrapper.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.