Skip to content

Commit

Permalink
Add optional onChange prop to Switcher
Browse files Browse the repository at this point in the history
- Allows for a function to be provided and called when the route changes
  • Loading branch information
jdlehman committed Apr 4, 2015
1 parent 14aafea commit 2f0c5d0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dist/switcheroo.min.js

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

12 changes: 9 additions & 3 deletions modules/components/Switcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,15 @@ export default class Switcher extends Component {
}

handleRouteChange(e) {
var newRoute = this.getLocation();
var newRoute = this.getLocation(),
switchElement = this.getSwitch(newRoute);
this.setState({
visibleComponent: this.getSwitch(newRoute)
visibleComponent: switchElement
});

if(typeof this.props.onChange === 'function') {
this.props.onChange(!!switchElement, newRoute);
}
}

render() {
Expand All @@ -80,7 +85,8 @@ Switcher.propTypes = {
children: React.PropTypes.arrayOf(React.PropTypes.element).isRequired,
pushState: React.PropTypes.bool,
defaultHandler: React.PropTypes.func,
defaultHandlerProps: React.PropTypes.object
defaultHandlerProps: React.PropTypes.object,
onChange: React.PropTypes.func
};

Switcher.defaultProps = {
Expand Down

0 comments on commit 2f0c5d0

Please sign in to comment.