UNPKG

2.47 kBJavaScriptView Raw
1var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5 return c > 3 && r && Object.defineProperty(target, key, r), r;
6};
7import { customAttribute } from 'aurelia-templating';
8import { getLogger } from 'aurelia-logging';
9/**
10 * Attribute to be placed on any HTML element in a view to emit the View instance
11 * to the debug console, giving you insight into the live View instance, including
12 * all child views, live bindings, behaviors and more.
13 */
14var ViewSpy = /** @class */ (function () {
15 /**
16 * Creates a new instance of ViewSpy.
17 */
18 function ViewSpy() {
19 this.logger = getLogger('view-spy');
20 }
21 ViewSpy.prototype._log = function (lifecycleName, context) {
22 if (!this.value && lifecycleName === 'created') {
23 this.logger.info(lifecycleName, this.view);
24 }
25 else if (this.value && this.value.indexOf(lifecycleName) !== -1) {
26 this.logger.info(lifecycleName, this.view, context);
27 }
28 };
29 /**
30 * Invoked when the target view is created.
31 * @param view The target view.
32 */
33 ViewSpy.prototype.created = function (view) {
34 this.view = view;
35 this._log('created');
36 };
37 /**
38 * Invoked when the target view is bound.
39 * @param bindingContext The target view's binding context.
40 */
41 ViewSpy.prototype.bind = function (bindingContext) {
42 this._log('bind', bindingContext);
43 };
44 /**
45 * Invoked when the target element is attached to the DOM.
46 */
47 ViewSpy.prototype.attached = function () {
48 this._log('attached');
49 };
50 /**
51 * Invoked when the target element is detached from the DOM.
52 */
53 ViewSpy.prototype.detached = function () {
54 this._log('detached');
55 };
56 /**
57 * Invoked when the target element is unbound.
58 */
59 ViewSpy.prototype.unbind = function () {
60 this._log('unbind');
61 };
62 ViewSpy = __decorate([
63 customAttribute('view-spy')
64 ], ViewSpy);
65 return ViewSpy;
66}());
67export { ViewSpy };