Skip to content

Commit

Permalink
ensure dispatch is defined before dispatching focus actions
Browse files Browse the repository at this point in the history
  • Loading branch information
lynndylanhurley committed Feb 11, 2016
1 parent c2fec74 commit a58e9fb
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions Router.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,29 @@ export default class Router extends React.Component {
componentDidMount(){
this.router.delegate = this.refs.router;

this.router.delegate.refs.nav.navigationContext.addListener('willfocus', function (ev) {
let name = ev.data.route.name;
let title = ev.data.route.title;

this.props.dispatch({
type: Actions.BEFORE_FOCUS,
name: name,
title: title
});
}.bind(this));

this.router.delegate.refs.nav.navigationContext.addListener('didfocus', function (ev) {
let name = ev.data.route.name;
let title = ev.data.route.title;

this.props.dispatch({
type: Actions.AFTER_FOCUS,
name: name,
title: title
});
}.bind(this));
if (this.props.dispatch) {
this.router.delegate.refs.nav.navigationContext.addListener('willfocus', function (ev) {
let name = ev.data.route.name;
let title = ev.data.route.title;

this.props.dispatch({
type: Actions.BEFORE_FOCUS,
name: name,
title: title
});
}.bind(this));

this.router.delegate.refs.nav.navigationContext.addListener('didfocus', function (ev) {
let name = ev.data.route.name;
let title = ev.data.route.title;

this.props.dispatch({
type: Actions.AFTER_FOCUS,
name: name,
title: title
});
}.bind(this));
}
}

render(){
Expand Down

0 comments on commit a58e9fb

Please sign in to comment.