This is the simplest type of all the provided events.
export interface Event { on(callback: () => void): number; off(handle: number): void; trigger(): void; } export class SimpleEvent extends BaseEvent<void, void> implements Event { on= (callback: () => void): number => super.add(callback); off= (handler: number): void => super.remove(handler); trigger= (): void => super.getResult(undefined); }
the following test.ts compiled into test.js:
import { SimpleEvent } from "typescript-simpleevents"; class EventTest { readonly action = new SimpleEvent(); doAction() { this.action.trigger(); } } const test = new EventTest(); test.action.on(() => { console.log('Action!'); }); test.doAction();
wil have the output:
> node test.js Action!
There was an error while loading. Please reload this page.
Base Event
Simple Event
Simple Data Event
Simple Cancelable Event
Simple Cancelable Data Event