svelte icon indicating copy to clipboard operation
svelte copied to clipboard

Adopt the Explicit Resource Management API

Open TheCymaera opened this issue 2 years ago • 0 comments

Describe the problem

The Explicit Resource Management API is nearing Stage 4 and is implemented in TypeScript 5.2

I propose that Svelte 5 make use of patterns added by this proposal.

Describe the proposed solution

Specifically, we could use Symbol.dispose instead of $destroy

const svelteComponent = new MyComponent(options);
svelteComponent.$destroy();

// becomes

const svelteComponent = new MyComponent(options);
svelteComponent[Symbol.dispose]();

Additionally, using declarations in the global scope should be tied to the component's lifecycle.

using resource = createResource();

// same as

const resource = createResource();
onDestroy(() => {
    resource[Symbol.dispose]();
});

Alternatives considered

NA

Importance

would make my life easier

TheCymaera avatar Jul 14 '23 19:07 TheCymaera