Skip to content

Computed still updating (and subscribed to input observables) while output not observed #162

@quixot1c

Description

@quixot1c

When trying the following code

const obs = observable(1);
const observer = () => { console.log("inside: " + obs()); return obs() };
const comp = computed(observer);
const unsub = subscribe(() => console.log(comp()));

obs(2);
unsub();
obs(3);
unsubscribe(observer);
obs(4);

we get the output

inside: 1
1
inside: 2
2
inside: 3

while I would kind of expect the logs from inside the computed to stop after the unsub(). But this is only the case when I call unsubscribe on the function that went into computed (which also puzzled me a bit).

Is it desirable that computeds still fire internally even when their output (data) is not subscribed to?

I think my use case with the pipe functionality that I am building would benefit greatly from automatic internal unsubscribe from a computeds observable inputs, because that would propagate up the chain, eventually allowing me to detect a whole chain has become unobserved at the beginning of the chain, which then allows me to stop the Websocket connection that produces the data for the chain.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions