Skip to content

Instantly share code, notes, and snippets.

@stravid
Created October 30, 2020 07:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stravid/023d1455e03d5a26b587cf6941b63efe to your computer and use it in GitHub Desktop.
Save stravid/023d1455e03d5a26b587cf6941b63efe to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const onlineTestMachine = Machine({
id: 'Online-Test',
initial: 'daten_laden',
context: {
beispielaufgaben: [1, 2, 3],
testteile: [
[4, 5, 6, 7],
[8, 9],
[10, 11, 12],
],
aktuelleAufgabe: 0,
aktuellerTestteil: 0,
},
states: {
daten_laden: {
on: {
ERFOLG: 'gesamt_instruktionen'
}
},
gesamt_instruktionen: {
on: {
BEISPIELAUFGABEN_STARTEN: { target: 'beispielaufgabe', actions: 'aktuelleAufgabeHochzaehlen' },
}
},
beispielaufgabe: {
on: {
WEITER_ZUR_NAECHSTEN_BEISPIELAUFGABE: [
{ target: 'letzte_beispielaufgabe', actions: 'aktuelleAufgabeHochzaehlen', cond: 'istVorletzteBeispielaufgabe' },
{ target: 'beispielaufgabe', actions: 'aktuelleAufgabeHochzaehlen' },
]
}
},
letzte_beispielaufgabe: {
on: {
WEITER: 'info_seite_testteil',
}
},
info_seite_testteil: {
on: {
TESTTEIL_N_STARTEN: { target: 'aufgabe', actions: ['aktuellenTestteilHochzaehlen', 'aufErsteAufgabeStellen'] },
}
},
aufgabe: {
on: {
ZU_NAECHSTER_AUFGABE: [
{ target: 'letzte_aufgabe', actions: 'aktuelleAufgabeHochzaehlen', cond: 'istVorletzteAufgabe' },
{ target: 'aufgabe', actions: 'aktuelleAufgabeHochzaehlen' },
],
BEANTWORTUNGSHINWEIS_ANZEIGEN: 'beantwortungshinweis',
ZU_VORHERIGER_AUFGABE: [
{ target: 'aufgabe', actions: 'aktuelleAufgabeRunterzaehlen', cond: 'nichtErsteAufgabe' },
]
}
},
letzte_aufgabe: {
on: {
ZU_VORHERIGER_AUFGABE: [
{ target: 'aufgabe', actions: 'aktuelleAufgabeRunterzaehlen', cond: 'nichtErsteAufgabe' },
],
BEANTWORTUNGSHINWEIS_ANZEIGEN: 'beantwortungshinweis',
TESTTEIL_N_BEENDEN: [
{ target: 'test_beenden', cond: 'istLetzterTestteil' },
{ target: 'testteil_beenden' },
]
}
},
beantwortungshinweis: {
on: {
ZURUECK_ZUR_AUFGABE: [
{ target: 'letzte_aufgabe', cond: 'istLetzteAufgabe' },
{ target: 'aufgabe' },
],
}
},
testteil_beenden: {
on: {
AUFGABEN_NOCHMALS_ANSEHEN: 'letzte_aufgabe',
WEITER_ZUM_NAECHSTEN_TESTTEIL: 'info_seite_testteil',
}
},
test_beenden: {
on: {
AUFGABEN_NOCHMALS_ANSEHEN: 'letzte_aufgabe',
TEST_BEENDEN: 'testende',
}
},
zeit_abgelaufen_testteil: {
on: {
}
},
zeit_abgelaufen_letzter_testteil: {
on: {
}
},
testende: {
}
},
}, {
actions: {
aktuelleAufgabeHochzaehlen: assign({
aktuelleAufgabe: (context) => context.aktuelleAufgabe + 1,
}),
aktuelleAufgabeRunterzaehlen: assign({
aktuelleAufgabe: (context) => context.aktuelleAufgabe - 1,
}),
aktuellenTestteilHochzaehlen: assign({
aktuellerTestteil: (context) => context.aktuellerTestteil + 1,
}),
aufErsteAufgabeStellen: assign({
aktuelleAufgabe: 1
}),
},
guards: {
istVorletzteBeispielaufgabe: (context) => context.aktuelleAufgabe == context.beispielaufgaben.length - 1,
istVorletzteAufgabe: (context) => !!context.testteile[context.aktuellerTestteil - 1] && context.aktuelleAufgabe == context.testteile[context.aktuellerTestteil - 1].length - 1,
istLetzteAufgabe: (context) => !!context.testteile[context.aktuellerTestteil - 1] && context.aktuelleAufgabe == context.testteile[context.aktuellerTestteil - 1].length,
istLetzterTestteil: (context) => context.aktuellerTestteil == context.testteile.length,
nichtErsteAufgabe: (context) => context.aktuelleAufgabe != 1
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment