Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions packages/next/next-server/lib/mitt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,31 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
// It's been edited for the needs of this script
// See the LICENSE at the top of the file

type Handler = (...evts: any[]) => void

type Handler<T extends any[] = any[]> = (...evts: T) => void
type UrlOnlyEvents =
| 'routeChangeStart'
| 'routeChangeComplete'
| 'beforeHistoryChange'
| 'hashChangeStart'
| 'hashChangeComplete'
type ErrorEvents = 'routeChangeError'
export type MittEmitter = {
on(type: string, handler: Handler): void
off(type: string, handler: Handler): void
emit(type: string, ...evts: any[]): void
on(type: UrlOnlyEvents, handler: Handler<[string]>): void
on(
type: ErrorEvents,
handler: Handler<[unknown & { cancelled?: boolean }, string]>
): void
off(type: UrlOnlyEvents, handler: Handler<[string]>): void
off(
type: ErrorEvents,
handler: Handler<[unknown & { cancelled?: boolean }, string]>
): void
emit(type: UrlOnlyEvents, url: string): void
emit(
type: ErrorEvents,
error: unknown & { cancelled?: boolean },
url: string
): void
}

export default function mitt(): MittEmitter {
Expand Down