react-crossroads
Version:
Client side router for web applications built with React and utilizing the Flux architecture. The backing routing engine is CrossroadsJs.
31 lines (27 loc) • 827 B
JavaScript
var ActiveState, React;
React = require('react');
ActiveState = {
contextTypes: {
router: React.PropTypes.object.isRequired
},
componentWillMount: function() {
return this.context.router.stores.route.addChangeListener(this.handleActiveStateChange);
},
componentDidMount: function() {
if (this.updateActiveState != null) {
return this.updateActiveState();
}
},
componentWillUnmount: function() {
return this.context.router.stores.route.removeChangeListener(this.handleActiveStateChange);
},
isActive: function(to, params) {
return this.context.router.stores.route.isActive(to, params);
},
handleActiveStateChange: function() {
if (this.isMounted() && (this.updateActiveState != null)) {
return this.updateActiveState();
}
}
};
module.exports = ActiveState;