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

Commit9bcf64c

Browse files
committed
refactor storage into editor
1 parent89045a3 commit9bcf64c

File tree

9 files changed

+88
-77
lines changed

9 files changed

+88
-77
lines changed

‎src/editor/commands/loadSolution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import*asCRfrom'typings'
2-
import*asstoragefrom'../storage'
2+
import*asstoragefrom'../../services/storage'
33
import{gitLoadCommits,gitClear}from'../../services/git'
44

55
exportdefaultasyncfunctionloadSolution():Promise<void>{

‎src/editor/commands/runTest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import{getOutputChannel}from'../channel'
22
import{exec}from'../../services/node'
3-
import*asstoragefrom'../storage'
3+
import*asstoragefrom'../../services/storage'
44
import*astestResultfrom'../../services/testResult'
55

66
// ensure only latest run_test action is taken

‎src/editor/commands/tutorialLoad.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as CR from 'typings'
44
importapifrom'../../services/api'
55
importtutorialSetupfrom'../../services/tutorialSetup'
66
import{loadProgressPosition}from'../../services/position'
7-
import*asstoragefrom'../storage'
7+
import*asstoragefrom'../../services/storage'
88
importrootSetupfrom'../../services/rootSetup'
99
import{isEmptyWorkspace,openReadme}from'../workspace'
1010
import*asgitfrom'../../services/git'

‎src/editor/storage.ts

Lines changed: 4 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -8,77 +8,11 @@ export function setStorage(workspaceState: vscode.Memento): void {
88
storage=workspaceState
99
}
1010

11-
// TUTORIAL
12-
constSTORE_TUTORIAL='coderoad:tutorial'
13-
14-
exportasyncfunctiongetTutorial():Promise<CR.Tutorial|undefined>{
15-
returnstorage.get(STORE_TUTORIAL)
16-
}
17-
18-
exportasyncfunctionsetTutorial(tutorial:CR.Tutorial):Promise<void>{
19-
awaitstorage.update(STORE_TUTORIAL,tutorial)
11+
exportfunctionget<T>(key:string):T|undefined{
12+
returnstorage.get(key)
2013
}
2114

22-
// POSITION
23-
constSTORE_POSITION='coderoad:position'
24-
25-
constdefaultPosition={levelId:'',stageId:'',stepId:''}
26-
27-
exportasyncfunctiongetPosition():Promise<CR.Position>{
28-
constposition:CR.Position|undefined=storage.get(STORE_POSITION)
29-
returnposition||defaultPosition
15+
exportfunctionupdate<T>(key:string,value:string|Object):Thenable<void>{
16+
returnstorage.update(key,value)
3017
}
3118

32-
exportasyncfunctionsetPosition(position:CR.Position):Promise<void>{
33-
awaitstorage.update(STORE_POSITION,position)
34-
}
35-
36-
// PROGRESS
37-
constSTORE_PROGRESS='coderoad:progress'
38-
39-
constdefaultProgress={levels:{},stages:{},steps:{},hints:{},complete:false}
40-
41-
exportasyncfunctiongetProgress():Promise<CR.Progress>{
42-
constprogress:CR.Progress|undefined=awaitstorage.get(STORE_PROGRESS)
43-
returnprogress||defaultProgress
44-
}
45-
46-
exportasyncfunctionresetProgress():Promise<void>{
47-
awaitstorage.update(STORE_PROGRESS,defaultProgress)
48-
}
49-
50-
interfaceProgressUpdate{
51-
levels?:{
52-
[levelId:string]:boolean
53-
}
54-
stages?:{
55-
[stageid:string]:boolean
56-
}
57-
steps?:{
58-
[stepId:string]:boolean
59-
}
60-
}
61-
62-
exportasyncfunctionupdateProgress(record:ProgressUpdate):Promise<void>{
63-
constprogress=awaitgetProgress()
64-
if(record.levels){
65-
progress.levels={
66-
...progress.levels,
67-
...record.levels,
68-
}
69-
}
70-
if(record.stages){
71-
progress.stages={
72-
...progress.stages,
73-
...record.stages,
74-
}
75-
}
76-
if(record.steps){
77-
progress.steps={
78-
...progress.steps,
79-
...record.steps,
80-
}
81-
}
82-
83-
awaitstorage.update(STORE_PROGRESS,progress)
84-
}

‎src/services/position.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import*asCRfrom'typings'
2-
import*asstoragefrom'../editor/storage'
2+
import*asstoragefrom'./storage'
33

44
exportasyncfunctiongetInitial(tutorial:CR.Tutorial):Promise<CR.Position>{
55
const{ data}=tutorial

‎src/services/storage.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import*asCRfrom'typings'
2+
import*asstoragefrom'../editor/storage'
3+
4+
// TUTORIAL
5+
constSTORE_TUTORIAL='coderoad:tutorial'
6+
7+
exportasyncfunctiongetTutorial():Promise<CR.Tutorial|undefined>{
8+
returnstorage.get<CR.Tutorial>(STORE_TUTORIAL)
9+
}
10+
11+
exportasyncfunctionsetTutorial(tutorial:CR.Tutorial):Promise<void>{
12+
awaitstorage.update<CR.Tutorial>(STORE_TUTORIAL,tutorial)
13+
}
14+
15+
// POSITION
16+
constSTORE_POSITION='coderoad:position'
17+
18+
constdefaultPosition={levelId:'',stageId:'',stepId:''}
19+
20+
exportasyncfunctiongetPosition():Promise<CR.Position>{
21+
constposition:CR.Position|undefined=storage.get<CR.Position>(STORE_POSITION)
22+
returnposition||defaultPosition
23+
}
24+
25+
exportasyncfunctionsetPosition(position:CR.Position):Promise<void>{
26+
awaitstorage.update<CR.Position>(STORE_POSITION,position)
27+
}
28+
29+
// PROGRESS
30+
constSTORE_PROGRESS='coderoad:progress'
31+
32+
constdefaultProgress={levels:{},stages:{},steps:{},hints:{},complete:false}
33+
34+
exportasyncfunctiongetProgress():Promise<CR.Progress>{
35+
constprogress:CR.Progress|undefined=awaitstorage.get<CR.Progress>(STORE_PROGRESS)
36+
returnprogress||defaultProgress
37+
}
38+
39+
exportasyncfunctionresetProgress():Promise<void>{
40+
awaitstorage.update<CR.Progress>(STORE_PROGRESS,defaultProgress)
41+
}
42+
43+
interfaceProgressUpdate{
44+
levels?:{
45+
[levelId:string]:boolean
46+
}
47+
stages?:{
48+
[stageid:string]:boolean
49+
}
50+
steps?:{
51+
[stepId:string]:boolean
52+
}
53+
}
54+
55+
exportasyncfunctionupdateProgress(record:ProgressUpdate):Promise<void>{
56+
constprogress=awaitgetProgress()
57+
if(record.levels){
58+
progress.levels={
59+
...progress.levels,
60+
...record.levels,
61+
}
62+
}
63+
if(record.stages){
64+
progress.stages={
65+
...progress.stages,
66+
...record.stages,
67+
}
68+
}
69+
if(record.steps){
70+
progress.steps={
71+
...progress.steps,
72+
...record.steps,
73+
}
74+
}
75+
76+
awaitstorage.update<CR.Progress>(STORE_PROGRESS,progress)
77+
}

‎src/services/testResult.ts

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

55

66
exportasyncfunctiononSuccess(position:CR.Position){

‎src/services/tutorialSetup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import*asCRfrom'typings'
22
import*aspositionfrom'../services/position'
3-
import*asstoragefrom'../editor/storage'
3+
import*asstoragefrom'../services/storage'
44
import{isEmptyWorkspace}from'../editor/workspace'
55
import{gitLoadCommits,gitInitIfNotExists,gitSetupRemote}from'../services/git'
66

‎src/state/actions/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import{assign,send}from'xstate'
22
import*asCRfrom'typings'
3-
import*asstoragefrom'../../editor/storage'
3+
import*asstoragefrom'../../services/storage'
44
import*asgitfrom'../../services/git'
55

66
letinitialTutorial:CR.Tutorial|undefined

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp