| author | ymh <ymh.work@gmail.com> |
| Thu, 03 Aug 2017 17:33:00 +0200 | |
| changeset 134 | be36eed5e6e0 |
| parent 132 | 906a6c7c7943 |
| child 168 | ea92f4fe783d |
| permissions | -rw-r--r-- |
| 1 | 1 |
import rootReducer from '../reducers'; |
|
87
dbcee57de2c6
Add first implementation of network monitor
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
2 |
import rootAuthSaga from '../sagas/authSaga'; |
|
100
6fd752d98933
Introduce group creation.
Alexandre Segura <mex.zktk@gmail.com>
parents:
91
diff
changeset
|
3 |
import rootGroupSaga from '../sagas/groupSaga'; |
|
129
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
101
diff
changeset
|
4 |
import rootSyncSaga from '../sagas/syncSaga'; |
|
87
dbcee57de2c6
Add first implementation of network monitor
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
5 |
import networkSaga from '../sagas/networkSaga'; |
|
62
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
59
diff
changeset
|
6 |
import { compose, createStore, applyMiddleware } from 'redux'; |
|
12
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
3
diff
changeset
|
7 |
import { routerMiddleware } from 'react-router-redux'; |
|
29
4cfeabef7d5e
Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
14
diff
changeset
|
8 |
import createSagaMiddleware from 'redux-saga' |
| 1 | 9 |
import Immutable from 'immutable'; |
|
129
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
101
diff
changeset
|
10 |
import {persistStore, autoRehydrate} from 'redux-persist-immutable' |
|
62
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
59
diff
changeset
|
11 |
import localForage from 'localforage'; |
| 67 | 12 |
import immutableTransform from 'redux-persist-transform-immutable'; |
13 |
import NoteRecord from './noteRecord'; |
|
14 |
import SessionRecord from './sessionRecord'; |
|
15 |
import UserRecord from './userRecord'; |
|
|
132
906a6c7c7943
add group to sync + create groups + various component cleaning
ymh <ymh.work@gmail.com>
parents:
129
diff
changeset
|
16 |
import GroupRecord from './groupRecord'; |
|
62
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
59
diff
changeset
|
17 |
import APIClient from '../api/APIClient'; |
| 55 | 18 |
import config from '../config'; |
| 91 | 19 |
import asyncRequest from '../constants/asyncRequest'; |
| 1 | 20 |
|
|
129
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
101
diff
changeset
|
21 |
const composeEnhancers = (process.env.NODE_ENV !== 'production' && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) ? |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
101
diff
changeset
|
22 |
window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({ |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
101
diff
changeset
|
23 |
shouldHotReload: false, |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
101
diff
changeset
|
24 |
}) : compose; |
|
62
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
59
diff
changeset
|
25 |
|
| 47 | 26 |
|
|
12
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
3
diff
changeset
|
27 |
const defaultState = { |
|
29
4cfeabef7d5e
Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
14
diff
changeset
|
28 |
sessions: Immutable.List([]), |
|
4cfeabef7d5e
Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
14
diff
changeset
|
29 |
notes: Immutable.List([]), |
|
100
6fd752d98933
Introduce group creation.
Alexandre Segura <mex.zktk@gmail.com>
parents:
91
diff
changeset
|
30 |
groups: Immutable.List([]), |
|
129
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
101
diff
changeset
|
31 |
status: Immutable.Map({ |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
101
diff
changeset
|
32 |
isSynchronizing: false, |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
101
diff
changeset
|
33 |
online: false |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
101
diff
changeset
|
34 |
}), |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
101
diff
changeset
|
35 |
authStatus: Immutable.Map({ |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
101
diff
changeset
|
36 |
token: '', |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
101
diff
changeset
|
37 |
isAuthenticated: false, |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
101
diff
changeset
|
38 |
clientId: null, |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
101
diff
changeset
|
39 |
lastSync: 0, |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
101
diff
changeset
|
40 |
currentUser: null, |
|
134
be36eed5e6e0
add menu to change current group and create a new group
ymh <ymh.work@gmail.com>
parents:
132
diff
changeset
|
41 |
currentGroup: null |
|
129
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
101
diff
changeset
|
42 |
}), |
|
72
7634b424f426
Add checkbox to add not on enter key.
Alexandre Segura <mex.zktk@gmail.com>
parents:
68
diff
changeset
|
43 |
autoSubmit: false, |
| 91 | 44 |
login: asyncRequest, |
45 |
register: asyncRequest, |
|
|
100
6fd752d98933
Introduce group creation.
Alexandre Segura <mex.zktk@gmail.com>
parents:
91
diff
changeset
|
46 |
createGroup: asyncRequest |
| 1 | 47 |
}; |
|
12
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
3
diff
changeset
|
48 |
|
|
62
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
59
diff
changeset
|
49 |
const immutableTransformConfig = { |
|
132
906a6c7c7943
add group to sync + create groups + various component cleaning
ymh <ymh.work@gmail.com>
parents:
129
diff
changeset
|
50 |
records: [NoteRecord, SessionRecord, UserRecord, GroupRecord], |
|
906a6c7c7943
add group to sync + create groups + various component cleaning
ymh <ymh.work@gmail.com>
parents:
129
diff
changeset
|
51 |
whitelist: ['sessions', 'notes', 'authStatus', 'groups'] |
|
62
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
59
diff
changeset
|
52 |
} |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
59
diff
changeset
|
53 |
|
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
59
diff
changeset
|
54 |
const persistOptions = { |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
59
diff
changeset
|
55 |
storage: localForage, |
|
132
906a6c7c7943
add group to sync + create groups + various component cleaning
ymh <ymh.work@gmail.com>
parents:
129
diff
changeset
|
56 |
records: [NoteRecord, SessionRecord, UserRecord, GroupRecord], |
|
62
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
59
diff
changeset
|
57 |
transforms: [immutableTransform(immutableTransformConfig)], |
|
132
906a6c7c7943
add group to sync + create groups + various component cleaning
ymh <ymh.work@gmail.com>
parents:
129
diff
changeset
|
58 |
whitelist: ['sessions', 'notes', 'autoSubmit', 'authStatus', 'groups'] |
|
62
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
59
diff
changeset
|
59 |
} |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
59
diff
changeset
|
60 |
|
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
59
diff
changeset
|
61 |
const apiClient = new APIClient(config.apiRootUrl); |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
59
diff
changeset
|
62 |
|
|
129
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
101
diff
changeset
|
63 |
const storeInitialState = Immutable.Map({ ...defaultState }); |
|
62
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
59
diff
changeset
|
64 |
|
|
12
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
3
diff
changeset
|
65 |
|
|
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
3
diff
changeset
|
66 |
export default (history, initialState = storeInitialState) => { |
|
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
3
diff
changeset
|
67 |
|
|
29
4cfeabef7d5e
Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
14
diff
changeset
|
68 |
const router = routerMiddleware(history); |
|
4cfeabef7d5e
Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
14
diff
changeset
|
69 |
const saga = createSagaMiddleware(); |
|
12
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
3
diff
changeset
|
70 |
|
|
129
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
101
diff
changeset
|
71 |
const store = createStore(rootReducer, initialState, composeEnhancers( |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
101
diff
changeset
|
72 |
applyMiddleware(router, saga), |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
101
diff
changeset
|
73 |
autoRehydrate() |
|
44
3b20e2b584fe
Introduce authentication through API.
Alexandre Segura <mex.zktk@gmail.com>
parents:
29
diff
changeset
|
74 |
)); |
|
12
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
3
diff
changeset
|
75 |
|
|
62
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
59
diff
changeset
|
76 |
apiClient.setStore(store); |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
59
diff
changeset
|
77 |
|
| 55 | 78 |
const context = { |
|
62
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
59
diff
changeset
|
79 |
client: apiClient, |
|
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
59
diff
changeset
|
80 |
history |
| 55 | 81 |
} |
82 |
||
|
129
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
101
diff
changeset
|
83 |
persistStore(store, persistOptions); |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
101
diff
changeset
|
84 |
|
|
87
dbcee57de2c6
Add first implementation of network monitor
ymh <ymh.work@gmail.com>
parents:
74
diff
changeset
|
85 |
saga.run(rootAuthSaga, context); |
|
100
6fd752d98933
Introduce group creation.
Alexandre Segura <mex.zktk@gmail.com>
parents:
91
diff
changeset
|
86 |
saga.run(rootGroupSaga, context); |
|
129
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
101
diff
changeset
|
87 |
saga.run(rootSyncSaga, context); |
|
d48946d164c6
Add a first version of synchronisation
ymh <ymh.work@gmail.com>
parents:
101
diff
changeset
|
88 |
saga.run(networkSaga, context); |
|
29
4cfeabef7d5e
Store data in PouchDB.
Alexandre Segura <mex.zktk@gmail.com>
parents:
14
diff
changeset
|
89 |
|
|
12
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
3
diff
changeset
|
90 |
return store; |
|
48ddaa42b810
Draft implementation of sessions.
Alexandre Segura <mex.zktk@gmail.com>
parents:
3
diff
changeset
|
91 |
}; |