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

27 lines
665 B
TypeScript

import { Injectable } from '@angular/core';
@Injectable()
export class LoggerService {
logs: string[] = [];
prevMsg = '';
prevMsgCount = 1;
log(msg: string) {
if (msg === this.prevMsg) {
// Repeat message; update last log entry with count.
this.logs[this.logs.length - 1] = msg + ` (${this.prevMsgCount += 1}x)`;
} else {
// New message; log it.
this.prevMsg = msg;
this.prevMsgCount = 1;
this.logs.push(msg);
}
}
clear() { this.logs.length = 0; }
// schedules a view refresh to ensure display catches up
tick() { this.tick_then(() => { }); }
tick_then(fn: () => any) { setTimeout(fn, 0); }
}