mirror of
https://github.com/He4eT/elseifplayer.git
synced 2026-05-05 01:17:22 +00:00
Player: extract handlers
This commit is contained in:
parent
e72481f7dc
commit
c74c425041
2 changed files with 48 additions and 47 deletions
|
|
@ -13,6 +13,8 @@ import GridBuffer from './GridBuffer'
|
|||
import InputBox from './InputBox'
|
||||
import Status from './Status'
|
||||
|
||||
import {Handlers} from './playerHandlers'
|
||||
|
||||
import './player.css'
|
||||
|
||||
const INITIAL_STATUS = {
|
||||
|
|
@ -30,53 +32,6 @@ const runMachine = ({ engine: Engine, file, handlers }) => {
|
|||
return { sendFn, instance: vm }
|
||||
}
|
||||
|
||||
const Handlers = ({
|
||||
setStatus,
|
||||
setWindows,
|
||||
setCurrentWindowId,
|
||||
setInputType,
|
||||
setInbox
|
||||
}) => ({
|
||||
onInit: _ => {
|
||||
setStatus({ stage: 'ready' })
|
||||
},
|
||||
/* */
|
||||
onUpdateWindows: windows => {
|
||||
setWindows(windows)
|
||||
},
|
||||
onUpdateInputs: data => {
|
||||
if (data.length === 0) return void null
|
||||
|
||||
const {type, id} = data[0]
|
||||
setCurrentWindowId(id)
|
||||
setInputType(type)
|
||||
},
|
||||
onUpdateContent: inbox => {
|
||||
setInbox(inbox)
|
||||
},
|
||||
onDisable: _ => {
|
||||
setInputType(null)
|
||||
},
|
||||
/* */
|
||||
onFileNameRequest: (tosave, usage, _, setFileName) => {
|
||||
setFileName({
|
||||
usage,
|
||||
filename: prompt('Enter the filename')
|
||||
})
|
||||
},
|
||||
onFileRead: ({ filename }) => {
|
||||
const content = localStorage.getItem(`fake-fs/${filename}`)
|
||||
return decode(content)
|
||||
},
|
||||
onFileWrite: ({ filename }, content) => {
|
||||
localStorage.setItem(`fake-fs/${filename}`, encode(content))
|
||||
},
|
||||
/* */
|
||||
onExit: _ => {
|
||||
setInputType(null)
|
||||
}
|
||||
})
|
||||
|
||||
export default function ({
|
||||
vmParts: { file, engine }, singleWindow
|
||||
}) {
|
||||
|
|
|
|||
46
src/components/Player/playerHandlers.js
Normal file
46
src/components/Player/playerHandlers.js
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
export const Handlers = ({
|
||||
setStatus,
|
||||
setWindows,
|
||||
setCurrentWindowId,
|
||||
setInputType,
|
||||
setInbox
|
||||
}) => ({
|
||||
onInit: _ => {
|
||||
setStatus({ stage: 'ready' })
|
||||
},
|
||||
/* */
|
||||
onUpdateWindows: windows => {
|
||||
setWindows(windows)
|
||||
},
|
||||
onUpdateInputs: data => {
|
||||
if (data.length === 0) return void null
|
||||
|
||||
const {type, id} = data[0]
|
||||
setCurrentWindowId(id)
|
||||
setInputType(type)
|
||||
},
|
||||
onUpdateContent: inbox => {
|
||||
setInbox(inbox)
|
||||
},
|
||||
onDisable: _ => {
|
||||
setInputType(null)
|
||||
},
|
||||
/* */
|
||||
onFileNameRequest: (tosave, usage, _, setFileName) => {
|
||||
setFileName({
|
||||
usage,
|
||||
filename: prompt('Enter the filename')
|
||||
})
|
||||
},
|
||||
onFileRead: ({ filename }) => {
|
||||
const content = localStorage.getItem(`fake-fs/${filename}`)
|
||||
return decode(content)
|
||||
},
|
||||
onFileWrite: ({ filename }, content) => {
|
||||
localStorage.setItem(`fake-fs/${filename}`, encode(content))
|
||||
},
|
||||
/* */
|
||||
onExit: _ => {
|
||||
setInputType(null)
|
||||
}
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue