18 lines
514 B
TypeScript
18 lines
514 B
TypeScript
import { defineStore } from "pinia";
|
|
|
|
export const useEvent = defineStore('event', () => {
|
|
const events: Partial<Record<EventNames, Function[]>> = {};
|
|
|
|
function Subscribe(name: EventNames, callback: Function) {
|
|
events[name] = events[name] || [];
|
|
events[name].push(callback);
|
|
}
|
|
|
|
function Publish(name: EventNames, ...args: any[]) {
|
|
events[name]?.forEach(e => e(...args));
|
|
}
|
|
|
|
return { Subscribe, Publish };
|
|
});
|
|
|
|
export type EventNames = 'submit' | 'update-texture' |