Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cleanup the canvas on VFX.destroy() #77

Merged
merged 3 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
. "$(dirname "$0")/_/husky.sh"

npm --workspace=react-vfx run lint-staged
npm --workspace=@vfx-js/core run lint-staged
2 changes: 1 addition & 1 deletion .husky/pre-publish
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
. "$(dirname "$0")/_/husky.sh"

npm run lint
npm --workspace=react-vfx run build
npm run build
1 change: 1 addition & 0 deletions packages/vfx-js/src/vfx-player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export class VFXPlayer {
}

destroy(): void {
this.stop();
if (typeof window !== "undefined") {
window.removeEventListener("resize", this.#resize);
window.removeEventListener("mousemove", this.#mousemove);
Expand Down
3 changes: 3 additions & 0 deletions packages/vfx-js/src/vfx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const canvasStyle = {
*/
export class VFX {
#player: VFXPlayer;
#canvas: HTMLCanvasElement;

/**
* Creates VFX instance and start playing immediately.
Expand All @@ -29,6 +30,7 @@ export class VFX {
canvas.style.setProperty("z-index", opts.zIndex.toString());
}
document.body.appendChild(canvas);
this.#canvas = canvas;

this.#player = new VFXPlayer(canvas);
this.#player.play();
Expand Down Expand Up @@ -86,6 +88,7 @@ export class VFX {
*/
destroy(): void {
this.#player.destroy();
this.#canvas.remove();
}

#addImage(element: HTMLImageElement, opts: VFXProps): void {
Expand Down
Loading