Skip to content
This repository has been archived by the owner on Jul 15, 2019. It is now read-only.

Commit

Permalink
[Resolves #58] Reuse router between instances when using only static …
Browse files Browse the repository at this point in the history
…routes
  • Loading branch information
Michael Ridgway committed Nov 13, 2015
1 parent df2f978 commit 9e1d6cb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/RouteStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ var RouteStore = createStore({
},
rehydrate: function (state) {
this._routes = state.routes;
if (this._routes) {
this._router = null;
}
this._currentUrl = state.currentUrl;
this._currentRoute = this._matchRoute(this._currentUrl, {
method: state.currentNavigate && state.currentNavigate.method || 'GET'
Expand All @@ -138,8 +141,10 @@ var RouteStore = createStore({
});

RouteStore.withStaticRoutes = function (staticRoutes) {
var staticRouter = new Router(staticRoutes);
function StaticRouteStore() {
RouteStore.apply(this, arguments);
this._router = staticRouter;
}
inherits(StaticRouteStore, RouteStore);
StaticRouteStore.storeName = RouteStore.storeName;
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/lib/RouteStore-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ describe('RouteStore', function () {
expect(newStore._routes).to.equal(null);
});
});
it('should reuse static router between instances', function () {
var newStore = new StaticRouteStore();
expect(newStore._router).to.equal(routeStore._router);
});
});

describe('withoutStaticRoutes', function () {
Expand Down

0 comments on commit 9e1d6cb

Please sign in to comment.