Patrice Chalin ac92e77611 docs(dev guide): lifecycle-hooks - updated dart/ts code and new dart prose
Mainly copyedits, but also

- Dart .jade extends TS .jade file with minor overrides
- Significant update of example code (so it matches the ts example in its
appearance and behavior).
- Tweaks to Dart code.
- A few extra/corrected mixin definitions in `_util-fns.jade`.
2016-05-06 14:17:34 +01:00

28 lines
593 B
Dart

import 'dart:async';
import 'package:angular2/core.dart';
@Injectable()
class LoggerService {
List<String> logs = [];
String _prevMsg = '';
int _prevMsgCount = 1;
void log(String msg) {
if (msg == _prevMsg) {
// Repeat message; update last log entry with count.
logs[logs.length - 1] = "$msg (${_prevMsgCount += 1}x)";
} else {
// New message; log it.
_prevMsg = msg;
_prevMsgCount = 1;
logs.add(msg);
}
}
void clear() => logs.clear();
// schedules a view refresh to ensure display catches up
tick() => new Future(() {});
}