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
setup tutorial initialization
  • Loading branch information
@ShMcK
ShMcK committedJun 2, 2019
commit04653e2f736790df082abc0abddf0f8fc69ccd13
11 changes: 9 additions & 2 deletionssrc/state/actions/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,8 @@ let initialProgress: CR.Progress = {

export default {
start: async () => {
// verify that the user has a tutorial & progress
// verify git is setup with a coderoad remote
const [tutorial, progress, hasGit, hasGitRemote] = await Promise.all([
storage.getTutorial(),
storage.getProgress(),
Expand All@@ -22,9 +24,11 @@ export default {
initialTutorial = tutorial
initialProgress = progress
const canContinue = !!(tutorial && progress && hasGit && hasGitRemote)
// if a tutorial exists, "CONTINUE"
// otherwise start from "NEW"
send(canContinue ? 'CONTINUE' : 'NEW')
},
loadTutorial: assign({
tutorialLoad: assign({
// load initial data, progress & position
data(): CR.TutorialData {
if (!initialTutorial) {
Expand All@@ -33,7 +37,9 @@ export default {
return initialTutorial.data

},
progress(): CR.Progress { return initialProgress },
progress(): CR.Progress {
return initialProgress
},
position() {
if (!initialTutorial) {
throw new Error('No Tutorial loaded')
Expand All@@ -53,4 +59,5 @@ export default {
return position
}
}),

}
6 changes: 5 additions & 1 deletionsrc/state/guards/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
import * as CR from 'typings'

export default {

// skip to the stage if the level has already been started
hasNoNextLevelProgress: (context: CR.MachineContext): boolean => {
return false
},
}
19 changes: 8 additions & 11 deletionssrc/state/machine.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
import { Machine } from 'xstate'
import { Machine, send } from 'xstate'
import * as CR from 'typings'

import actions from './actions'
Expand DownExpand Up@@ -43,28 +43,25 @@ export const tutorialMachine = Machine<

},
ContinueTutorial: {
onEntry: 'loadTutorial',
onEntry: 'tutorialLoad',
on: {
TUTORIAL_START: {
target: 'Tutorial',
target: 'Tutorial.LoadNext',
}
}
},
}
},
Tutorial: {
initial: 'Initialize',
initial: 'Summary',
states: {
Initialize: {
LoadNext: {
onEntry: () => send('LOAD_NEXT'),
on: {
TUTORIAL_LOADED: [
{
target: 'Summary',
cond: 'hasNoProgress',
},
LOAD_NEXT: [
{
target: 'Level',
cond: 'hasNoLevelProgress',
cond: 'hasNoNextLevelProgress',
},
{
target: 'Stage',
Expand Down
2 changes: 1 addition & 1 deletionsrc/typings/index.d.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -143,7 +143,7 @@ export interface MachineStateSchema {
}
Tutorial: {
states: {
Initialize: {}
LoadNext: {}
Summary: {}
Level: {}
Stage: {
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp