Skip to content

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 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 11 commits into from
Jun 2, 2019
Prev Previous commit
Next Next commit
setup start w/ continue or new
  • Loading branch information
ShMcK committed Jun 2, 2019
commit 4be011f457ad47d599e71a0a2e94741540122c7a
17 changes: 16 additions & 1 deletion src/state/actions/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
export default {}
import { send } from "xstate";
import * as storage from '../../services/storage'
import * as git from '../../services/git'

export default {
start: async () => {
const [tutorial, progress, hasGit, hasGitRemote] = await Promise.all([
storage.getTutorial(),
storage.getProgress(),
git.gitVersion(),
git.gitCheckRemoteExists(),
])
const canContinue = !!(tutorial && progress && hasGit && hasGitRemote)
send(canContinue ? 'CONTINUE' : 'NEW')
}
}
5 changes: 4 additions & 1 deletion src/state/guards/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export default {}

export default {

}
12 changes: 3 additions & 9 deletions src/state/machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,10 @@ export const tutorialMachine = Machine<
initial: 'initial',
states: {
initial: {
onEntry: 'start',
on: {
START: [
{
target: 'continue',
cond: 'hasExistingTutorial',
},
{
target: 'new',
},
],
CONTINUE: 'continue',
NEW: 'new',
},
},
new: {
Expand Down