import { FluxAction } from '@nlabs/arkhamjs' ; import { createBrowserHistory , History } from 'history' ; export class InspectorActions { static dispatch ( action ) { this . message ( { _arkhamCall : { args : [ action ] , method : 'dispatch' } } ) ; } static goto ( routePath ) { const history = createBrowserHistory ( ) ; history . push ( `/${ routePath }` ) ; return history ; } static onDispatch ( data ) { const { action , duration , state , stack } = data ; const formatDuration = InspectorActions . msToTime ( duration ) ; console . log ( 'InspectorActions::action' , action ) ; console . log ( 'InspectorActions::state' , state ) ; console . log ( 'InspectorActions::stack' , stack ) ; console . log ( 'InspectorActions::formatDuration' , formatDuration ) ; } static onInfo ( data ) { console . log ( 'InspectorActions::onInfo::data' , data ) ; } static message ( data ) { window . postMessage ( data , '*' ) ; } static msToTime ( duration ) { const milliseconds = Math . floor ( duration % 1000 ) ; const seconds = Math . floor ( ( duration / 1000 ) % 60 ) ; const minutes = Math . floor ( ( duration / ( 1000 * 60 ) ) % 60 ) ; const hours = Math . floor ( ( duration / ( 1000 * 60 * 60 ) ) % 24 ) ; const formatHours = ( hours < 10 ) ? `0${ hours }` : hours . toString ( ) ; const formatMinutes = ( minutes < 10 ) ? `0${ minutes }` : minutes . toString ( ) ; const formatSeconds = ( seconds < 10 ) ? `0${ seconds }` : seconds . toString ( ) ; return `${ formatHours }:${ formatMinutes }:${ formatSeconds }.${ milliseconds . toString ( ) }` ; } }