From 9e1d6cb7a90dddd41049307d53669014c017ef62 Mon Sep 17 00:00:00 2001 From: Michael Ridgway Date: Fri, 13 Nov 2015 15:07:32 -0800 Subject: [PATCH] [Resolves #58] Reuse router between instances when using only static routes --- lib/RouteStore.js | 5 +++++ tests/unit/lib/RouteStore-test.js | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/lib/RouteStore.js b/lib/RouteStore.js index 4a315bc..1778fe7 100644 --- a/lib/RouteStore.js +++ b/lib/RouteStore.js @@ -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' @@ -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; diff --git a/tests/unit/lib/RouteStore-test.js b/tests/unit/lib/RouteStore-test.js index 2a7d52b..9f77290 100644 --- a/tests/unit/lib/RouteStore-test.js +++ b/tests/unit/lib/RouteStore-test.js @@ -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 () {