knowyt/client/src/composables/useEngine.ts

30 lines
773 B
TypeScript

import { useState } from '#app'
import { Ref } from 'vue'
import { start, stop } from '@/composables/engine/startStop'
import { fetchUpdate } from '@/composables/engine/fetchUpdate'
interface EngineContext {
isActive: Ref<boolean>
shouldStop: Ref<boolean>
fetchUpdate: () => void
}
export interface useEngine {
start(): void
stop(): void
fetchUpdate(): void
}
export default (): useEngine => {
const context: EngineContext = {
isActive: useState('engine__is-active', () => false),
shouldStop: useState('engine__should-stop', () => false),
fetchUpdate,
}
return {
start: () => start.apply(context),
stop: () => stop.apply(context),
fetchUpdate: () => fetchUpdate.apply(context),
}
}