ste-signals
Version:
Add the power of Signals to your projects. They are the most bare bones implementation of an event.
50 lines (49 loc) • 1.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SignalDispatcher = void 0;
const ste_core_1 = require("ste-core");
/**
* The dispatcher handles the storage of subsciptions and facilitates
* subscription, unsubscription and dispatching of a signal event.
*
* @export
* @class SignalDispatcher
* @extends {DispatcherBase<ISignalHandler>}
* @implements {ISignal}
*/
class SignalDispatcher extends ste_core_1.DispatcherBase {
/**
* Dispatches the signal.
*
* @returns {IPropagationStatus} The status of the signal.
*
* @memberOf SignalDispatcher
*/
dispatch() {
const result = this._dispatch(false, this, arguments);
if (result == null) {
throw new ste_core_1.DispatchError("Got `null` back from dispatch.");
}
return result;
}
/**
* Dispatches the signal without waiting for the result.
*
* @memberOf SignalDispatcher
*/
dispatchAsync() {
this._dispatch(true, this, arguments);
}
/**
* Creates an event from the dispatcher. Will return the dispatcher
* in a wrapper. This will prevent exposure of any dispatcher methods.
*
* @returns {ISignal} The signal.
*
* @memberOf SignalDispatcher
*/
asEvent() {
return super.asEvent();
}
}
exports.SignalDispatcher = SignalDispatcher;