ng-jhipster
Version:
A Jhipster util library for Angular 2
56 lines (55 loc) • 1.8 kB
JavaScript
/*
* Copyright 2016 the original author or authors.
*
* 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/Rx';
/**
* An utily class to manage RX events
*/
export var EventManager = (function () {
function EventManager() {
var _this = this;
this.observable = Observable.create(function (observer) {
_this.observer = observer;
}).share();
}
/**
* Method to broadcast the event to observer
*/
EventManager.prototype.broadcast = function (event) {
this.observer.next(event);
};
/**
* Method to subscribe to an event with callback
*/
EventManager.prototype.subscribe = function (eventName, callback) {
var subscriber = this.observable.filter(function (event) {
return event.name === eventName;
}).subscribe(callback);
return subscriber;
};
/**
* Method to unsubscribe the subscribion
*/
EventManager.prototype.destroy = function (subscriber) {
subscriber.unsubscribe();
};
EventManager.decorators = [
{ type: Injectable },
];
/** @nocollapse */
EventManager.ctorParameters = function () { return []; };
return EventManager;
}());