From 592e8b1edb0ca0fe0972f47b5a46e1402d1d3c55 Mon Sep 17 00:00:00 2001
From: Chris Beer <cabeer@stanford.edu>
Date: Thu, 7 Feb 2019 13:40:23 -0800
Subject: [PATCH] Move the redux store into the viewer instance

---
 src/lib/MiradorViewer.js | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/lib/MiradorViewer.js b/src/lib/MiradorViewer.js
index b68f8b64e..3bd09c917 100644
--- a/src/lib/MiradorViewer.js
+++ b/src/lib/MiradorViewer.js
@@ -8,7 +8,6 @@ import createStore from '../state/createStore';
 import * as actions from '../state/actions';
 import settings from '../config/settings';
 
-const store = createStore();
 /**
  * Default Mirador instantiation
  */
@@ -16,16 +15,17 @@ class MiradorViewer {
   /**
    */
   constructor(config) {
+    this.store = createStore();
     this.config = config;
     this.processPlugins();
     this.processConfig();
     const viewer = {
       actions,
-      store,
+      store: this.store,
     };
 
     ReactDOM.render(
-      <Provider store={store}>
+      <Provider store={this.store}>
         <App config={config} />
       </Provider>,
       document.getElementById(config.id),
@@ -40,7 +40,7 @@ class MiradorViewer {
   processConfig() {
     const mergedConfig = deepmerge(settings, this.config);
     const action = actions.setConfig(mergedConfig);
-    store.dispatch(action);
+    this.store.dispatch(action);
 
     mergedConfig.windows.forEach((miradorWindow) => {
       let thumbnailNavigationPosition;
@@ -49,8 +49,8 @@ class MiradorViewer {
       } else {
         thumbnailNavigationPosition = mergedConfig.thumbnailNavigation.defaultPosition;
       }
-      store.dispatch(actions.fetchManifest(miradorWindow.loadedManifest));
-      store.dispatch(actions.addWindow({
+      this.store.dispatch(actions.fetchManifest(miradorWindow.loadedManifest));
+      this.store.dispatch(actions.addWindow({
         canvasIndex: (miradorWindow.canvasIndex || 0),
         manifestId: miradorWindow.loadedManifest,
         thumbnailNavigationPosition,
@@ -88,8 +88,8 @@ class MiradorViewer {
     });
 
     actionCreators.forEach((action) => { actions[action.name] = action.action; });
-    reducers.forEach((reducer) => { store.pluginReducers[reducer.name] = reducer.reducer; });
-    store.replaceReducer(createRootReducer(store.pluginReducers));
+    reducers.forEach((reducer) => { this.store.pluginReducers[reducer.name] = reducer.reducer; });
+    this.store.replaceReducer(createRootReducer(this.store.pluginReducers));
   }
 }
 
-- 
GitLab