UNPKG

tixif-ngx-busy

Version:

Angular 2 Busy: show busy/loading indicators on any promise, or on any Observable's subscription

98 lines 4.07 kB
"use strict"; /** * @file Component: Busy * @author yumao<yuzhang.lille@gmail.com> */ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 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; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; Object.defineProperty(exports, "__esModule", { value: true }); var core_1 = require("@angular/core"); var animations_1 = require("@angular/animations"); var promise_tracker_service_1 = require("./promise-tracker.service"); var inactiveStyle = animations_1.style({ opacity: 0, transform: 'translateY(-40px)' }); var timing = '.3s ease'; ; var BusyComponent = /** @class */ (function () { function BusyComponent(tracker, compiler) { this.tracker = tracker; this.compiler = compiler; } BusyComponent.prototype.ngDoCheck = function () { if (this.message === this.lastMessage) { return; } this.lastMessage = this.message; this.clearDynamicTemplateCache(); this.createDynamicTemplate(); }; BusyComponent.prototype.ngOnDestroy = function () { this.clearDynamicTemplateCache(); }; BusyComponent.prototype.createDynamicTemplate = function () { var _a = this, template = _a.template, message = _a.message; var TemplateComponent = /** @class */ (function () { function TemplateComponent() { this.message = message; } TemplateComponent = __decorate([ core_1.Component({ template: template }) ], TemplateComponent); return TemplateComponent; }()); var TemplateModule = /** @class */ (function () { function TemplateModule() { } TemplateModule = __decorate([ core_1.NgModule({ declarations: [TemplateComponent], entryComponents: [TemplateComponent] }) ], TemplateModule); return TemplateModule; }()); this.TemplateComponent = TemplateComponent; this.nmf = this.compiler.compileModuleSync(TemplateModule); }; BusyComponent.prototype.clearDynamicTemplateCache = function () { if (!this.nmf) { return; } this.compiler.clearCacheFor(this.nmf.moduleType); this.nmf = null; }; BusyComponent.prototype.isActive = function () { return this.tracker.isActive(); }; BusyComponent = __decorate([ core_1.Component({ selector: 'ng-busy', template: "\n <div [class]=\"wrapperClass\" *ngIf=\"isActive()\" @flyInOut>\n <ng-container *ngComponentOutlet=\"TemplateComponent; ngModuleFactory: nmf;\"></ng-container>\n </div>\n ", animations: [ animations_1.trigger('flyInOut', [ animations_1.transition('void => *', [ inactiveStyle, animations_1.animate(timing) ]), animations_1.transition('* => void', [ animations_1.animate(timing, inactiveStyle) ]) ]) ] }), __metadata("design:paramtypes", [promise_tracker_service_1.PromiseTrackerService, core_1.Compiler]) ], BusyComponent); return BusyComponent; }()); exports.BusyComponent = BusyComponent; //# sourceMappingURL=busy.component.js.map