/** * Created by mm28969 on 10/25/16. */ export class Channel { observerMap; constructor() { this.observerMap = {}; } subscribe(observerId, observer: Function){ this.observerMap[observerId] = observer; } unsubscribe(observerId, observer: Function){ delete this.observerMap[observerId]; } notify(payload) { let observerId, observer: Function; for (observerId in this.observerMap) { if (this.observerMap.hasOwnProperty(observerId)) { observer = this.observerMap[observerId]; observer(payload); } } } get details() { let observerCount = Object.keys(this.observerMap).length; return { observerCount: observerCount } } }