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

Improve Auto Cleanup Logic #11

Open
abdel-17 opened this issue Mar 28, 2024 · 1 comment
Open

Improve Auto Cleanup Logic #11

abdel-17 opened this issue Mar 28, 2024 · 1 comment

Comments

@abdel-17
Copy link
Collaborator

abdel-17 commented Mar 28, 2024

Currently, we auto cleanup effects by calling onDestroy in a try { ... } block with an empty catch {} to avoid errors when a melt component is created outside of a .svelte file. This is error-prone, however.

An admittedly hacky, but less error-prone alternative, is to first check if we can safely call onDestroy by calling an $effect with a noop.

function canSafelyCleanup() {
    try {
        $effect(noop);
        return true;
    } catch {
        return false;
    }
}
@abdel-17
Copy link
Collaborator Author

abdel-17 commented May 5, 2024

Alternative suggestion: Don't rely on $effect.root. If you want to use a builder outside of Svelte components, you can wrap it with $effect.root manually. Maybe we can provide it as a separate helper.

let tooltip: Tooltip;

$effect.root(() => {
  tooltip = new Tooltip();
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant