raphaelameaume / fragment

[alpha] A web development environment for creative coding
https://fragment.tools
MIT License
828 stars 19 forks source link

Add dispose lifecycle function #104

Closed raphaelameaume closed 7 months ago

raphaelameaume commented 7 months ago

This PR adds a new sketch lifecycle function named dispose() that allows a sketch to run some code before getting reloaded, such as cleaning up effects, removing elements, destroying textures... and so on.

Example

let element;

export let init = ({ canvas }) => {
    element = document.createElement('div');

    canvas.parentNode.appendChild(element);
}

export let dispose = () => {
    element.parentNode.removeChild(element);
}