mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
0c7089f856
This fixes one of the crucial bug in Next.js The issue happens when you try to load a page when it's prefetching. With mitt, it only fires the first registered event.
22 lines
418 B
JavaScript
22 lines
418 B
JavaScript
export default class EventEmitter {
|
|
listeners = {}
|
|
|
|
on (event, cb) {
|
|
if (!this.listeners[event]) {
|
|
this.listeners[event] = new Set()
|
|
}
|
|
|
|
this.listeners[event].add(cb)
|
|
}
|
|
|
|
emit (event, ...data) {
|
|
if (!this.listeners[event]) return
|
|
this.listeners[event].forEach(cb => cb(...data))
|
|
}
|
|
|
|
off (event, cb) {
|
|
if (!this.listeners[event]) return
|
|
this.listeners[event].delete(cb)
|
|
}
|
|
}
|