refactor: move engine's start() to separate file
This commit is contained in:
parent
d9ebd90c12
commit
0b406595c7
9
client/src/composables/engine/start.ts
Normal file
9
client/src/composables/engine/start.ts
Normal file
@ -0,0 +1,9 @@
|
||||
export default function (): void {
|
||||
if (this.isActive.value && !this.shouldStop.value) {
|
||||
console.warn('attempt to start already running engine!')
|
||||
return
|
||||
}
|
||||
this.isActive.value = true
|
||||
this.shouldStop.value = false
|
||||
console.log('start engine')
|
||||
}
|
@ -1,4 +1,11 @@
|
||||
import { useState } from '#app'
|
||||
import { Ref } from 'vue'
|
||||
import start from '@/composables/engine/start'
|
||||
|
||||
interface EngineContext {
|
||||
isActive: Ref<boolean>
|
||||
shouldStop: Ref<boolean>
|
||||
}
|
||||
|
||||
export interface useEngine {
|
||||
start(): void
|
||||
@ -6,23 +13,16 @@ export interface useEngine {
|
||||
}
|
||||
|
||||
export default (): useEngine => {
|
||||
const isActive = useState('engine__is-active', () => false)
|
||||
const shouldStop = useState('engine__should-stop', () => false)
|
||||
const context: EngineContext = {
|
||||
isActive: useState('engine__is-active', () => false),
|
||||
shouldStop: useState('engine__should-stop', () => false),
|
||||
}
|
||||
|
||||
return {
|
||||
start: (): void => {
|
||||
if (isActive.value && !shouldStop.value) {
|
||||
console.warn('attempt to start already running engine!')
|
||||
return
|
||||
}
|
||||
isActive.value = true
|
||||
shouldStop.value = false
|
||||
console.log('start engine')
|
||||
},
|
||||
|
||||
start: () => start.apply(context),
|
||||
stop: (): void => {
|
||||
if (isActive.value) {
|
||||
shouldStop.value = true
|
||||
if (context.isActive.value) {
|
||||
context.shouldStop.value = true
|
||||
console.log('shut down engine')
|
||||
}
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user