@g20/player
Version:
Window Animation Frame Player
54 lines (51 loc) • 1.74 kB
JavaScript
/**
* @g20/player 1.0.0-alpha.46
* (c) David Geo Holmes david.geo.holmes@gmail.com
* Released under the MIT License.
*/
System.register(['@g20/reactive'], (function (exports) {
'use strict';
var effect;
return {
setters: [function (module) {
effect = module.effect;
}],
execute: (function () {
class Player {
#board;
#frameCount;
/**
* The handle of the last frame requested.
*/
#handle = null;
constructor(board, callback) {
this.#board = board;
this.#frameCount = effect(() => {
callback(board.frameCount);
});
}
dispose() {
if (this.#frameCount) {
this.#frameCount.dispose();
}
}
play() {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const animate = (timestamp) => {
this.#handle = null;
this.#board.update();
this.#handle = window.requestAnimationFrame(animate);
};
this.#handle = window.requestAnimationFrame(animate);
}
pause() {
if (typeof this.#handle === "number") {
window.cancelAnimationFrame(this.#handle);
this.#handle = null;
}
}
} exports("Player", Player);
})
};
}));
//# sourceMappingURL=index.js.map