Commit d35fe29f authored by Jakob Moser's avatar Jakob Moser
Browse files

Refactor to use event handlers

parent 539d5bdb
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -73,7 +73,16 @@ export class Exercise {

    /**
     * Set the handler that is called every time the exercise's completion
     * is verified (this verification might fail or be successful)
     * is in the process of being verified.
     * @param {Function} handler Function with no parameter
     */
    onVerifiying(handler) {
        // TODO
    }

    /**
     * Set the handler that is called every time the exercise's completion
     * is verified (this verification either failed or was successful)
     * @param {Function} handler Function that takes the result of the verification (true/false) as parameter 
     */
    onVerified(handler) {
+3 −1
Original line number Diff line number Diff line
import { State } from "./state.mjs"
import * as tests from "./exercises.mjs"
import { createExerciseCard, displayAsSolved, displayAsNonCurrent, displayAsCurrent } from "./exercises.cards.mjs"
import { createExerciseCard, displayAsSolved, displayAsNonCurrent, displayAsCurrent, displayAsVerifying, displayAsNonVerifying } from "./exercises.cards.mjs"
import { Exercise } from "./exercises.api.mjs"
import { enableAutoFocus } from "./jslinux.api.mjs"

@@ -44,8 +44,10 @@ function startExercise(exercise) {

    exercise.markAsCurrent(currentState)
    exercise.onDescribed((/** @type {string} */ description) => cardEl.querySelector(".description").textContent = description)
    exercise.onVerifiying(()=>displayAsVerifying(cardEl))
    exercise.onVerified(
        (/** @type {boolean} */ success) => {
            displayAsNonVerifying(cardEl)
            if (success) {
                exercise.markAsSolved(currentState)
                displayAsSolved(cardEl)