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

Commit91feec8

Browse files
committed
refactor send actions
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parent9139d8f commit91feec8

File tree

15 files changed

+76
-62
lines changed

15 files changed

+76
-62
lines changed

‎src/actions/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export{defaultasonErrorPage}from'./onErrorPage'
2+
export{defaultasonTestPass}from'./onTestPass'

‎src/actions/onErrorPage.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import*asTfrom'typings'
2+
import{readFile}from'../services/node'
3+
importloggerfrom'../services/logger'
4+
5+
constonErrorPage=async(action:T.Action)=>{
6+
// Error middleware
7+
if(action?.payload?.error?.type){
8+
// load error markdown message
9+
consterror=action.payload.error
10+
consterrorMarkdown=awaitreadFile(__dirname,'..','..','errors',`${action.payload.error.type}.md`).catch(
11+
()=>{
12+
// onError(new Error(`Error Markdown file not found for ${action.type}`))
13+
},
14+
)
15+
16+
// log error to console for safe keeping
17+
logger(`ERROR:\n${errorMarkdown}`)
18+
19+
if(errorMarkdown){
20+
// add a clearer error message for the user
21+
error.message=`${errorMarkdown}\n\n${error.message}`
22+
}
23+
}
24+
}
25+
26+
exportdefaultonErrorPage

‎src/actions/onTestPass.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import*asgitfrom'../services/git'
2+
import*asTfrom'typings'
3+
importContextfrom'../services/context/context'
4+
5+
constonTestPass=(action:T.Action,context:Context)=>{
6+
consttutorial=context.tutorial.get()
7+
if(!tutorial){
8+
thrownewError('Error with current tutorial. Tutorial may be missing an id.')
9+
}
10+
// update local storage stepProgress
11+
constprogress=context.progress.setStepComplete(tutorial,action.payload.position.stepId)
12+
context.position.setPositionFromProgress(tutorial,progress)
13+
git.saveCommit('Save progress')
14+
}
15+
16+
exportdefaultonTestPass

‎src/actions/saveCommit.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

‎src/actions/tutorialConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import*asEfrom'typings/error'
22
import*asTTfrom'typings/tutorial'
33
import*asvscodefrom'vscode'
4-
import{COMMANDS}from'../editor/commands'
4+
import{COMMANDS}from'../commands'
55
import*asgitfrom'../services/git'
66
import{DISABLE_RUN_ON_SAVE}from'../environment'
77

‎src/actions/utils/loadWatchers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import*aschokidarfrom'chokidar'
22
import*asvscodefrom'vscode'
3-
import{COMMANDS}from'../../editor/commands'
3+
import{COMMANDS}from'../../commands'
44
import{WORKSPACE_ROOT}from'../../environment'
55

66
// NOTE: vscode createFileWatcher doesn't seem to detect changes outside of vscode

‎src/actions/utils/openFiles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import{join}from'path'
22
import*asvscodefrom'vscode'
3-
import{COMMANDS}from'../../editor/commands'
3+
import{COMMANDS}from'../../commands'
44

55
constopenFiles=async(files:string[])=>{
66
if(!files.length){

‎src/channel/index.tsrenamed to‎src/channel.ts

Lines changed: 17 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,20 @@ import * as E from 'typings/error'
44
import*asvscodefrom'vscode'
55
importfetchfrom'node-fetch'
66
import{satisfies}from'semver'
7-
importsaveCommitfrom'../actions/saveCommit'
8-
import{setupActions,solutionActions}from'../actions/setupActions'
9-
importtutorialConfigfrom'../actions/tutorialConfig'
10-
import{COMMANDS}from'../editor/commands'
11-
importContextfrom'./context'
12-
import{readFile}from'fs'
13-
import{join}from'path'
14-
import{promisify}from'util'
15-
importloggerfrom'../services/logger'
16-
import{version,compareVersions}from'../services/dependencies'
17-
import{openWorkspace,checkWorkspaceEmpty}from'../services/workspace'
18-
import{showOutput}from'../services/testRunner/output'
19-
import{exec}from'../services/node'
20-
import{WORKSPACE_ROOT,TUTORIAL_URL}from'../environment'
21-
importresetfrom'../services/reset'
22-
importgetLastCommitHashfrom'../services/reset/lastHash'
23-
import{onEvent}from'../services/telemetry'
24-
25-
constreadFileAsync=promisify(readFile)
7+
import{setupActions,solutionActions}from'./actions/setupActions'
8+
importtutorialConfigfrom'./actions/tutorialConfig'
9+
import{COMMANDS}from'./commands'
10+
importContextfrom'./services/context/context'
11+
importloggerfrom'./services/logger'
12+
import{version,compareVersions}from'./services/dependencies'
13+
import{openWorkspace,checkWorkspaceEmpty}from'./services/workspace'
14+
import{showOutput}from'./services/testRunner/output'
15+
import{exec}from'./services/node'
16+
import{WORKSPACE_ROOT,TUTORIAL_URL}from'./environment'
17+
importresetfrom'./services/reset'
18+
importgetLastCommitHashfrom'./services/reset/lastHash'
19+
import{onEvent}from'./services/telemetry'
20+
import*asactionsfrom'./actions'
2621

2722
interfaceChannel{
2823
receive(action:T.Action):Promise<void>
@@ -359,39 +354,16 @@ class Channel implements Channel {
359354
}
360355
// send to webview
361356
publicsend=async(action:T.Action):Promise<void>=>{
362-
// Error middleware
363-
if(action?.payload?.error?.type){
364-
// load error markdown message
365-
consterror=action.payload.error
366-
consterrorMarkdownFile=join(__dirname,'..','..','errors',`${action.payload.error.type}.md`)
367-
consterrorMarkdown=awaitreadFileAsync(errorMarkdownFile).catch(()=>{
368-
// onError(new Error(`Error Markdown file not found for ${action.type}`))
369-
})
370-
371-
// log error to console for safe keeping
372-
logger(`ERROR:\n${errorMarkdown}`)
373-
374-
if(errorMarkdown){
375-
// add a clearer error message for the user
376-
error.message=`${errorMarkdown}\n\n${error.message}`
377-
}
378-
}
379-
357+
// load error page if error action is triggered
358+
actions.onErrorPage(action)
380359
// action may be an object.type or plain string
381360
constactionType:string=typeofaction==='string' ?action :action.type
382361

383362
logger(`EXT TO CLIENT: "${actionType}"`)
384363

385364
switch(actionType){
386365
case'TEST_PASS':
387-
consttutorial=this.context.tutorial.get()
388-
if(!tutorial){
389-
thrownewError('Error with current tutorial. Tutorial may be missing an id.')
390-
}
391-
// update local storage stepProgress
392-
constprogress=this.context.progress.setStepComplete(tutorial,action.payload.position.stepId)
393-
this.context.position.setPositionFromProgress(tutorial,progress)
394-
saveCommit()
366+
actions.onTestPass(action,this.context)
395367
}
396368

397369
// send message

‎src/editor/commands.tsrenamed to‎src/commands.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import*asTfrom'typings'
22
import*asTTfrom'typings/tutorial'
33
import*asvscodefrom'vscode'
4-
importcreateTestRunnerfrom'../services/testRunner'
5-
import{setupActions}from'../actions/setupActions'
6-
importcreateWebViewfrom'../services/webview'
7-
importloggerfrom'../services/logger'
4+
importcreateTestRunnerfrom'./services/testRunner'
5+
import{setupActions}from'./actions/setupActions'
6+
importcreateWebViewfrom'./services/webview'
7+
importloggerfrom'./services/logger'
88

99
exportconstCOMMANDS={
1010
START:'coderoad.start',

‎src/extension.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import*asvscodefrom'vscode'
2-
import{createCommands}from'./editor/commands'
2+
import{createCommands}from'./commands'
33
import*astelemetryfrom'./services/telemetry'
44

55
letonDeactivate=()=>{}
File renamed without changes.
File renamed without changes.

‎src/channel/state/Progress.tsrenamed to‎src/services/context/state/Progress.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import*asTfrom'typings'
22
import*asTTfrom'typings/tutorial'
33
import*asvscodefrom'vscode'
4-
importStoragefrom'../../services/storage'
4+
importStoragefrom'../../storage'
55

66
constdefaultValue:T.Progress={
77
levels:{},

‎src/channel/state/Tutorial.tsrenamed to‎src/services/context/state/Tutorial.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import*asTTfrom'typings/tutorial'
22
import*asvscodefrom'vscode'
3-
importStoragefrom'../../services/storage'
3+
importStoragefrom'../../storage'
44

55
// Tutorial
66
classTutorial{

‎src/services/node/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { WORKSPACE_ROOT } from '../../environment'
66

77
constasyncExec=promisify(cpExec)
88
constasyncRemoveFile=promisify(fs.unlink)
9+
constasyncReadFile=promisify(fs.readFile)
910

1011
interfaceExecParams{
1112
command:string
@@ -24,3 +25,7 @@ export const exists = (...paths: string[]): boolean | never => {
2425
exportconstremoveFile=(...paths:string[])=>{
2526
returnasyncRemoveFile(join(WORKSPACE_ROOT, ...paths))
2627
}
28+
29+
exportconstreadFile=(...paths:string[])=>{
30+
returnasyncReadFile(join(...paths))
31+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp