/**
 * This file contains epics associated with processing
 * particular types of messages returned from and sent to
 * the Jupyter kernel.
 */ import { StateObservable , ofType } from "redux-observable" ; import { EMPTY , Observable , of } from "rxjs" ; import { switchMap , filter , map , takeUntil , catchError } from "rxjs/operators" ; import * as actions from "@nteract/actions" ; import { inputReply , ofMessageType , JupyterMessage } from "@nteract/messaging" ; import * as selectors from "@nteract/selectors" ; import { AppState } from "@nteract/types" ; param action$ export const updateDisplayEpic = ( action$ ) => action$ . pipe ( ofType ( actions . LAUNCH_KERNEL_SUCCESSFUL ) , switchMap ( ( action ) => ( action as actions . NewKernelAction ) . payload . kernel . channels . pipe ( ofMessageType ( "update_display_data" ) , map ( ( msg ) => actions . updateDisplay ( { content : msg . content , contentRef : ( action as actions . NewKernelAction ) . payload . contentRef } ) ) , takeUntil ( action$ . pipe ( ofType ( actions . KILL_KERNEL_SUCCESSFUL ) , filter ( ( killAction ) => killAction . payload . kernelRef === action . payload . kernelRef ) ) ) , catchError ( ( error ) => of ( actions . updateDisplayFailed ( { error , contentRef : ( action as actions . NewKernelAction ) . payload . contentRef } ) ) ) ) ) ) ; param action$ param state$ export const sendInputReplyEpic = ( action$ , state$ ) => action$ . pipe ( ofType ( actions . SEND_INPUT_REPLY ) , switchMap ( ( action ) => { const state = state$ . value ; const kernel = selectors . kernelByContentRef ( state , { contentRef : action . payload . contentRef } ) ; if ( kernel ) { const reply = inputReply ( { value : action . payload . value } ) ; kernel . channels . next ( reply ) ; } return EMPTY ; } ) ) ;