Type event store

This commit is contained in:
Adria Navarro 2024-12-30 13:59:08 +01:00
parent 0c937e0827
commit d476a5c5cd
2 changed files with 7 additions and 8 deletions

View File

@ -2,11 +2,11 @@ import { createEventDispatcher } from "svelte"
export const createEventManagers = () => { export const createEventManagers = () => {
const svelteDispatch = createEventDispatcher() const svelteDispatch = createEventDispatcher()
let subscribers = {} let subscribers: Record<string, ((...params: any) => void)[]> = {}
// Dispatches an event, notifying subscribers and also emitting a normal // Dispatches an event, notifying subscribers and also emitting a normal
// svelte event // svelte event
const dispatch = (event, payload) => { const dispatch = (event: string, payload: any) => {
svelteDispatch(event, payload) svelteDispatch(event, payload)
const subs = subscribers[event] || [] const subs = subscribers[event] || []
for (let i = 0; i < subs.length; i++) { for (let i = 0; i < subs.length; i++) {
@ -15,7 +15,7 @@ export const createEventManagers = () => {
} }
// Subscribes to events // Subscribes to events
const subscribe = (event, callback) => { const subscribe = (event: string, callback: () => void) => {
const subs = subscribers[event] || [] const subs = subscribers[event] || []
subscribers[event] = [...subs, callback] subscribers[event] = [...subs, callback]

View File

@ -79,6 +79,8 @@ export interface BaseStore {
API: APIClient API: APIClient
gridID: string gridID: string
props: Writable<BaseStoreProps> props: Writable<BaseStoreProps>
subscribe: any
dispatch: (event: string, data: any) => any
} }
export type Store = BaseStore & export type Store = BaseStore &
@ -93,11 +95,8 @@ export type Store = BaseStore &
Filter.Store & Filter.Store &
UI.Store & UI.Store &
Clipboard.Store & Clipboard.Store &
Scroll.Store & { Scroll.Store &
// TODO while typing the rest of stores Rows.Store &
subscribe: any
dispatch: (event: string, data: any) => any
} & Rows.Store &
Reorder.Store & Reorder.Store &
Resize.Store & Resize.Store &
Config.Store & Config.Store &