import { createStore , applyMiddleware } from "redux" ; import thunk from "redux-thunk" ; import { composeWithDevTools } from "redux-devtools-extension" ; import reducer from "./reducers" ; import mediaMiddleware from "./mediaMiddleware" ; import { merge } from "./utils" ; import { UPDATE_TIME_ELAPSED , STEP_MARQUEE } from "./actionTypes" ; import Media from "./media" ; import Emitter from "./emitter" ; import { Extras , Dispatch , Action , Middleware , PartialState } from "./types" ; const compose = composeWithDevTools ( { actionsBlacklist : [ UPDATE_TIME_ELAPSED , STEP_MARQUEE ] , } ) ; export default function ( media , actionEmitter , customMiddlewares = [ ] , stateOverrides , extras ) { let initialState ; if ( stateOverrides ) { initialState = merge ( reducer ( undefined , { type : "@@init" } ) , stateOverrides ) ; } const emitterMiddleware = ( ) => ( next ) => ( action ) => { actionEmitter . trigger ( action . type , action ) ; return next ( action ) ; } ; const enhancer = compose ( applyMiddleware ( ... [ thunk . withExtraArgument ( extras ) , mediaMiddleware ( media ) , emitterMiddleware , ... customMiddlewares , ] . filter ( Boolean ) ) ) ; const store = initialState ? createStore ( reducer , initialState , enhancer ) : createStore ( reducer , enhancer ) ; return store ; }