diff --git a/modules/mixins/ActiveState.js b/modules/mixins/ActiveState.js index 2e9298d752..9e0ecaf2da 100644 --- a/modules/mixins/ActiveState.js +++ b/modules/mixins/ActiveState.js @@ -1,29 +1,5 @@ var ActiveStore = require('../stores/ActiveStore'); -function routeIsActive(activeRoutes, routeName) { - return activeRoutes.some(function (route) { - return route.props.name === routeName; - }); -} - -function paramsAreActive(activeParams, params) { - for (var property in params) { - if (activeParams[property] !== String(params[property])) - return false; - } - - return true; -} - -function queryIsActive(activeQuery, query) { - for (var property in query) { - if (activeQuery[property] !== String(query[property])) - return false; - } - - return true; -} - /** * A mixin for components that need to know about the routes, params, * and query that are currently active. Components that use it get two @@ -62,15 +38,7 @@ var ActiveState = { * Returns true if the route with the given name, URL parameters, and query * are all currently active. */ - isActive: function (routeName, params, query) { - var state = ActiveStore.getState(); - var isActive = routeIsActive(state.routes, routeName) && paramsAreActive(state.params, params); - - if (query) - return isActive && queryIsActive(state.query, query); - - return isActive; - } + isActive: ActiveStore.isActive }, diff --git a/modules/stores/ActiveStore.js b/modules/stores/ActiveStore.js index 9a5b5390b4..8925d8b9ee 100644 --- a/modules/stores/ActiveStore.js +++ b/modules/stores/ActiveStore.js @@ -2,6 +2,30 @@ var _activeRoutes = []; var _activeParams = {}; var _activeQuery = {}; +function routeIsActive(routeName) { + return _activeRoutes.some(function (route) { + return route.props.name === routeName; + }); +} + +function paramsAreActive(params) { + for (var property in params) { + if (_activeParams[property] !== String(params[property])) + return false; + } + + return true; +} + +function queryIsActive(query) { + for (var property in query) { + if (_activeQuery[property] !== String(query[property])) + return false; + } + + return true; +} + var EventEmitter = require('event-emitter'); var _events = EventEmitter(); @@ -45,15 +69,16 @@ var ActiveStore = { }, /** - * Returns an object with the currently active `routes`, `params`, - * and `query`. + * Returns true if the route with the given name, URL parameters, and query + * are all currently active. */ - getState: function () { - return { - routes: _activeRoutes, - params: _activeParams, - query: _activeQuery - }; + isActive: function (routeName, params, query) { + var isActive = routeIsActive(routeName) && paramsAreActive(params); + + if (query) + return isActive && queryIsActive(query); + + return isActive; } }; diff --git a/specs/ActiveStore.spec.js b/specs/ActiveStore.spec.js index d5c5077697..3d52c30bfd 100644 --- a/specs/ActiveStore.spec.js +++ b/specs/ActiveStore.spec.js @@ -17,7 +17,7 @@ describe('when a Route is active', function () { describe('and it has no params', function () { beforeEach(function () { - ActiveStore.update({ + ActiveStore.updateState({ activeRoutes: [ route ] }); }); @@ -29,7 +29,7 @@ describe('when a Route is active', function () { describe('and the right params are given', function () { beforeEach(function () { - ActiveStore.update({ + ActiveStore.updateState({ activeRoutes: [ route ], activeParams: { id: '123', show: 'true' }, activeQuery: { search: 'abc' } @@ -57,7 +57,7 @@ describe('when a Route is active', function () { describe('and the wrong params are given', function () { beforeEach(function () { - ActiveStore.update({ + ActiveStore.updateState({ activeRoutes: [ route ], activeParams: { id: 123 } });