Skip to content

Feature/completed #22

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 23, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
setup state string for debugging
  • Loading branch information
ShMcK committed Jul 23, 2019
commit 22eb2c96ff7e689af318b6447fb0cd863bcc7a54
19 changes: 16 additions & 3 deletions src/state/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ import createMachine from './machine'
// machine interpreter
// https://xstate.js.org/docs/guides/interpretation.html

// convert state into a readable string
const stateToString = (state: string | object, str: string = ''): string => {
if (typeof state === 'object') {
const keys = Object.keys(state)
if (keys && keys.length) {
const key = keys[0]
return stateToString(state[key], str.length ? `${str}.${key}` : key)
}
return str
} else if (typeof state === 'string') {
return state
}
return ''
}

interface Props {
dispatch: CR.EditorDispatch
}
Expand All @@ -23,10 +38,8 @@ class StateMachine {
this.service = interpret(machine, this.machineOptions)
// logging
.onTransition(state => {
// console.log('onTransition', state)
if (state.changed) {
// console.log('next state')
// console.log(state.value)
console.log(`STATE: ${stateToString(state.value)}`)
dispatch('coderoad.send_state', { state: state.value, data: state.context })
} else {
dispatch('coderoad.send_data', { data: state.context })
Expand Down