Skip to content

WIP - Split state machines #83

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

Closed
wants to merge 11 commits into from
Prev Previous commit
Next Next commit
cleanup select tutorial config
  • Loading branch information
ShMcK committed Jan 26, 2020
commit c4051018a1800410a544837bab29a9c48e71a8a0
57 changes: 0 additions & 57 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,63 +42,6 @@ export interface ErrorMessage {
description?: string
}

export interface MachineContext {
env: Environment
error: ErrorMessage | null
tutorial: G.Tutorial | null
}

export interface PlayMachineContext extends MachineContext {
position: Position
progress: Progress
processes: ProcessEvent[]
}

export interface MachineEvent {
type: string
payload?: any
data?: any
}

export interface SelectTutorialMachineStateSchema {
states: {
Startup: {}
Authenticate: {}
NewOrContinue: {}
SelectTutorial: {}
Summary: {}
Configure: {}
Launch: {}
ContinueTutorial: {}
}
}

export interface PlayTutorialMachineStateSchema {
states: {
LoadNext: {}
Level: {
states: {
Loading: {}
Normal: {}
TestRunning: {}
TestPass: {}
TestFail: {}
TestError: {}
StepNext: {}
LevelComplete: {}
}
}
Completed: {}
}
}

export interface MachineStateSchema {
states: {
SelectTutorial: {}
PlayTutorial: {}
}
}

export interface StateMachine {
activate(): void
deactivate(): void
Expand Down
2 changes: 1 addition & 1 deletion web-app/src/containers/New/TutorialList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface Props {
const TutorialList = (props: Props) => {
const onSelect = (tutorial: G.Tutorial) => {
channel.machineSend({
type: 'TUTORIAL_START',
type: 'SELECT_NEW_TUTORIAL',
payload: {
tutorial,
},
Expand Down
3 changes: 2 additions & 1 deletion web-app/src/containers/Overview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import * as G from 'typings/graphql'
import ErrorView from '../../components/Error'
import queryTutorial from '../../services/apollo/queries/tutorial'
import OverviewPage from './OverviewPage'
import { MachineContext } from '../../services/state/selectTutorial'

interface PageProps {
context: CR.MachineContext
context: MachineContext
send(action: CR.Action): void
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as CR from 'typings'
import * as G from 'typings/graphql'
import client from '../../../apollo'
import tutorialQuery from '../../../apollo/queries/tutorial'
import channel from '../../../channel'
import * as selectors from '../../../selectors'
import onError from '../../../../services/sentry/onError'
import { ActionFunctionMap } from 'xstate'
import client from '../../apollo'
import tutorialQuery from '../../apollo/queries/tutorial'
import channel from '../../channel'
import onError from '../../../services/sentry/onError'
import { MachineContext, MachineEvent } from './index'

interface TutorialData {
tutorial: G.Tutorial
Expand All @@ -15,7 +15,7 @@ interface TutorialDataVariables {
// version: string
}

export default {
const actionMap: ActionFunctionMap<MachineContext, MachineEvent> = {
loadEnv(): void {
channel.editorSend({
type: 'ENV_GET',
Expand All @@ -28,7 +28,7 @@ export default {
type: 'EDITOR_TUTORIAL_LOAD',
})
},
initializeTutorial(context: CR.PlayMachineContext, event: CR.MachineEvent) {
initializeTutorial(context: MachineContext, event: MachineEvent) {
// setup test runner and git
if (!context.tutorial) {
const error = new Error('Tutorial not available to load')
Expand Down Expand Up @@ -62,50 +62,21 @@ export default {
return Promise.reject(message)
})
},
continueConfig(context: CR.PlayMachineContext) {
channel.editorSend({
type: 'EDITOR_TUTORIAL_CONTINUE_CONFIG',
payload: {
// pass position because current stepId or first stepId will be empty
stepId: context.position.stepId,
},
})
},
loadLevel(context: CR.PlayMachineContext): void {
const level: G.Level = selectors.currentLevel(context)
if (level.setup) {
// load step actions
channel.editorSend({
type: 'SETUP_ACTIONS',
payload: level.setup,
})
}
},
loadStep(context: CR.PlayMachineContext): void {
const step: G.Step = selectors.currentStep(context)
if (step.setup) {
// load step actions
channel.editorSend({
type: 'SETUP_ACTIONS',
payload: {
stepId: step.id,
...step.setup,
},
})
}
},
editorLoadSolution(context: CR.PlayMachineContext): void {
const step: G.Step = selectors.currentStep(context)
// tell editor to load solution commit
channel.editorSend({
type: 'SOLUTION_ACTIONS',
payload: {
stepId: step.id,
...step.solution,
},
})
},
// continueConfig(context: CR.MachineContext) {
// channel.editorSend({
// type: 'EDITOR_TUTORIAL_CONTINUE_CONFIG',
// payload: {
// // pass position because current stepId or first stepId will be empty
// stepId: context.position.stepId,
// },
// })
// },
clearStorage(): void {
channel.editorSend({ type: 'TUTORIAL_CLEAR' })
},
userTutorialComplete(context: MachineContext) {
console.log('should update user tutorial as complete')
},
}

export default actionMap
68 changes: 0 additions & 68 deletions web-app/src/services/state/selectTutorial/actions/api.ts

This file was deleted.

47 changes: 0 additions & 47 deletions web-app/src/services/state/selectTutorial/actions/context.ts

This file was deleted.

9 changes: 0 additions & 9 deletions web-app/src/services/state/selectTutorial/actions/index.ts

This file was deleted.

Loading