UNPKG

@tendrock/lib

Version:

A lib under the Tendrock system for Minecraft Bedrock Script API

24 lines (23 loc) 641 B
export class EventSignal { constructor(bus, eventName) { this._eventBus = bus; this._eventType = eventName; } subscribe(callback) { this._eventBus.subscribe(this._eventType, callback); return callback; } subscribeOnce(callback) { const wrappedCallback = (event) => { this.unsubscribe(wrappedCallback); callback(event); }; this.subscribe(wrappedCallback); return () => { this.unsubscribe(wrappedCallback); }; } unsubscribe(callback) { this._eventBus.unsubscribe(this._eventType, callback); } }