UNPKG

ng-jhipster

Version:

A Jhipster util library for Angular 2

81 lines (76 loc) 2.49 kB
/* Copyright 2013-2017 the original author or authors from the JHipster project. This file is part of the JHipster project, see https://jhipster.github.io/ for more information. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ import { Injectable } from '@angular/core'; import { Observable } from 'rxjs/Observable'; import 'rxjs/add/operator/filter'; /** * An utility class to manage RX events */ var JhiEventManager = (function () { function JhiEventManager() { var _this = this; this.observable = Observable.create(function (observer) { _this.observer = observer; }).share(); } /** * Method to broadcast the event to observer */ /** * Method to broadcast the event to observer */ JhiEventManager.prototype.broadcast = /** * Method to broadcast the event to observer */ function (event) { if (this.observer != null) { this.observer.next(event); } }; /** * Method to subscribe to an event with callback */ /** * Method to subscribe to an event with callback */ JhiEventManager.prototype.subscribe = /** * Method to subscribe to an event with callback */ function (eventName, callback) { var subscriber = this.observable.filter(function (event) { return event.name === eventName; }).subscribe(callback); return subscriber; }; /** * Method to unsubscribe the subscription */ /** * Method to unsubscribe the subscription */ JhiEventManager.prototype.destroy = /** * Method to unsubscribe the subscription */ function (subscriber) { subscriber.unsubscribe(); }; JhiEventManager.decorators = [ { type: Injectable }, ]; /** @nocollapse */ JhiEventManager.ctorParameters = function () { return []; }; return JhiEventManager; }()); export { JhiEventManager };