Skip to main content
Version: next

Complex event payloads

You can pass any type as the event payload. If you've got a particular complex, consider creating a dedicated payload type for it. This makes writing listeners a little easier as you can use the type for the parameters.

Examples
ts
interface ComplexEventPayload {
foobar: {
name: string;
enabled: boolean;
};
option: 'a'|'b';
}
// Creating event
const complexEvent = new SimpleEvent<ComplexEventPayload>();
// Listening
function listener(payload: ComplexEventPayload) {
// ...
}
complexEvent.subscribe(listener);
// Firing
complexEvent.dispatch({
foobar: {
name: 'guest',
enabled: true,
},
option: 'b',
});
Examples
ts
interface ComplexEventPayload {
foobar: {
name: string;
enabled: boolean;
};
option: 'a'|'b';
}
// Creating event
const complexEvent = new SimpleEvent<ComplexEventPayload>();
// Listening
function listener(payload: ComplexEventPayload) {
// ...
}
complexEvent.subscribe(listener);
// Firing
complexEvent.dispatch({
foobar: {
name: 'guest',
enabled: true,
},
option: 'b',
});

See events for more information.