stash/ui/v2.5/src/hooks/event.ts
Raghavan 6a9175c954
Implement UI event dispatcher/listener (#4492)
* page change event
* expose event to plugin api
* Update UIPluginApi.md
* Add to example plugin
---------
Co-authored-by: WithoutPants <53250216+WithoutPants@users.noreply.github.com>
2024-02-27 09:27:28 +11:00

19 lines
403 B
TypeScript

class StashEvent extends EventTarget {
dispatch(event: string, id?: string, data?: object) {
event = `stash:${event}${id ? `:${id}` : ""}`;
this.dispatchEvent(
new CustomEvent(event, {
detail: {
event: event,
...(id ? { id } : {}),
...(data ? { data } : {}),
},
})
);
}
}
const Event = new StashEvent();
export default Event;