E.W.O. Next / All files / src/engine store.ts

24.14% Statements 7/29
0% Branches 0/8
0% Functions 0/3
24.14% Lines 7/29

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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          3x 3x 3x 3x 3x 3x   3x                                                                                            
/**
 * @module Engine
 * Redux Store
 */
 
import { isImmutable } from 'immutable';
import { applyMiddleware, createStore } from 'redux';
import { createLogger } from 'redux-logger';
import reduxThunk from 'redux-thunk';
import { Logger } from './node-logger';
import { rootReducer } from './reducers';
 
export const makeStore = () => {
 
  const hasLog = ['1', 'true', 'action'].includes(process.env.SERVER_LOG);
 
  console.log({ hasLog });
 
  if (hasLog) {
 
    const onlyAction = process.env.SERVER_LOG === 'action';
    console.log({ onlyAction });
 
    const ImmutableStateTransformer = (state) => {
      if (isImmutable(state)) {
        return state.toJS();
      }
 
      return state;
    };
 
    const EmptyStateTransformer = () => {
      return null;
    };
 
    const options: any = {};
 
    options.stateTransformer = onlyAction ? EmptyStateTransformer : ImmutableStateTransformer;
    options.logger = Logger;
 
    if (onlyAction) {
      options.collapsed = true;
      options.duration = true;
    }
 
    const loggerMiddleware = createLogger(options);
 
    const middlewares = [reduxThunk, loggerMiddleware];
 
    store = createStore(rootReducer, applyMiddleware(...middlewares));
  } else {
    const middlewares = [reduxThunk];
 
    store = createStore(rootReducer, applyMiddleware(...middlewares));
  }
};
 
export let store;