Skip to content
Source
Sign inSign up
TanStack/form
Open History to see the last commit

testEventBus.ts

17 lines629 Bytes

1export function connectTestEventBus(): () => void {
2 const handleConnect = () => {
3 window.dispatchEvent(new CustomEvent('tanstack-connect-success'))
4 }
5 const handleDispatch = (event: Event) => {
6 const payload = (event as CustomEvent).detail
7 window.dispatchEvent(new CustomEvent(payload.type, { detail: payload }))
8 }
9​
10 window.addEventListener('tanstack-connect', handleConnect)
11 window.addEventListener('tanstack-dispatch-event', handleDispatch)
12​
13 return () => {
14 window.removeEventListener('tanstack-connect', handleConnect)
15 window.removeEventListener('tanstack-dispatch-event', handleDispatch)
16 }