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