Skip to content

Instantly share code, notes, and snippets.

@robinheinze
Last active April 7, 2021 21:09
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 robinheinze/0701db7a9d7482e9bd02b1086257a219 to your computer and use it in GitHub Desktop.
Save robinheinze/0701db7a9d7482e9bd02b1086257a219 to your computer and use it in GitHub Desktop.
Question with guess helpers
export const QuestionModel = types
.model("Question")
.props({
id: types.identifier,
category: types.maybe(types.string),
type: types.enumeration(["multiple", "boolean"]),
difficulty: types.enumeration(["easy", "medium", "hard"]),
question: types.maybe(types.string),
correctAnswer: types.maybe(types.string),
incorrectAnswers: types.optional(types.array(types.string), []),
guess: types.maybe(types.string),
})
.views(self => ({
get allAnswers() {
return shuffle(self.incorrectAnswers.concat([self.correctAnswer]))
},
get isCorrect() {
return self.guess === self.correctAnswer
},
}))
.actions(self => ({
setGuess(guess: string) {
self.guess = guess
},
}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment