Bloc: debounceTime problem when pagination

Created on 20 Mar 2020  路  5Comments  路  Source: felangel/bloc

I want to paginate a ListView, so I use NotificationListener<ScrollNotification> which adds new event when the end of the ListView is reached. But I want to use debounce to get rid of spamming event about end of the ListView. So I use it in this way in the Bloc:

  @override
  Stream<ListState> transformEvents(
      Stream<ListEvent> events,
      Stream<ListState> Function(ListEvent event) next,
      ) {
    return super.transformEvents(
      events.debounceTime(
        Duration(milliseconds: 500),
      ),
      next,
    );
  }

But now I have three problems:

  1. If I will keep scrolling down(and generate events more often than every 500 milliseconds), then nothing will happen, the event will not be received. How can I fix it?
  2. Now every event class has debounceTime, how can I specify which subclasses of ListEvent should has debounceTime?
  3. How can I set that debounceTime should be only between two instances of the same class? Thus, for example, if this is the first event of this class, then debounceTime isn't needed.
question

Most helpful comment

@felangel sorry, I forgot to reply. throttleTime is what I need, thanks!

All 5 comments

Hi @don-prog 馃憢
Thanks for opening an issue!

Have you checked out https://github.com/felangel/bloc/issues/524#issuecomment-573978217?

@felangel thanks, I think this comment solves my second question. And what about two others?

  1. This is how debounceTime works. Maybe you're looking for a different operator like throttle or buffer?
  2. Check out https://github.com/ReactiveX/rxdart/blob/b0edb3d0b2adfb8245b6692623c2ae863c8b520c/lib/src/transformers/backpressure/debounce.dart#L61

Closing for now but feel free to comment with additional questions or details and I鈥檓 happy to continue the conversation 馃憤

@felangel sorry, I forgot to reply. throttleTime is what I need, thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

clicksocial picture clicksocial  路  3Comments

Reidond picture Reidond  路  3Comments

nerder picture nerder  路  3Comments

1AlexFix1 picture 1AlexFix1  路  3Comments

krusek picture krusek  路  3Comments