forked from firefox-devtools/profiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-store.js
36 lines (30 loc) · 1.09 KB
/
create-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
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// @flow
import { createStore, applyMiddleware } from 'redux';
import { thunk } from 'redux-thunk';
import { createLogger } from 'redux-logger';
import reducers from 'firefox-profiler/reducers';
import type { Store } from 'firefox-profiler/types';
/**
* Isolate the store creation into a function, so that it can be used outside of the
* app's execution context, e.g. for testing.
* @return {object} Redux store.
*/
export default function initializeStore(): Store {
const middlewares = [thunk];
if (process.env.NODE_ENV === 'development') {
middlewares.push(
createLogger({
collapsed: true,
titleFormatter: (action, time, duration) =>
`[action] ${action.type} (in ${duration.toFixed(2)} ms)`,
logErrors: false,
duration: true,
})
);
}
const store = createStore(reducers, applyMiddleware(...middlewares));
return store;
}