Lifecycle
setup, mount and unmount.
Order
setup()runs once, before rendering.render()runs once and returns the DOM.- The
onMountcallbacks run once the DOM is in the page. - On unmount, the cleanup returned by
onMountand theonUnmountcallbacks run, then everything the component owns is disposed.
onMount()
Register it in setup(). It may return a cleanup function,
which runs on unmount.
onUnmount()
protected setup(): void {
const socket = new WebSocket(url);
this.onUnmount(() => socket.close());
}
What you do not clean up
Bindings, effects created in setup(), control flow
branches and child components are owned by the component and disposed
for you. Only clean up what Signy cannot see, such as timers, sockets
and listeners on window.