Type event store
This commit is contained in:
parent
0c937e0827
commit
d476a5c5cd
|
@ -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]
|
||||
|
|
@ -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 &
|
||||
|
|
Loading…
Reference in New Issue