erratic-gate/src/modules/create-simulation/stores/CreateSimulationStore.ts
2019-07-22 11:59:10 +03:00

46 lines
1.2 KiB
TypeScript

import { BehaviorSubject, Subject } from 'rxjs'
import { take } from 'rxjs/operators'
import { simulationMode } from '../../saving/types/SimulationSave'
import { InputStore } from '../../input/stores/InputStore'
export type CreateSimulationStoreAction = 'quit' | 'submit'
export const CreateSimulationStore = {
create: async () => {
CreateSimulationStore.open()
const action = await CreateSimulationStore.actions
.pipe(take(1))
.toPromise()
CreateSimulationStore.close()
if (action === 'quit') {
return null
}
const name = await InputStore.get(
'What do you want your simulation to be called?'
)
if (!name) {
return null
}
return {
mode: CreateSimulationStore.data.output.value,
name
}
},
open() {
CreateSimulationStore.data.open.next(true)
},
close() {
CreateSimulationStore.data.open.next(false)
},
data: {
open: new BehaviorSubject(false),
output: new BehaviorSubject<simulationMode>('project')
},
actions: new Subject<CreateSimulationStoreAction>()
}