import { ofType } from 'redux-observable' ; import { POST } from '../../robot-api/constants' ; import { mapToRobotApiRequest } from '../../robot-api/operators' ; import * as Actions from '../actions' ; import * as Constants from '../constants' ; import type { Action , Epic } from '../../types' ; import type { ActionToRequestMapper , ResponseToActionMapper , } from '../../robot-api/operators' ; import type { UpdateModuleAction } from '../types' ; const mapActionToRequest = action => ( { method : POST , path : `${ Constants . MODULES_PATH }/${ action . payload . moduleId }/${ Constants . MODULE_UPDATE_PATH_EXT }` , } ) ; const mapResponseToAction = ( response , originalAction ) => { const { host , body , ... responseMeta } = response ; const { moduleId } = originalAction . payload ; const meta = { ... originalAction . meta , response : responseMeta } ; return response . ok ? Actions . updateModuleSuccess ( host . name , moduleId , body . message , meta ) : Actions . updateModuleFailure ( host . name , moduleId , body , meta ) ; } ; export const updateModuleEpic = ( action$ , state$ ) => { return action$ . pipe ( ofType < Action , UpdateModuleAction > ( Constants . UPDATE_MODULE ) , mapToRobotApiRequest ( state$ , a => a . payload . robotName , mapActionToRequest , mapResponseToAction ) ) ; } ;