Skip to content

svelte/store derived doesn't handle RxJS observables #4298

@Conduitry

Description

@Conduitry

Describe the bug
The derived implementation doesn't handle RxJS Observables like other autosubscription stuff does.

Logs

TypeError: "fn is not a function"

To Reproduce

<script>
	import { of } from 'rxjs';
	import { derived } from 'svelte/store';
	const store1 = of('foo');
	const store2 = derived(store1, _ => _);
	store2.subscribe()();
</script>

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 the derived implementation.

Information about your Svelte project:

  • Svelte 3.17.2
  • REPL

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-argument subscribe() calls for diamond dependency stuff.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions