Skip to content
New issue

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

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

Already on GitHub? # to your account

Multiple streams #6

Closed
scullabyte opened this issue Apr 25, 2020 · 2 comments
Closed

Multiple streams #6

scullabyte opened this issue Apr 25, 2020 · 2 comments

Comments

@scullabyte
Copy link
Contributor

scullabyte commented Apr 25, 2020

How would you implement multiple streams with the StreamViewModel currently? I would imagine combining and transforming streams to get multiple types out of them could get tedious.

My two cents:

I would think the best implementation would be the way you set up Provider previously:

providers = [
    ..._independentServices,
    ..._dependentServices,
    ..._consumableServices,
  ];

Maybe it would it make sense to have something like this:

abstract class StreamsViewModel extends BaseViewModel {

List<StreamsMixin<T>> get streams;

StreamsViewModel(){
    _listenToStreams(streams);
}
  void _listenToStreams(List<StreamsMixin> streams) {
    _streams = streams;
    for (var stream in _streams) {
      stream.addListener(_indicateChange);
    }
  }

Where the StreamsMixin does the same thing that the StreamViewModel does. Does that make sense? If I'm missing something and this is already doable, then an example of multiple streams would go a long way. Thanks!

@FilledStacks
Copy link
Contributor

Hey @scullabyte this is not possible yet. The only thing that I struggle with when it comes to multiple streams is how we'll distinguish the data that's fetched and how it will be stored. Currently it's available through the data property but if there's multiple streams what will those be stored in?

I was thinking of using a map with keys or an enum for readability so you can access the streams using that. So you'll register

Map<enum, Stream<T>> get streamsMap = {
  AuthenticationStatus: _authService.authenticationStatusStream,
  Orders: _orderStervice.ordersStream,
}

// Accessing a stream
var latestOrders = data[Orders]

I haven't tried it out but I am thinking about it, the same with the Future viewmodel. Multiple Futures and cancel / timeout / retry functionality built into it. I'm writing today, hoping I can get the written done and the video in one day for the new tutorial series episode 1. I'll be improving this package as we're developing a new food delivery service customer app so It'll get constant updates and fixes over the next few weeks.

@scullabyte scullabyte mentioned this issue Apr 27, 2020
@FilledStacks
Copy link
Contributor

Pushed base implementation. We'll refactor as we find better ways of doing things or the requirements change. Thanks for all the effort

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

No branches or pull requests

2 participants