Skip to content

Refactor editor #396

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 8 commits into from
Jul 20, 2020
Prev Previous commit
Next Next commit
refactor onRunReset
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
  • Loading branch information
ShMcK committed Jul 20, 2020
commit a9d6561bff8bbdfb206c752e83f983e591db8b4d
1 change: 1 addition & 0 deletions src/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ export { default as onStartup } from './onStartup'
export { default as onTutorialConfig } from './onTutorialConfig'
export { default as onTutorialContinueConfig } from './onTutorialContinueConfig'
export { default as onValidateSetup } from './onValidateSetup'
export { default as onRunReset } from './onRunReset'
export { default as onErrorPage } from './onErrorPage'
export { default as onTestPass } from './onTestPass'
32 changes: 32 additions & 0 deletions src/actions/onRunReset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import * as T from 'typings'
import * as TT from 'typings/tutorial'
import Context from '../services/context/context'
import { exec } from '../services/node'
import reset from '../services/reset'
import getLastCommitHash from '../services/reset/lastHash'

const onRunReset = async (context: Context) => {
// reset to timeline
const tutorial: TT.Tutorial | null = context.tutorial.get()
const position: T.Position = context.position.get()

// get last pass commit
const hash = getLastCommitHash(position, tutorial?.levels || [])

const branch = tutorial?.config.repo.branch

if (!branch) {
console.error('No repo branch found for tutorial')
return
}

// load timeline until last pass commit
reset({ branch, hash })

// if tutorial.config.reset.command, run it
if (tutorial?.config?.reset?.command) {
await exec({ command: tutorial.config.reset.command })
}
}

export default onRunReset
27 changes: 1 addition & 26 deletions src/channel.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import * as T from 'typings'
import * as TT from 'typings/tutorial'
import * as vscode from 'vscode'
import { setupActions, solutionActions } from './actions/setupActions'
import { COMMANDS } from './commands'
import Context from './services/context/context'
import logger from './services/logger'
import { openWorkspace } from './services/workspace'
import { showOutput } from './services/testRunner/output'
import { exec } from './services/node'
import reset from './services/reset'
import getLastCommitHash from './services/reset/lastHash'

import * as actions from './actions'

interface Channel {
Expand Down Expand Up @@ -88,27 +83,7 @@ class Channel implements Channel {
vscode.commands.executeCommand(COMMANDS.RUN_TEST, action?.payload)
return
case 'EDITOR_RUN_RESET':
// reset to timeline
const tutorial: TT.Tutorial | null = this.context.tutorial.get()
const position: T.Position = this.context.position.get()

// get last pass commit
const hash = getLastCommitHash(position, tutorial?.levels || [])

const branch = tutorial?.config.repo.branch

if (!branch) {
console.error('No repo branch found for tutorial')
return
}

// load timeline until last pass commit
reset({ branch, hash })

// if tutorial.config.reset.command, run it
if (tutorial?.config?.reset?.command) {
await exec({ command: tutorial.config.reset.command })
}
actions.onRunReset(this.context)
return
default:
logger(`No match for action type: ${actionType}`)
Expand Down