client/src/store/configureStore.js
author Alexandre Segura <mex.zktk@gmail.com>
Mon, 12 Jun 2017 18:12:38 +0200
changeset 29 4cfeabef7d5e
parent 14 df6780e48eb5
child 44 3b20e2b584fe
permissions -rw-r--r--
Store data in PouchDB. - Introduce redux-saga to perform async actions. - Refactor actions to be async.

import rootReducer from '../reducers';
import rootSaga from '../sagas';
import { loadSessions } from '../actions/sessionsActions';
import { createStore, applyMiddleware } from 'redux';
import { routerMiddleware } from 'react-router-redux';
import createSagaMiddleware from 'redux-saga'
import Immutable from 'immutable';

const defaultState = {
  currentSession: null,
  sessions: Immutable.List([]),
  notes: Immutable.List([]),
  isAuthenticated: false,
};

const storeInitialState = Immutable.Map(defaultState);

export default (history, initialState = storeInitialState) => {

  const router = routerMiddleware(history);
  const saga = createSagaMiddleware();

  const store = createStore(rootReducer, initialState, applyMiddleware(router, saga));

  saga.run(rootSaga)

  store.dispatch(loadSessions());

  return store;
};