Skip to content

Instantly share code, notes, and snippets.

@kadeer
Last active March 20, 2020 16:22
Show Gist options
  • Save kadeer/80c1d6b0da52af371c9d385384a37c0a to your computer and use it in GitHub Desktop.
Save kadeer/80c1d6b0da52af371c9d385384a37c0a to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const examinationSessionMachine = Machine({
id: "session",
initial: "inSession",
states: {
init: {
on: {
LOAD: "loading"
}
},
loading: {
// on: {
// 'LOAD_COMPLETE': 'loaded'
// }
type: "compound",
initial: "pending",
states: {
pending: {
on: {
RESOLVE: "success",
ERROR: "failure"
}
},
success: {
type: "final",
on: {
"": "#session.loaded"
}
},
failure: {
on: { RETRY: "pending" }
}
}
},
loaded: {
on: {
START: "start"
}
},
start: {
on: {
STARTED: "inSession"
}
},
inSession: {
initial: "inSession",
states: {
inSession: {
// on: { COMPLETE: "#session.complete", PAUSE: ".paused" }
// on: { QUESTION_ANSWERED: "" },
// sync
// behaviour
// timer
// connectivity
type: "parallel",
states: {
timer: {
initial: "timeGTE5mins",
states: {
timeGTE5mins: {},
timeLE5mins: {},
timeExhausted: {}
},
on: {
TIME_LE_5MINS: ".timeLE5mins",
TIME_EXHAUSTED: ".timeExhausted"
// SET_TIME
}
},
timeSpent: {
initial: "timeLE40mins",
states: {
timeLE40mins: {},
timeGE40mins: {}
}
},
sync: {
// uploading
// uploaded
// complete
},
behavior: {},
subjects: {
initial: "noneAttempted",
states: {
noneAttempted: {},
someAttempted: {},
allAttempted: {}
}
},
connectivity: {
initial: "unknown",
states: {
unknown: {},
connecting: {},
connected: {},
disconnected: {}
},
on: {
CONNECTING: ".connecting",
CONNECTED: ".connected",
DISCONNECTED: ".disconnected"
}
},
keyboard: {
initial: "unknown",
states: {
unknown: {},
bound: {
// type: "compound",
states: {},
on: {
UNBIND: "unbound"
}
},
unbound: {
on: { BIND: "bound" }
}
}
},
view: {
on: {
// LEFT
// RIGHT
// GOTO_QUESTION
// GOTO_SUBJECT
// SELECT_CHOICE
}
}
}
},
paused: {},
connectivityLost: {}
},
on: {
RESUME: ".inSession",
PAUSE: ".paused",
CONNECTIVITY_LOST: ".connectivityLost",
COMPLETE: {
target: "complete"
// cond: session.timeSpent.matches("timeGE40mins") && session.subjects.matches("allAttempted")
}
}
},
complete: {
on: {
SUBMIT: "submitting"
}
},
submitting: {
type: "compound",
initial: "pending",
states: {
pending: {
on: {
RESOLVE: "success",
ERROR: "failure"
}
},
success: {
type: "final",
on: {
"": "#session.submitted"
}
},
failure: {
on: { RETRY: "pending" }
}
}
},
submitted: {
type: "final"
}
// canSubmit?
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment