2016-03-25 19:03:53 -04:00
|
|
|
import 'package:angular2/core.dart';
|
2016-01-27 18:51:50 -05:00
|
|
|
|
|
|
|
import 'backend_service.dart';
|
|
|
|
import 'hero.dart';
|
|
|
|
import 'logger_service.dart';
|
2015-12-05 20:35:03 -05:00
|
|
|
|
|
|
|
@Injectable()
|
2016-07-01 11:44:28 -04:00
|
|
|
// #docregion class
|
2015-12-05 20:35:03 -05:00
|
|
|
class HeroService {
|
|
|
|
final BackendService _backendService;
|
|
|
|
final Logger _logger;
|
2016-07-01 11:44:28 -04:00
|
|
|
final List<Hero> heroes = [];
|
|
|
|
|
|
|
|
HeroService(this._logger, this._backendService);
|
|
|
|
|
2015-12-05 20:35:03 -05:00
|
|
|
List<Hero> getHeroes() {
|
2016-07-01 11:44:28 -04:00
|
|
|
_backendService.getAll(Hero).then((heroes) {
|
|
|
|
_logger.log('Fetched ${heroes.length} heroes.');
|
|
|
|
this.heroes.addAll(heroes); // fill cache
|
|
|
|
});
|
2015-12-05 20:35:03 -05:00
|
|
|
return heroes;
|
|
|
|
}
|
|
|
|
}
|