import { default as createSagaMiddleware , SagaMiddleware } from "redux-saga" ; import { IExtension , IItemManager , getRefCountedManager , IModuleManager , } from "redux-dynamic-modules-core" ; import { ISagaRegistration , ISagaModule } from "./Contracts" ; import { getSagaManager } from "./SagaManager" ; import { sagaEquals } from "./SagaComparer" ; param sagaContext export function getSagaExtension < C > ( sagaContext ? , onError ? ) { let sagaMonitor = undefined ; if ( process . env . NODE_ENV === "development" && typeof window !== "undefined" ) { sagaMonitor = window [ "__SAGA_MONITOR_EXTENSION__" ] || undefined ; } let sagaMiddleware = createSagaMiddleware < any > ( { context : sagaContext , sagaMonitor , onError } ) ; let _sagaManager = getRefCountedManager ( getSagaManager ( sagaMiddleware ) , sagaEquals ) ; return { middleware : [ sagaMiddleware ] , onModuleManagerCreated : ( moduleManager ) => { if ( sagaContext ) { sagaContext [ "moduleManager" ] = moduleManager ; } } , onModuleAdded : ( module ) : void => { if ( module . sagas ) { _sagaManager . add ( module . sagas ) ; } } , onModuleRemoved : ( module ) : void => { if ( module . sagas ) { _sagaManager . remove ( module . sagas ) ; } } , dispose : ( ) => { _sagaManager . dispose ( ) ; } } ; }