--- a/client/src/store/configureStore.js Mon Jun 19 18:32:27 2017 +0200
+++ b/client/src/store/configureStore.js Mon Jun 19 21:37:33 2017 +0200
@@ -1,11 +1,16 @@
import rootReducer from '../reducers';
import rootSaga from '../sagas';
import { loadSessions } from '../actions/sessionsActions';
-import { createStore, applyMiddleware, compose } from 'redux';
+import { compose, createStore, applyMiddleware } from 'redux';
import { routerMiddleware } from 'react-router-redux';
import handleTransitions from 'redux-history-transitions';
import createSagaMiddleware from 'redux-saga'
import Immutable from 'immutable';
+import { offline } from 'redux-offline';
+import offlineDefaultConfig from 'redux-offline/lib/defaults';
+import localForage from 'localforage';
+import immutableTransform from 'redux-persist-transform-immutable'
+import NoteRecord from './noteRecord'
import APIClient from '../APIClient';
import config from '../config';
@@ -13,7 +18,7 @@
const currentUser = localStorage.getItem('currentUser');
const defaultState = {
- currentSession: null,
+// currentSession: null,
sessions: Immutable.List([]),
notes: Immutable.List([]),
isAuthenticated: token !== null,
@@ -26,7 +31,23 @@
}
};
-const storeInitialState = Immutable.Map(defaultState);
+const immutableTransformConfig = {
+ records: [NoteRecord],
+ whitelist: ['sessions', 'notes']
+}
+
+const offlineConfig = {
+ ...offlineDefaultConfig,
+ persistOptions: {
+ storage: localForage,
+ transforms: [immutableTransform(immutableTransformConfig)]
+ },
+ detectNetwork: callback => callback(true),
+}
+
+//const storeInitialState = Immutable.Map(defaultState);
+//const storeInitialState = new Map(defaultState);
+const storeInitialState = defaultState;
export default (history, initialState = storeInitialState) => {
@@ -34,7 +55,7 @@
const saga = createSagaMiddleware();
const transitions = handleTransitions(history);
- const store = createStore(rootReducer, initialState, compose(
+ const store = offline(offlineConfig)(createStore)(rootReducer, initialState, compose(
applyMiddleware(router, saga),
transitions
));
@@ -45,7 +66,7 @@
saga.run(rootSaga, context);
- store.dispatch(loadSessions());
+ //store.dispatch(loadSessions());
return store;
};