ReactiveX / rxdart

The Reactive Extensions for Dart
http://reactivex.io
Apache License 2.0
3.37k stars 270 forks source link

Bridging to Listenable (RxFlutter?) #272

Closed patniemeyer closed 5 years ago

patniemeyer commented 5 years ago

Is there a way to bridge a Dart Listenable to an Observable other than to create a subject and manually bind the two?

Anyone working on tighter integration with Flutter components? Is there somewhere we can offer help with this?

Thanks for your work!

brianegan commented 5 years ago

Hey there!

We don't have a built-in mechanism for that. I don't believe it makes sense to have such a method in the RxDart library itself because that would require us to depend on Flutter, which means you could not use RxDart for pure web apps or server side apps.

If this is a common scenario in your apps, you could definitely create a separate library that helps with some of these bits!

Anyone working on tighter integration with Flutter components?

Just curious, but what kind of additional integration would you like to see? In general, I tend to expose data via a Bloc and use StreamBuilder Widgets to rebuild.

patniemeyer commented 5 years ago

Hi, thanks for your reply. Yes, an additional lib sounds like the right thing. So, I'm coming at this from Swift where we have RxSwift and RxCocoa to separate those dependencies. In that case RxCocoa exposes Observables for most of the UI widget set. My first reaction when coming to RxDart with Flutter was looking for a similar way to bind a TextFieldController as an Observable. The examples that I've found all do the (straightforward but tedious) thing of creating a separate Subject, listening to the TextFieldController, and then passing along the events.

Since Dart doesn't have extensions and it's more idiomatic to wrap things I was thinking perhaps a lib of wrapper classes or factory methods on Observable for different widgets would make sense.

I'll probably start doing this on the small scale in my own code. But if anyone knows of a project that is already undertaking this I'd be interested in helping. Alternately if I'm way off base and this is not the right approach for Flutter I'd be interested in alternative patterns. I am not very familiar with Bloc but it seemed a bit heavy for what I am doing. I will take your suggestion and read more about it.

Thanks!

brianegan commented 5 years ago

Sounds good, definitely could see that being very helpful! I did have some things similar to that in a library called flutter_stream_friends:

https://pub.dartlang.org/documentation/flutter_stream_friends/latest/flutter_stream_friends/flutter_stream_friends-library.html

I think the API could evolve a bit at this point (it was an early experiment with Streams and Flutter before StreamBuilder was even available), but it might give you an idea of some of the things I've also done to combine Flutter with Streams.

Some of the helpful classes that I still like using:

https://pub.dartlang.org/documentation/flutter_stream_friends/latest/flutter_stream_friends/InfiniteScrollStream-class.html

https://pub.dartlang.org/documentation/flutter_stream_friends/latest/flutter_stream_friends/RefreshStreamCallback-class.html

SeongBrave commented 5 years ago

@patniemeyer I am a Swifter, RxCocoa and RxSwift is very nice,I expect a similar expansion of rxdart,

brianegan commented 5 years ago

I'd like to close this down since I think it's a great idea, but really believe this library should focus on core Rx / Stream functionality and allow other libs to bridge the gap more seamlessly between Flutter and Streams.

Now that extension functions are available, I could imagine some nice helpers, like listenable.asStream or stream.asListenable, but again -- I think those would be best implemented in a Flutter-specific package!