* example(dart/toh-4,5): getHeroesSlowly() to return getHeroes() Have `getHeroesSlowly()` delay and then return the value of `getHeroes()`. This makes it easier for user’s performing the tutorial to keep this slower method as they evolve toh-5 into toh-6. * example(ts/toh-4,5): getHeroesSlowly() to return getHeroes() Have `getHeroesSlowly()` delay and then return the value of `getHeroes()`. This makes it easier for user’s performing the tutorial to keep this slower method as they evolve toh-5 into toh-6.
23 lines
504 B
Dart
23 lines
504 B
Dart
// #docregion
|
|
import 'dart:async';
|
|
|
|
import 'package:angular2/core.dart';
|
|
|
|
import 'hero.dart';
|
|
import 'mock_heroes.dart';
|
|
|
|
@Injectable()
|
|
class HeroService {
|
|
Future<List<Hero>> getHeroes() async => mockHeroes;
|
|
|
|
Future<List<Hero>> getHeroesSlowly() {
|
|
return new Future<List<Hero>>.delayed(
|
|
const Duration(seconds: 2), getHeroes);
|
|
}
|
|
|
|
// #docregion getHero
|
|
Future<Hero> getHero(int id) async =>
|
|
(await getHeroes()).firstWhere((hero) => hero.id == id);
|
|
// #enddocregion getHero
|
|
}
|