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

View File

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