1- var ActiveStore = require ( '../stores/ActiveStore' ) ;
1+ var React = require ( 'react' ) ;
2+ var ActiveDelegate = require ( './ActiveDelegate' ) ;
23
34/**
45 * A mixin for components that need to know about the routes, params,
56 * and query that are currently active. Components that use it get two
67 * things:
78 *
8- * 1. An `isActive` static method they can use to check if a route,
9- * params, and query are active.
10- * 2. An `updateActiveState` instance method that is called when the
9+ * 1. An `updateActiveState` method that is called when the
1110 * active state changes.
11+ * 2. An `isActive` method they can use to check if a route,
12+ * params, and query are active.
13+ *
1214 *
1315 * Example:
1416 *
@@ -24,40 +26,45 @@ var ActiveStore = require('../stores/ActiveStore');
2426 *
2527 * updateActiveState: function () {
2628 * this.setState({
27- * isActive: Tab .isActive(routeName, params, query)
29+ * isActive: this .isActive(routeName, params, query)
2830 * })
2931 * }
3032 *
3133 * });
3234 */
3335var ActiveState = {
3436
35- statics : {
36-
37- /**
38- * Returns true if the route with the given name, URL parameters, and query
39- * are all currently active.
40- */
41- isActive : ActiveStore . isActive
42-
37+ contextTypes : {
38+ activeDelegate : React . PropTypes . any . isRequired
4339 } ,
4440
45- componentWillMount : function ( ) {
46- ActiveStore . addChangeListener ( this . handleActiveStateChange ) ;
41+ /**
42+ * Returns this component's ActiveDelegate component.
43+ */
44+ getActiveDelegate : function ( ) {
45+ return this . context . activeDelegate ;
4746 } ,
4847
4948 componentDidMount : function ( ) {
50- if ( this . updateActiveState )
51- this . updateActiveState ( ) ;
49+ this . getActiveDelegate ( ) . addChangeListener ( this . handleActiveStateChange ) ;
50+ this . handleActiveStateChange ( ) ;
5251 } ,
5352
5453 componentWillUnmount : function ( ) {
55- ActiveStore . removeChangeListener ( this . handleActiveStateChange ) ;
54+ this . getActiveDelegate ( ) . removeChangeListener ( this . handleActiveStateChange ) ;
5655 } ,
5756
5857 handleActiveStateChange : function ( ) {
5958 if ( this . isMounted ( ) && typeof this . updateActiveState === 'function' )
6059 this . updateActiveState ( ) ;
60+ } ,
61+
62+ /**
63+ * Returns true if the route with the given name, URL parameters, and
64+ * query are all currently active.
65+ */
66+ isActive : function ( routeName , params , query ) {
67+ return this . getActiveDelegate ( ) . isActive ( routeName , params , query ) ;
6168 }
6269
6370} ;
0 commit comments