mirror of
https://github.com/He4eT/elseifplayer.git
synced 2026-05-05 01:17:22 +00:00
Rename components files to JSX
This commit is contained in:
parent
a100cbef4f
commit
884c53d6ae
8 changed files with 0 additions and 0 deletions
|
|
@ -1,100 +0,0 @@
|
|||
import { h } from 'preact'
|
||||
import { useState, useEffect } from 'preact/hooks'
|
||||
|
||||
import CheapGlkOte from 'cheap-glkote'
|
||||
|
||||
import TextBuffer from './TextBuffer'
|
||||
import InputBox from './InputBox'
|
||||
|
||||
const INITIAL_STATUS = {
|
||||
stage: 'loading',
|
||||
details: 'Preparing...'
|
||||
}
|
||||
|
||||
const runMachine = ({ Engine, file, handlers }) => {
|
||||
console.log('runMachine')
|
||||
|
||||
const vm = new Engine()
|
||||
const { glkInterface, sendFn } = CheapGlkOte(handlers)
|
||||
|
||||
vm.prepare(file, glkInterface)
|
||||
vm.start()
|
||||
|
||||
return { sendFn, instance: vm }
|
||||
}
|
||||
|
||||
const Handlers = ({
|
||||
setStatus,
|
||||
setCurrentWindow,
|
||||
setInputType,
|
||||
setInbox
|
||||
}) => ({
|
||||
onInit: _ => setStatus({ stage: 'ready' }),
|
||||
/* */
|
||||
onUpdateWindows: windows => {
|
||||
setCurrentWindow(windows
|
||||
.filter(x => x.type === 'buffer')
|
||||
.slice(-1)[0])
|
||||
},
|
||||
onUpdateInputs: setInputType,
|
||||
onUpdateContent: setInbox,
|
||||
onDisable: _ => setInputType(null),
|
||||
/* */
|
||||
onFileNameRequest: (tosave, usage, _, setFileName) => {
|
||||
setFileName({ filename: 'filename', usage })
|
||||
},
|
||||
onFileRead: filename => {
|
||||
return 'content'
|
||||
},
|
||||
onFileWrite: (filename, content) => {},
|
||||
/* */
|
||||
onExit: _ => setInputType(null)
|
||||
})
|
||||
|
||||
export default function ({ vmParts: { file, engine } }) {
|
||||
const [status, setStatus] = useState(INITIAL_STATUS)
|
||||
|
||||
const [currentWindow, setCurrentWindow] = useState(null)
|
||||
const [inputType, setInputType] = useState(null)
|
||||
const [inbox, setInbox] = useState([])
|
||||
|
||||
const [vm, setVm] = useState(null)
|
||||
const [sendMessage, setSendMessage] = useState(null)
|
||||
|
||||
useEffect(() => {
|
||||
const handlers = Handlers({
|
||||
setStatus,
|
||||
setCurrentWindow,
|
||||
setInputType,
|
||||
setInbox
|
||||
})
|
||||
|
||||
const vm = runMachine({
|
||||
Engine: engine,
|
||||
file,
|
||||
handlers
|
||||
})
|
||||
|
||||
setVm(vm)
|
||||
}, [file, engine])
|
||||
|
||||
useEffect(() => {
|
||||
setSendMessage(_ => vm
|
||||
? vm.sendFn
|
||||
: null)
|
||||
}, [vm])
|
||||
|
||||
return status.stage !== 'ready'
|
||||
? (<div>{status.details}</div>)
|
||||
: (<section>
|
||||
<TextBuffer {...{
|
||||
inbox,
|
||||
currentWindow
|
||||
}}/>
|
||||
<InputBox {...{
|
||||
currentWindow,
|
||||
inputType,
|
||||
sendMessage
|
||||
}}/>
|
||||
</section>)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue