import { of } from 'rxjs' ; import { filter , switchMap , withLatestFrom } from 'rxjs/operators' ; import { ofType } from 'redux-observable' ; import { getConnectedRobotName } from '../../robot/selectors' ; import * as Actions from '../actions' ; import type { Action , Epic } from '../../types' ; import type { DisconnectAction , UnexpectedDisconnectAction , } from '../../robot/actions' ; export const clearAllSessionsOnDisconnectEpic = ( action$ , state$ ) => { return action$ . pipe ( ofType < Action , DisconnectAction | UnexpectedDisconnectAction > ( 'robot:DISCONNECT' , 'robot:UNEXPECTED_DISCONNECT' ) , withLatestFrom ( state$ , ( _a , s ) => getConnectedRobotName ( s ) ) , filter ( ( robotName ) : robotName is string => { return robotName != null ; } ) , switchMap ( robotName => of ( Actions . clearAllSessions ( robotName ) ) ) ) ; } ;