-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
svelte/store derived
doesn't handle RxJS observables
#4298
Comments
This seems to work fine in REPL (though maybe I misunderstood your intent) https://svelte.dev/repl/ce3b3cf61ea942c9bc3f67667d37188a?version=3.17.2 |
That works fine because the component with the autosubscription is never destroyed. When we try to remove the last subscription from a derived that was based on an RxJS observable is when the exception is thrown, because derived expects to be able to call the return value from the observable's |
This doesn't look like it was actually fixed for some reason, reopening. |
Never mind, this is fixed in 3.17.3. The OP was a bad repro. <script>
import { of } from 'rxjs';
import { derived } from 'svelte/store';
const store1 = of('foo');
const store2 = derived(store1, _ => _);
store2.subscribe(() => {})();
</script> This breaks in 3.17.2 and works in 3.17.3. |
Describe the bug
The
derived
implementation doesn't handle RxJS Observables like other autosubscription stuff does.Logs
To Reproduce
Expected behavior
Subscribing to and unsubscribing from a store derived from an observable should work. In particular, this means the 'look to see whether there's an
unsubscribe
method to call instead' logic we use elsewhere should also be use in thederived
implementation.Information about your Svelte project:
Severity
Probably worth the bytes it would take to fix.
Additional context
A question came up in chat about using Observables in Svelte. I don't know whether the gap this issue describes is part of what was wrong, but the question did lead me to look into this.
We're already shipping a few extra bytes to everyone for RxJS support whether they're using it or not. It would be nice to be able to use the same helper in
derived
as we're already using in every Svelte project that uses autosubscription, but that might not be possible because of the two-argumentsubscribe()
calls for diamond dependency stuff.The text was updated successfully, but these errors were encountered: