import { routerReducer as routing } from 'react-router-redux';
import { reducer as form } from 'redux-form';
import { combineReducers } from 'redux';
import { APP_TOOLS, APP_TOPIC_MAPPER, APP_SOURCE_MANAGER, APP_EXPLORER } from '../config';
import app from './app';
import user from './user';
import topics from './topics/topics';
import explorer from './explorer/explorer';
import sources from './sources/sources';
import system from './system/system';
import notebook from './notebook/notebook';
import story from './story/story';

function getRootReducer(appName) {
  // only load the reducer for the appropriate app
  let appReducer;
  switch (appName) {
    case APP_TOPIC_MAPPER:
      appReducer = topics;
      break;
    case APP_SOURCE_MANAGER:
      appReducer = sources;
      break;
    case APP_EXPLORER:
      appReducer = explorer;
      break;
    case APP_TOOLS:
    default:
      appReducer = null;
      break;
  }

  const defaultReducers = {
    app,
    user,
    system,
    form,
    routing,
    notebook,
    story,
  };

  let reducers = {};
  reducers[appName] = appReducer;
  reducers = Object.assign(reducers, defaultReducers);

  const rootReducer = combineReducers(reducers);

  return rootReducer;
}

export default getRootReducer;

@@ -531,43 +531,172 @@
 ';%0A%0A
-function getRootReducer(appName) %7B%0A
+const LIMIT_REDUCERS = false; // change to true once Topics decoupled from Sources%0A%0Afunction getRootReducer(appName) %7B%0A  let appReducers;%0A  if (LIMIT_REDUCERS) %7B%0A  
   //
@@ -748,24 +748,8 @@
 p%0A  
-let appReducer;%0A
   sw
@@ -761,24 +761,26 @@
 (appName) %7B%0A
+  
     case APP
@@ -792,32 +792,34 @@
 C_MAPPER:%0A      
+  
 appReducer = top
@@ -816,25 +816,30 @@
 ucer
+s
  =
+ %7B
  topics
+ %7D
 ;%0A      
 brea
@@ -826,39 +826,43 @@
 topics %7D;%0A      
+ 
+ 
 break;%0A
+  
     case APP_SOU
@@ -872,32 +872,34 @@
 _MANAGER:%0A      
+  
 appReducer = sou
@@ -896,18 +896,21 @@
 ucer
+s
  =
+ %7B
  sources
 ;%0A  
@@ -905,18 +905,22 @@
  sources
-;%0A
+ %7D;%0A  
       br
@@ -916,32 +916,34 @@
 %0A        break;%0A
+  
     case APP_EXP
@@ -945,24 +945,26 @@
 P_EXPLORER:%0A
+  
       appRed
@@ -967,18 +967,21 @@
 pReducer
+s
  =
+ %7B
  explore
@@ -981,18 +981,22 @@
 explorer
-;%0A
+ %7D;%0A  
       br
@@ -1000,24 +1000,26 @@
  break;%0A    
+ 
+ 
 case APP_TOO
@@ -1026,16 +1026,18 @@
 LS:%0A    
+  
 default:
@@ -1039,24 +1039,26 @@
 ault:%0A      
+ 
+ 
 appReducer =
@@ -1059,17 +1059,18 @@
 ucer
+s
  = 
-null;%0A
+%7B%7D;%0A  
     
@@ -1078,16 +1078,82 @@
  break;%0A
+    %7D%0A  %7D else %7B%0A    appReducers = %7B topics, sources, explorer %7D;%0A
   %7D%0A%0A  c
@@ -1284,33 +1284,12 @@
  = %7B
-%7D;%0A  reducers%5BappName%5D = 
+ ...
 appR
@@ -1294,16 +1294,19 @@
 pReducer
+s %7D
 ;%0A  redu

include all reducers again (#786, #756)