import * as api from "../api" ; import { merge } from "../immutable" ; import { getLatestRunId , getCallText } from "../selectors" ; import { sanitizeValueDisplay } from "../valueDisplay" ; export const logCallEnd = ( payload ) => ( state ) : Partial < api . State > => { const { runId = getLatestRunId ( state ) , eventId , result , error } = payload ; const runsById = { ... state . runsById } ; const run = { ... runsById [ runId ] } ; runsById [ runId ] = run ; run . eventsById = { ... run . eventsById } ; const event = { ... run . eventsById [ eventId ] } ; run . eventsById [ eventId ] = event ; let valueDisplay = state . valueDisplay ; if ( event . type === "action" || event . type === "function" ) { if ( result ) { event . result = result ; if ( event . type === "action" && ! result . then ) { const path = event . name . split ( "." ) ; path . pop ( ) ; const stateAfter = merge ( event . stateBefore , path , event . result ) ; event . stateAfter = stateAfter ; run . currentState = stateAfter ; } } if ( error ) { event . error = error ; } } run . currentEvent = eventId === run . currentEvent ? event . parent : run . currentEvent ; const selectedEvent = { runId : run . id , eventId } ; valueDisplay = sanitizeValueDisplay ( valueDisplay , event ) ; const callOverviewText = getCallText ( event as any ) ; return { runsById , selectedEvent , valueDisplay , callOverviewText } ; } ;