mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 06:26:16 +00:00
Add app command/search (#622)
This commit is contained in:
16
resources/js/lib/event-bus.tsx
Normal file
16
resources/js/lib/event-bus.tsx
Normal file
@ -0,0 +1,16 @@
|
||||
type Callback = (data: unknown) => void;
|
||||
|
||||
const events: Record<string, Callback[]> = {};
|
||||
|
||||
export const EventBus = {
|
||||
on(event: string, callback: Callback) {
|
||||
if (!events[event]) events[event] = [];
|
||||
events[event].push(callback);
|
||||
},
|
||||
off(event: string, callback: Callback) {
|
||||
events[event] = events[event]?.filter((cb) => cb !== callback) || [];
|
||||
},
|
||||
emit(event: string, data?: unknown) {
|
||||
events[event]?.forEach((cb) => cb(data));
|
||||
},
|
||||
};
|
Reference in New Issue
Block a user