-
Notifications
You must be signed in to change notification settings - Fork 2
Signals
Vitaly Tomilov edited this page Oct 1, 2024
·
19 revisions
A signal is an event that doesn't send any data. To create such event, use type void
explicitly:
class Signal extends SubEvent<void> {} // reusable Signal type
const s = new Signal(); // creating event-signal
s.emit(); // emitting the signal
And when you need to pass in options, your data will have to be null
or undefined
:
s.emit(null, {schedule: EmitSchedule.next});
s.emit(undefined, {schedule: EmitSchedule.next});
Or you can implement your own, signal-specific trigger
method:
import {SubEvent, IEmitOptions} from 'sub-events';
class Signal extends SubEvent<void> {
trigger(options?: IEmitOptions) {
return this.emit(undefined, options);
}
}
When listening for a once-off signal, see also methods once and toPromise.