create / open simulations
This commit is contained in:
parent
057c2268ac
commit
097c44e86e
43 changed files with 596 additions and 84 deletions
src/modules/input/stores
34
src/modules/input/stores/InputStore.ts
Normal file
34
src/modules/input/stores/InputStore.ts
Normal file
|
@ -0,0 +1,34 @@
|
|||
import { Subject, BehaviorSubject } from 'rxjs'
|
||||
import { take } from 'rxjs/operators'
|
||||
|
||||
export type InputAction = 'quit' | 'submit'
|
||||
|
||||
export const InputStore = {
|
||||
async get(text: string) {
|
||||
InputStore.open(text)
|
||||
|
||||
const action = await InputStore.actions.pipe(take(1)).toPromise()
|
||||
|
||||
InputStore.close()
|
||||
|
||||
if (action === 'quit') {
|
||||
return null
|
||||
}
|
||||
|
||||
return InputStore.data.output.value
|
||||
},
|
||||
open(text: string) {
|
||||
InputStore.data.open.next(true)
|
||||
InputStore.data.output.next('')
|
||||
InputStore.data.question.next(text)
|
||||
},
|
||||
close() {
|
||||
InputStore.data.open.next(false)
|
||||
},
|
||||
data: {
|
||||
question: new BehaviorSubject(''),
|
||||
output: new BehaviorSubject(''),
|
||||
open: new BehaviorSubject(false)
|
||||
},
|
||||
actions: new Subject<InputAction>()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue