a6287fc06d
* init db migration * WIP store view * create service call * WIP insertion * insert sort of works * moving code arounmd * creation tests * avoid duplicate entries * fixes from main * basic group retrieval works * group filtering works * WIP view listing * filter by acl * fixes + WIP single group retrieval * wip pivot * more pivot query fixes * tests fixed after pivot * views list tests * fixing test command * business plan only checks * more tests for coverage * .dts import fix * cli fix * anutha one * auth policy tests for business plan access * WIP saved views panel base * BE listing adjustments * WIP group rendering * group render done * WIP post create cache updates * listing fine? * my vs theirs * auto open * minor fixes * click load omg * nicely loading views * type fix * less spammy loading * another type fix: * more lint fix * test fix * codecov disable * moar coverage * fix sidebar flashin * more test coverage * more test cvoverage * minor adfjustments * adj * saved view wipe fixes * CSR viewer * more improvements * extra feature flag checks * lint fix * feature flags fix * more test fixes
49 lines
1.2 KiB
TypeScript
49 lines
1.2 KiB
TypeScript
import type {
|
|
ViewerEventBusKeyPayloadMap,
|
|
ViewerEventBusKeys
|
|
} from '~/lib/viewer/helpers/eventBus'
|
|
|
|
export enum CoreEventBusKeys {
|
|
TestKey = 'test_event_bus'
|
|
}
|
|
|
|
export type EventBusKeys = CoreEventBusKeys | ViewerEventBusKeys
|
|
|
|
// Add mappings between event keys and expected payloads here
|
|
export type EventBusKeyPayloadMap = {
|
|
[CoreEventBusKeys.TestKey]: { foo: string; bar: string }
|
|
} & ViewerEventBusKeyPayloadMap & { [k in EventBusKeys]: unknown } & Record<
|
|
string,
|
|
unknown
|
|
>
|
|
|
|
export function useEventBus() {
|
|
const nuxt = useNuxtApp()
|
|
const $eventBus = nuxt.$eventBus
|
|
const handles = shallowRef<Array<() => void>>([])
|
|
|
|
const on = <T extends EventBusKeys>(
|
|
key: T,
|
|
handler: (event: EventBusKeyPayloadMap[T]) => void
|
|
) => {
|
|
$eventBus.on(key, handler)
|
|
const offHandle = () => $eventBus.off(key, handler)
|
|
handles.value = [...handles.value, offHandle]
|
|
return offHandle
|
|
}
|
|
|
|
onUnmounted(() => {
|
|
handles.value.forEach((quit) => quit())
|
|
handles.value = []
|
|
})
|
|
|
|
return {
|
|
/**
|
|
* Event subscribe w/ automatic cleanup on unmount.
|
|
* Returns a function to manually unsubscribe if needed.
|
|
*/
|
|
on,
|
|
emit: $eventBus.emit
|
|
}
|
|
}
|