Skip to content

Investigate the concept of "disposing" signals #25

@cesarParra

Description

@cesarParra

Background

Some Signal frameworks, like Preact and many others, allow you to "dispose" of a computed of effect.

Once they are disposed, they will no longer be reevaluated.

Possible syntax

One possible syntax is to return the dispose function as part of the computed or effect object:

const computed = $computed(fn);

// then it can be disposed as follows
computed.dispose();

Or the function can be destructured out of the object

const {dispose} = $computed(fn);

You should be able to check if a value is disposed

const isDisposed = computed.disposed

Reacting to a disposal

We can allow for a function to be assigned that will run when a computed or effect get disposed.

const computed = $computed(fn);
computed.onDispose(() => console.log('the computed was disposed'));

Further investigation necessary

What happens to the computed and effects that depend on the disposed value when a computed signal gets disposed?

Ideas:

  • We can freeze the last value of the computed. When a dependency changes a disposed computed will not be recomputed, but dependants will still have a reference to the last value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions