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.
When trying the following code
we get the output
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 callunsubscribeon the function that went intocomputed(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
pipefunctionality that I am building would benefit greatly from automatic internal unsubscribe from acomputedsobservableinputs, 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.