1 | import { customAttribute } from 'aurelia-templating';
|
2 | import { getLogger, Logger } from 'aurelia-logging';
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | @customAttribute('view-spy')
|
10 | export class ViewSpy {
|
11 | private logger: Logger;
|
12 | private value: any;
|
13 | private view: any;
|
14 |
|
15 | |
16 |
|
17 |
|
18 | constructor() {
|
19 | this.logger = getLogger('view-spy');
|
20 | }
|
21 |
|
22 | private _log(lifecycleName: string, context?: {}) {
|
23 | if (!this.value && lifecycleName === 'created') {
|
24 | this.logger.info(lifecycleName, this.view);
|
25 | } else if (this.value && this.value.indexOf(lifecycleName) !== -1) {
|
26 | this.logger.info(lifecycleName, this.view, context);
|
27 | }
|
28 | }
|
29 |
|
30 | |
31 |
|
32 |
|
33 |
|
34 | public created(view: any) {
|
35 | this.view = view;
|
36 | this._log('created');
|
37 | }
|
38 |
|
39 | |
40 |
|
41 |
|
42 |
|
43 | public bind(bindingContext: {}) {
|
44 | this._log('bind', bindingContext);
|
45 | }
|
46 |
|
47 | |
48 |
|
49 |
|
50 | public attached() {
|
51 | this._log('attached');
|
52 | }
|
53 |
|
54 | |
55 |
|
56 |
|
57 | public detached() {
|
58 | this._log('detached');
|
59 | }
|
60 |
|
61 | |
62 |
|
63 |
|
64 | public unbind() {
|
65 | this._log('unbind');
|
66 | }
|
67 | }
|