UNPKG

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