All files / src/web run-controls.js

100% Statements 9/9
100% Branches 0/0
100% Functions 4/4
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18              3x 3x 3x 5x 5x   3x 3x      
/** The play and pause buttons on the top bar, kept in step with the loop's running state. */
export class RunControls {
    /**
     * @param {object} options
     * @param {object} options.loop - the emulation loop
     */
    constructor({ loop }) {
        const playButton = document.getElementById("debug-play");
        const pauseButton = document.getElementById("debug-pause");
        loop.addEventListener("running", () => {
            playButton.disabled = loop.isRunning();
            pauseButton.disabled = !loop.isRunning();
        });
        pauseButton.addEventListener("click", () => loop.stop(true));
        playButton.addEventListener("click", () => loop.go());
    }
}