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

Migrate to xstate as app skeleton#2

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ShMcK merged 11 commits intoxstatefromfeature/treeview
Jun 2, 2019
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
refactor storage into editor
  • Loading branch information
@ShMcK
ShMcK committedJun 2, 2019
commit9bcf64cc75b38a7c46df17f18d1d44fd5fd6afb9
2 changes: 1 addition & 1 deletionsrc/editor/commands/loadSolution.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
import*asCRfrom'typings'
import*asstoragefrom'../storage'
import*asstoragefrom'../../services/storage'
import{gitLoadCommits,gitClear}from'../../services/git'

exportdefaultasyncfunctionloadSolution():Promise<void>{
Expand Down
2 changes: 1 addition & 1 deletionsrc/editor/commands/runTest.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
import { getOutputChannel } from '../channel'
import { exec } from '../../services/node'
import * as storage from '../storage'
import * as storage from '../../services/storage'
import * as testResult from '../../services/testResult'

// ensure only latest run_test action is taken
Expand Down
2 changes: 1 addition & 1 deletionsrc/editor/commands/tutorialLoad.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,7 +4,7 @@ import * as CR from 'typings'
import api from '../../services/api'
import tutorialSetup from '../../services/tutorialSetup'
import { loadProgressPosition } from '../../services/position'
import * as storage from '../storage'
import * as storage from '../../services/storage'
import rootSetup from '../../services/rootSetup'
import { isEmptyWorkspace, openReadme } from '../workspace'
import * as git from '../../services/git'
Expand Down
74 changes: 4 additions & 70 deletionssrc/editor/storage.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,77 +8,11 @@ export function setStorage(workspaceState: vscode.Memento): void {
storage = workspaceState
}

// TUTORIAL
const STORE_TUTORIAL = 'coderoad:tutorial'

export async function getTutorial(): Promise<CR.Tutorial | undefined> {
return storage.get(STORE_TUTORIAL)
}

export async function setTutorial(tutorial: CR.Tutorial): Promise<void> {
await storage.update(STORE_TUTORIAL, tutorial)
export function get<T>(key: string): T | undefined {
return storage.get(key)
}

// POSITION
const STORE_POSITION = 'coderoad:position'

const defaultPosition = { levelId: '', stageId: '', stepId: '' }

export async function getPosition(): Promise<CR.Position> {
const position: CR.Position | undefined = storage.get(STORE_POSITION)
return position || defaultPosition
export function update<T>(key: string, value: string | Object): Thenable<void> {
return storage.update(key, value)
}

export async function setPosition(position: CR.Position): Promise<void> {
await storage.update(STORE_POSITION, position)
}

// PROGRESS
const STORE_PROGRESS = 'coderoad:progress'

const defaultProgress = { levels: {}, stages: {}, steps: {}, hints: {}, complete: false }

export async function getProgress(): Promise<CR.Progress> {
const progress: CR.Progress | undefined = await storage.get(STORE_PROGRESS)
return progress || defaultProgress
}

export async function resetProgress(): Promise<void> {
await storage.update(STORE_PROGRESS, defaultProgress)
}

interface ProgressUpdate {
levels?: {
[levelId: string]: boolean
}
stages?: {
[stageid: string]: boolean
}
steps?: {
[stepId: string]: boolean
}
}

export async function updateProgress(record: ProgressUpdate): Promise<void> {
const progress = await getProgress()
if (record.levels) {
progress.levels = {
...progress.levels,
...record.levels,
}
}
if (record.stages) {
progress.stages = {
...progress.stages,
...record.stages,
}
}
if (record.steps) {
progress.steps = {
...progress.steps,
...record.steps,
}
}

await storage.update(STORE_PROGRESS, progress)
}
2 changes: 1 addition & 1 deletionsrc/services/position.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
import * as CR from 'typings'
import * as storage from '../editor/storage'
import * as storage from './storage'

export async function getInitial(tutorial: CR.Tutorial): Promise<CR.Position> {
const { data } = tutorial
Expand Down
77 changes: 77 additions & 0 deletionssrc/services/storage.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
import * as CR from 'typings'
import * as storage from '../editor/storage'

// TUTORIAL
const STORE_TUTORIAL = 'coderoad:tutorial'

export async function getTutorial(): Promise<CR.Tutorial | undefined> {
return storage.get<CR.Tutorial>(STORE_TUTORIAL)
}

export async function setTutorial(tutorial: CR.Tutorial): Promise<void> {
await storage.update<CR.Tutorial>(STORE_TUTORIAL, tutorial)
}

// POSITION
const STORE_POSITION = 'coderoad:position'

const defaultPosition = { levelId: '', stageId: '', stepId: '' }

export async function getPosition(): Promise<CR.Position> {
const position: CR.Position | undefined = storage.get<CR.Position>(STORE_POSITION)
return position || defaultPosition
}

export async function setPosition(position: CR.Position): Promise<void> {
await storage.update<CR.Position>(STORE_POSITION, position)
}

// PROGRESS
const STORE_PROGRESS = 'coderoad:progress'

const defaultProgress = { levels: {}, stages: {}, steps: {}, hints: {}, complete: false }

export async function getProgress(): Promise<CR.Progress> {
const progress: CR.Progress | undefined = await storage.get<CR.Progress>(STORE_PROGRESS)
return progress || defaultProgress
}

export async function resetProgress(): Promise<void> {
await storage.update<CR.Progress>(STORE_PROGRESS, defaultProgress)
}

interface ProgressUpdate {
levels?: {
[levelId: string]: boolean
}
stages?: {
[stageid: string]: boolean
}
steps?: {
[stepId: string]: boolean
}
}

export async function updateProgress(record: ProgressUpdate): Promise<void> {
const progress = await getProgress()
if (record.levels) {
progress.levels = {
...progress.levels,
...record.levels,
}
}
if (record.stages) {
progress.stages = {
...progress.stages,
...record.stages,
}
}
if (record.steps) {
progress.steps = {
...progress.steps,
...record.steps,
}
}

await storage.update<CR.Progress>(STORE_PROGRESS, progress)
}
2 changes: 1 addition & 1 deletionsrc/services/testResult.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
import * as CR from 'typings'
import * as vscode from 'vscode'
import * as storage from '../editor/storage'
import * as storage from './storage'


export async function onSuccess(position: CR.Position) {
Expand Down
2 changes: 1 addition & 1 deletionsrc/services/tutorialSetup.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
import * as CR from 'typings'
import * as position from '../services/position'
import * as storage from '../editor/storage'
import * as storage from '../services/storage'
import { isEmptyWorkspace } from '../editor/workspace'
import { gitLoadCommits, gitInitIfNotExists, gitSetupRemote } from '../services/git'

Expand Down
2 changes: 1 addition & 1 deletionsrc/state/actions/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
import { assign, send } from 'xstate'
import * as CR from 'typings'
import * as storage from '../../editor/storage'
import * as storage from '../../services/storage'
import * as git from '../../services/git'

let initialTutorial: CR.Tutorial | undefined
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp