src/domain/task/store/store.ts

Summary

Maintainability
A
0 mins
Test Coverage
import type { Action, Store } from 'redux'
import { applyMiddleware, legacy_createStore } from 'redux'
import { composeWithDevTools } from 'redux-devtools-extension'
import type { ThunkAction, ThunkDispatch, ThunkMiddleware } from 'redux-thunk'
import thunk from 'redux-thunk'
import type { EventBus } from 'ts-bus'
import type { AppState } from './appState'
import rootReducer from './reducer/task.reducer'
import { eventBusMiddleware } from 'domain/common/store.helper'
import type { DeepReadonly } from 'superTypes'

export const configureStore = (
  eventBus: DeepReadonly<EventBus>,
  preloadedState?: DeepReadonly<ReturnType<typeof rootReducer>>
): Store<AppState> =>
  legacy_createStore(
    rootReducer,
    preloadedState,
    composeWithDevTools(
      applyMiddleware(
        thunk as ThunkMiddleware<AppState, Action>,
        eventBusMiddleware(eventBus, 'domain:task')
      )
    )
  )

export type ReduxStore = Store<AppState> & {
  readonly dispatch: ThunkDispatch<AppState, undefined, Action>
}
export type ThunkResult<R> = ThunkAction<R, AppState, undefined, Action>