Created
May 5, 2021 12:54
-
-
Save Krutie/0eed8b06c66b7d79bfe4c3da3f172db7 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// v1 - probably incorrect machine | |
const lastQuestion = (context, event) => { | |
return context.ques > 0 | |
} | |
const quizMachine = Machine({ | |
id: 'quiz', | |
initial: 'idle', | |
context: { | |
rght: 0, | |
wrng: 0, | |
idx: 0, | |
ques: 5 | |
}, | |
states: { | |
idle: { | |
on: { | |
START: [ | |
{ | |
target: 'loading', | |
}, | |
] | |
}, | |
}, | |
loading: { | |
on: { | |
CORRECT:[{ | |
target: 'loading', | |
cond: lastQuestion, | |
actions:[ | |
assign({ | |
rght: (ctx,e) => ctx.rght + 1, | |
ques: (ctx,e) => ctx.ques - 1 | |
}), | |
assign({ | |
idx: (ctx,e) => ctx.idx + 1 | |
}) | |
] | |
}, | |
{ target: '.final' } | |
], | |
INCORRECT: [{ | |
target: 'loading', | |
cond: lastQuestion, | |
actions: [ | |
assign({ | |
wrng: (ctx,e) => ctx.wrng + 1, | |
ques: (ctx,e) => ctx.ques - 1 | |
}), | |
assign({ | |
idx: (ctx,e) => ctx.idx + 1 | |
}) | |
] | |
}, | |
{ target: '.final' } | |
] | |
}, | |
initial: 'normal', | |
states: { | |
normal: {}, | |
final: { | |
type: 'final' | |
} | |
} | |
}, | |
}, | |
// guards: { | |
// lastQuestion | |
// } | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment