/
store.js
97 lines (87 loc) 路 2.63 KB
/
store.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* global window */
import createLogger from 'redux-logger';
import promiseMiddleware from 'redux-promise-middleware';
import persistState from 'redux-localstorage';
import thunk from 'redux-thunk';
import { combineReducers, applyMiddleware, createStore, compose } from 'redux';
import { reducer as tooltip, middleware as tooltipMW } from 'redux-tooltip';
import api from './steemAPI';
import MessagesWorker, { messagesReducer } from './messages';
import appReducers from './app/appReducers';
import authReducers from './auth/authReducers';
import commentsReducer from './comments/commentsReducer.js';
import feedReducers from './feed/feedReducers';
import postsReducers from './post/postsReducers';
import userProfileReducer from './user/userReducer';
import notificationReducer from './app/Notification/notificationReducers';
import bookmarksReducer from './bookmarks/bookmarksReducer';
import favoritesReducer from './favorites/favoritesReducers';
import editorReducer from './post/Write/EditorReducers';
import { responsiveReducer, mountResponsive } from './helpers/responsive';
import reblogReducers from './app/Reblog/reblogReducers';
import walletReducer from './wallet/walletReducer';
export const messagesWorker = new MessagesWorker();
if (process.env.NODE_ENV !== 'production') {
window.steemAPI = api;
}
const reducers = combineReducers({
app: appReducers,
auth: authReducers,
comments: commentsReducer,
editor: editorReducer,
posts: postsReducers,
feed: feedReducers,
userProfile: userProfileReducer,
responsive: responsiveReducer,
messages: messagesReducer,
notifications: notificationReducer,
bookmarks: bookmarksReducer,
favorites: favoritesReducer,
reblog: reblogReducers,
wallet: walletReducer,
tooltip,
});
const middleware = [
promiseMiddleware({
promiseTypeSuffixes: [
'START',
'SUCCESS',
'ERROR',
]
}),
thunk.withExtraArgument({
messagesWorker,
steemAPI: api,
}),
tooltipMW
];
if (process.env.ENABLE_LOGGER &&
process.env.IS_BROWSER &&
process.env.NODE_ENV !== 'production') {
middleware.push(createLogger({
collapsed: true,
duration: true,
}));
}
const enhancer = compose(
applyMiddleware(...middleware),
persistState(['favorites', 'editor', 'app'], {
slicer: () => state => ({
favorites: state.favorites,
editor: state.editor,
app: {
locale: state.app.locale,
layout: state.app.layout,
},
}),
})
);
const store = createStore(
reducers,
window.devToolsExtension && window.devToolsExtension(),
enhancer
);
mountResponsive(store);
messagesWorker.attachToStore(store);
messagesWorker.start();
export default store;