Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A higher-order source that is switched is always stopped #4

Open
loreanvictor opened this issue Dec 1, 2023 · 0 comments · May be fixed by #5
Open

A higher-order source that is switched is always stopped #4

loreanvictor opened this issue Dec 1, 2023 · 0 comments · May be fixed by #5
Labels
bug Something isn't working

Comments

@loreanvictor
Copy link
Owner

Imagine this scenario:

$ => return makeNewSource($(dependency))

Whenever the expression is re-run, the result of previous call to makeNewSource() is stopped, which is the desired behaviour. However, this behaviour becomes buggy when the inner-source is created outside of the expression:

const sourceA = someSource()
const sourceB = someOtherSource()

$ => $(dependency) ? sourceA : sourceB

In this case, whenever there is a switch from sourceA to sourceB by the higher-order expression, sourceA is stopped, while it might be depended by other observations and have more data to emit.

This issue is marked as a bug because the current behaviour, though working correctly in most situations, works unexpectedly in some specific situations. To resolve this, I'd suggest the following remedies:

  • Provide a way to return an inner-source without stopping it on switch. This can be in the form of a select helper function:

    import { select } from 'quel'
    
    $ => $(dependency) ? select(sourceA) : select(sourceB)
  • Document this specific behaviour and the solution for the case where the inner-source is created outside of the expression.

The suggested solutions require further contemplation and investigation. Initially they seem ok, as although this solution increases the API surface, we do have conflicting use-cases of higher-order sources and the status quo behaviour does match the most common use case, meaning for most use cases the API surface does not get larger and the current level of simplicity is maintained.

@loreanvictor loreanvictor added the bug Something isn't working label Dec 1, 2023
loreanvictor added a commit that referenced this issue May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant