Skip to content

Adopt the Explicit Resource Management API #8973

@TheCymaera

Description

@TheCymaera

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 of a script tag 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions