blob: 5cab6ae5614353d59b3ee2ef6187868fd6a02fd4 [file] [log] [blame]
svishnev1eb66b72018-01-11 14:39:45 +02001/*
2 * Copyright © 2016-2017 European Support Limited
AviZi280f8012017-06-09 02:39:56 +03003 *
Michael Landoefa037d2017-02-19 12:57:33 +02004 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
svishnev1eb66b72018-01-11 14:39:45 +02007 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
Michael Landoefa037d2017-02-19 12:57:33 +020010 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
svishnev1eb66b72018-01-11 14:39:45 +020012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
Michael Landoefa037d2017-02-19 12:57:33 +020015 */
16
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020017import { createStore, applyMiddleware, compose } from 'redux';
svishnev1eb66b72018-01-11 14:39:45 +020018import Reducers from './Reducers.js';
svishnevea5e43c2018-04-15 09:06:57 +030019import filterUpdater from 'sdc-app/onboarding/onboard/filter/FilterMiddleware.js';
20
AviZi280f8012017-06-09 02:39:56 +030021const thunk = store => next => action =>
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020022 typeof action === 'function'
23 ? action(store.dispatch, store.getState)
24 : next(action);
AviZi280f8012017-06-09 02:39:56 +030025
26const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
svishnevea5e43c2018-04-15 09:06:57 +030027
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020028export const storeCreator = initialState =>
29 createStore(
30 Reducers,
31 initialState,
svishnevea5e43c2018-04-15 09:06:57 +030032 composeEnhancers(applyMiddleware(thunk, filterUpdater))
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020033 );
Michael Landoefa037d2017-02-19 12:57:33 +020034
35const store = storeCreator();
36
svishnev1eb66b72018-01-11 14:39:45 +020037if (module.hot) {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020038 module.hot.accept('./Reducers.js', () =>
39 store.replaceReducer(require('./Reducers.js').default)
40 );
svishnev1eb66b72018-01-11 14:39:45 +020041}
42
Michael Landoefa037d2017-02-19 12:57:33 +020043export default store;