luwes / luwes/sinuous

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

Open
#162 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
JavaScript
Stars
1.1k
Forks
34
PR merge metrics
No merged PRs in 30d

Description

When trying the following code
```javascript
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
```javascript
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 `computed`s 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 `computed`s `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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the example using observable, computed, subscribe, and unsubscribe, then inspect how computed tracks its observable inputs after the output subscription is removed. Define and test the desired unsubscribe propagation for the pipe chain, including when upstream work should stop.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.