UNPKG

@hamstudy/flamp

Version:

JavaScript Amateur Multicast Protocol AMP-2 Version 3 Implemented from specification document http://www.w1hkj.com/files/flamp/Amp-2.V3.0.Protocol.pdf • Version 1.0.0 - W5ALT, Walt Fair, Jr. (Derived From) • Version 2.0.0 - W1HKJ, Dave Freese, w

37 lines (36 loc) 1.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** passes through events as they happen. You will not get events from before you start listening */ class TypedEvent { constructor() { this.listeners = []; this.listenersOncer = []; this.on = (listener) => { this.listeners.push(listener); return { dispose: () => this.off(listener) }; }; this.once = (listener) => { this.listenersOncer.push(listener); }; this.off = (listener) => { var callbackIndex = this.listeners.indexOf(listener); if (callbackIndex > -1) this.listeners.splice(callbackIndex, 1); }; this.emit = (event) => { /** Update any general listeners */ this.listeners.forEach((listener) => listener(event)); /** Clear the `once` queue */ if (this.listenersOncer.length > 0) { this.listenersOncer.forEach((listener) => listener(event)); this.listenersOncer = []; } }; this.pipe = (te) => { return this.on((e) => te.emit(e)); }; } } exports.TypedEvent = TypedEvent;