lik/dist/lik.observablemap.js
2017-10-24 13:19:52 +02:00

35 lines
2.4 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const plugins = require("./lik.plugins");
const lik_objectmap_1 = require("./lik.objectmap");
/**
* manages observables by making sure that only one observable is regsitered per event
*/
class Observablemap {
constructor() {
this.ObservableEmitterBundleObjectmap = new lik_objectmap_1.Objectmap();
}
/**
* creates a new observable if not yet registered for the same event.
* In case event has been registered before the same observable is returned.
*/
getObservableForEmitterEvent(emitterArg, eventArg) {
let existingBundle = this.ObservableEmitterBundleObjectmap.find((bundleArg) => {
return (bundleArg.emitter === emitterArg && bundleArg.event === eventArg);
});
if (existingBundle) {
return existingBundle.observable;
}
else {
let emitterObservable = plugins.rx.Observable.fromEvent(emitterArg, eventArg);
this.ObservableEmitterBundleObjectmap.add({
observable: emitterObservable,
emitter: emitterArg,
event: eventArg
});
return emitterObservable;
}
}
}
exports.Observablemap = Observablemap;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibGlrLm9ic2VydmFibGVtYXAuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9saWsub2JzZXJ2YWJsZW1hcC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUFBLHlDQUF3QztBQUN4QyxtREFBMkM7QUFhM0M7O0dBRUc7QUFDSDtJQUFBO1FBQ0UscUNBQWdDLEdBQUcsSUFBSSx5QkFBUyxFQUEyQixDQUFBO0lBc0I3RSxDQUFDO0lBcEJDOzs7T0FHRztJQUNILDRCQUE0QixDQUFFLFVBQXVDLEVBQUUsUUFBZ0I7UUFDckYsSUFBSSxjQUFjLEdBQUcsSUFBSSxDQUFDLGdDQUFnQyxDQUFDLElBQUksQ0FBQyxDQUFDLFNBQVMsRUFBRSxFQUFFO1lBQzVFLE1BQU0sQ0FBQyxDQUFDLFNBQVMsQ0FBQyxPQUFPLEtBQUssVUFBVSxJQUFJLFNBQVMs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