import { h } from "hyperapp" ; import { guid } from "./utils" ; import { view } from "./view" ; import { state } from "./state" ; import { Actions } from "./api" ; import * as actions from "./actions" ; import enhanceActions from "./enhanceActions" ; import { injectedSetState } from "./api" ; export interface View { ( state , actions ) : any ; } export interface HypperApp { ( state , actions , view , container ) : any ; } let devtoolsApp ; export function getDevtoolsApp ( ) { return devtoolsApp ; } export function devtools < App extends HypperApp > ( app ) { const div = document . createElement ( "div" ) ; document . body . appendChild ( div ) ; devtoolsApp = app ( state , actions , view , div ) ; return < App > function ( state , actions , view , element ) { const runId = guid ( ) ; actions [ injectedSetState ] = function timeTravel ( state ) { return state ; } ; actions = enhanceActions ( devtoolsApp , runId , actions ) ; const interop = app ( state , actions , view , element ) ; devtoolsApp . logInit ( { runId , state , timestamp : new Date ( ) . getTime ( ) , interop } ) ; return interop ; } ; } export default devtools ;