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

Add set alias for next on BehaviorSubject #4740

Open
benlesh opened this issue Apr 26, 2019 · 14 comments
Open

Add set alias for next on BehaviorSubject #4740

benlesh opened this issue Apr 26, 2019 · 14 comments

Comments

@benlesh
Copy link
Member

benlesh commented Apr 26, 2019

Per this discussion on Twitter

Basically, svelte has amazing support for RxJS. Particularly in reading from RxJS observables.

This very small addition to RxJS would enable Svelte users to very conveniently trigger reactive updates through RxJS.

Proposal

Just alias next as set on BehaviorSubject. (I don't see a reason yet to add it to all subjects).

That would enable Svelte users to simply bind to them in their templates.

cc/ @Rich-Harris

Other things

It's probably worth discussion with Svelte experts if this solves a big enough use case for them to be a valid change, and/or what other use cases we might need to consider.

@benlesh benlesh added the AGENDA ITEM Flagged for discussion at core team meetings label Apr 26, 2019
@kwonoj
Copy link
Member

kwonoj commented Apr 26, 2019

dumb q: why svelte can't use next directly?

at a first sight, I'm bit on opposite path for similar reason to we discussed around zone.js 1. I don't want to some framework specific path (even though this is only setting alias) 2. we tend to block / remove alias as much as it's generally bring confusion from consumer point of view.

@johnlindquist
Copy link
Contributor

Here's a little playground with set aliased to next for the curious:

https://svelte.dev/repl?version=3.1.0&gist=90c5eb4c3e9754ebafb1ed0f828866a2

@Rich-Harris
Copy link

...and a very slightly modified version illustrating assignments directly to a BehaviourSubject:

https://svelte.dev/repl?version=3.1.0&gist=542cdd9735cb7964a5c618374178a5c2

@AlexAegis
Copy link

AlexAegis commented Apr 26, 2019

This would be extremely helpful in Angular too.

[(value)]="fooBehaviorSubject.value"

@cartant
Copy link
Collaborator

cartant commented Apr 27, 2019

🤷‍♂ BehaviorSubject already has a read-only value property and a getValue method. With a set method, it's going to be a shambles, IMO. I can see the appeal - and Svelte looks great - but this class's interface is horrible. Maybe it's already so horrible that it doesn't matter, IDK. Either way I don't feel too strongly about this, but ... yuck.

@benlesh
Copy link
Member Author

benlesh commented May 8, 2019

So after discussion with the core team. It seems more reasonable to create a separate package with a SvelteSubject that would behave in the way you want... it is exactly this:

class SvelteSubject extends BehaviorSubject {
	set(value) {
		super.next(value);
	}
	
	lift(operator) {
		const result = new SvelteSubject();
		result.operator = operator;
		result.source = this;
		return result;
	}
}

@Rich-Harris what do you think about us adding this to the svelte org? (I'd happily help maintain that for you)

@benlesh benlesh removed the AGENDA ITEM Flagged for discussion at core team meetings label May 8, 2019
@evdama
Copy link

evdama commented May 28, 2019

I've been looking into using rxjs with svelte today but didn't find much info apart this issue and sveltejs/svelte#2549

Is there some documentation yet, or maybe tests with some code examples?

@Rich-Harris
Copy link

Hey, sorry — just seeing this. Sure, would be glad to host it in the Svelte org, thank you.

@BioPhoton
Copy link
Contributor

Hi @benlesh.

As i can see from the discussion this issue can be closed.

@spierala
Copy link

spierala commented Mar 6, 2021

Started a small project with the "SvelteSubject" and implemented the svelte stores as RxJS Observables:
https://github.com/spierala/svelte-store-rxjs

  • writable() returns a Writable instance. Writable extends RxJS BehaviorSubject.
  • readable() and derived() return a RxJS Observable

@AlexWarnes
Copy link

So after discussion with the core team. It seems more reasonable to create a separate package with a SvelteSubject that would behave in the way you want... it is exactly this:

class SvelteSubject extends BehaviorSubject {
	set(value) {
		super.next(value);
	}
	
	lift(operator) {
		const result = new SvelteSubject();
		result.operator = operator;
		result.source = this;
		return result;
	}
}

@benlesh thank you for this! I have two questions if you ever come back to this thread and have some time:

  1. Given the deprecation warnings around lift do you see any issues with this implementation in the future?

  2. Does const result = new SvelteSubject() require an initial/current value since it is creating a new bs? (this might be a dumb question)

Side Note: I wrote my first npm package with a handful of rxjs-based svelte actions for ppl who don't want to touch the rxjs side of things, but also expose an rxWritable based on this code for those who need more control with operators, so thank you again because it's a great combination.

@benlesh
Copy link
Member Author

benlesh commented Mar 25, 2022

The lift method would be optional, honestly.

@DallasHoff
Copy link

Hey, sorry — just seeing this. Sure, would be glad to host it in the Svelte org, thank you.

What did the name of this package end up being? I'm not finding it.

@m1nhtu99-hoan9
Copy link

@DallasHoff The package @AlexWarnes wrote and maintains is svelte-fuse-rx. I don't think there's official support for RxJS inside Svelte yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests