[AngularDart] Replacement to deprecated Stream functions from Tutorial?

50 views
Skip to first unread message

Rookie C

unread,
Mar 21, 2021, 10:49:23 AM3/21/21
to Dart Web Development
In this tutorial:
https://angulardart.dev/tutorial/toh-pt6#herosearchcomponent

A couple of deprecated functions are used:

(1) debounce()
from package:stream_transform/src/rate_limit.dart

(2) switchMap()
from package:stream_transform/src/switch.dart

So, the following function (in tutorial) does not work any more:

////////////////////////////////////////////////////////////
void ngOnInit() async {
  heroes = _searchTerms.stream
    .transform(debounce(Duration(milliseconds: 300)))
    .distinct()
    .transform(switchMap((term) => term.isEmpty
      ? Stream<List<Hero>>.fromIterable([<Hero>[]])
      : _heroSearchService.search(term).asStream()))
    .handleError((e) {
      print(e);
    });
}
////////////////////////////////////////////////////////////

How to make the tutorial app work again?

Rookie C

unread,
Mar 21, 2021, 11:24:57 AM3/21/21
to Dart Web Development, Rookie C
Found the answer.
Simply remove the "transform" part.
Reply all
Reply to author
Forward
0 new messages