Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Feature/tutorial setup#4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ShMcK merged 12 commits intomasterfromfeature/tutorial-setup
Jun 9, 2019
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
setup state/data
  • Loading branch information
@ShMcK
ShMcK committedJun 9, 2019
commit3cdce4d9aa088558b0956273c0de0229e1bf8292
12 changes: 6 additions & 6 deletionssrc/editor/commands/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,6 +9,7 @@ const COMMANDS = {
NEW_OR_CONTINUE: 'coderoad.new_or_continue',
OPEN_WEBVIEW: 'coderoad.open_webview',
SEND_STATE: 'coderoad.send_state',
SEND_DATA: 'coderoad.send_data',
RECEIVE_ACTION: 'coderoad.receive_action',
OPEN_FILE: 'coderoad.open_file',
RUN_TEST: 'coderoad.test_run',
Expand DownExpand Up@@ -70,15 +71,14 @@ export const createCommands = ({ context, machine, storage, git }: CreateCommand
}
},
// send messages to webview
[COMMANDS.SEND_STATE]: (payload: any) => {
console.log(`SEND ${JSON.stringify(payload)}`)
// console.log(webview.currentPanel)
// if (!webview || !webview.currentPanel) {
// throw new Error('No valid panel available')
// }
[COMMANDS.SEND_STATE]: (payload: { data: any, state: any }) => {
webview.postMessage({ type: 'SET_STATE', payload })
},
[COMMANDS.SEND_DATA]: (payload: { data: any }) => {
webview.postMessage({ type: 'SET_DATA', payload })
},
[COMMANDS.RECEIVE_ACTION]: (action: string | CR.Action) => {
console.log('onReceiveAction', action)
machine.onReceive(action)
}
})
6 changes: 4 additions & 2 deletionssrc/state/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,11 +18,13 @@ class StateMachine {
this.service = interpret(machine, this.machineOptions)
// logging
.onTransition(state => {
console.log('onTransition', state.changed)
console.log('onTransition', state)
if (state.changed) {
console.log('next state')
console.log(state.value)
vscode.commands.executeCommand('coderoad.send_state', state.value)
vscode.commands.executeCommand('coderoad.send_state', { state: state.value, data: state.context })
} else {
vscode.commands.executeCommand('coderoad.send_data', { data: state.context })
}
})
}
Expand Down
25 changes: 14 additions & 11 deletionsweb-app/src/Routes.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
import * as React from 'react'
import * as CR from 'typings'
import { send } from './utils/vscode'

import NewPage from './components/New'
import ContinuePage from './components/Continue'
import Cond from './components/Cond'
Expand All@@ -8,23 +10,21 @@ interface ReceivedEvent {
data: CR.Action
}

declare var acquireVsCodeApi: any

const vscode = acquireVsCodeApi()

function send(event: string|CR.Action) {
return vscode.postMessage(event)
}


const Routes = () => {
const [state, setState] = React.useState({ SelectTutorial: 'Initial' })
const [data, setData] = React.useState({})


const handleEvent = (event: ReceivedEvent): void => {
const message = event.data
console.log(`RECEIVED: ${JSON.stringify(message)}`)
console.log('RECEIVED')
console.log(message)
// messages from core
if (message.type === 'SET_STATE') {
setState(message.payload)
setState(message.payload.state)
setData(message.payload.data)
} else if (message.type === 'SET_DATA') {
setData(message.payload.data)
}
}

Expand All@@ -37,8 +37,11 @@ const Routes = () => {
}
})

// TODO: refactor cond to user <Router><Route> and accept first route as if/else if
return (
<div>
<h5>state: {JSON.stringify(state)}</h5>
<p>data:{JSON.stringify(data)}</p>
<Cond state={state} path="SelectTutorial.NewTutorial">
<NewPage onNew={() => send('TUTORIAL_START')} />
</Cond>
Expand Down
9 changes: 9 additions & 0 deletionsweb-app/src/utils/vscode.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
import { Action } from 'typings'

declare var acquireVsCodeApi: any

const vscode = acquireVsCodeApi()

export function send(event: string | Action) {
return vscode.postMessage(event)
}

[8]ページ先頭

©2009-2025 Movatter.jp