client/src/store/configureStore.js
changeset 87 dbcee57de2c6
parent 74 043477fd5c5c
child 89 06f609adfbf8
equal deleted inserted replaced
86:fa8ef84a1780 87:dbcee57de2c6
     1 import rootReducer from '../reducers';
     1 import rootReducer from '../reducers';
     2 import rootSaga from '../sagas';
     2 import rootAuthSaga from '../sagas/authSaga';
       
     3 import networkSaga from '../sagas/networkSaga';
     3 import { compose, createStore, applyMiddleware } from 'redux';
     4 import { compose, createStore, applyMiddleware } from 'redux';
     4 import { routerMiddleware } from 'react-router-redux';
     5 import { routerMiddleware } from 'react-router-redux';
     5 import createSagaMiddleware from 'redux-saga'
     6 import createSagaMiddleware from 'redux-saga'
     6 import Immutable from 'immutable';
     7 import Immutable from 'immutable';
     7 import { offline } from 'redux-offline';
     8 import { offline } from 'redux-offline';
    12 import SessionRecord from './sessionRecord';
    13 import SessionRecord from './sessionRecord';
    13 import UserRecord from './userRecord';
    14 import UserRecord from './userRecord';
    14 import APIClient from '../api/APIClient';
    15 import APIClient from '../api/APIClient';
    15 import createEffect from '../api';
    16 import createEffect from '../api';
    16 import config from '../config';
    17 import config from '../config';
       
    18 import { offlineConfigInitialized } from '../actions/networkActions';
    17 
    19 
    18 // const composeEnhancers = (process.env.NODE_ENV !== 'production' && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) ?
    20 // const composeEnhancers = (process.env.NODE_ENV !== 'production' && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) ?
    19 //     window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({
    21 //     window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({
    20 //         shouldHotReload: false,
    22 //         shouldHotReload: false,
    21 //     }) : compose;
    23 //     }) : compose;
    51 
    53 
    52 const offlineConfig = {
    54 const offlineConfig = {
    53   ...offlineDefaultConfig,
    55   ...offlineDefaultConfig,
    54   persistOptions,
    56   persistOptions,
    55   effect: createEffect(apiClient),
    57   effect: createEffect(apiClient),
    56 //  detectNetwork: callback => callback(true),
       
    57 }
    58 }
    58 
    59 
    59 const storeInitialState = { ...defaultState };
    60 const storeInitialState = { ...defaultState };
    60 
    61 
    61 
    62 
    62 export default (history, initialState = storeInitialState) => {
    63 export default (history, initialState = storeInitialState) => {
    63 
    64 
    64   const router = routerMiddleware(history);
    65   const router = routerMiddleware(history);
    65   const saga = createSagaMiddleware();
    66   const saga = createSagaMiddleware();
       
    67 
       
    68   offlineConfig.detectNetwork = callback => { saga.run(networkSaga, { callback }); };
    66 
    69 
    67   const store = offline(offlineConfig)(createStore)(rootReducer, initialState, composeEnhancers(
    70   const store = offline(offlineConfig)(createStore)(rootReducer, initialState, composeEnhancers(
    68     applyMiddleware(router, saga)
    71     applyMiddleware(router, saga)
    69   ));
    72   ));
    70 
    73 
    73   const context = {
    76   const context = {
    74     client: apiClient,
    77     client: apiClient,
    75     history
    78     history
    76   }
    79   }
    77 
    80 
    78   saga.run(rootSaga, context);
    81   saga.run(rootAuthSaga, context);
       
    82 
       
    83   store.dispatch(offlineConfigInitialized({ client: apiClient }))
    79 
    84 
    80   return store;
    85   return store;
    81 };
    86 };