-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ab4997a
commit 870693e
Showing
2 changed files
with
9 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,28 @@ | ||
export default function handler() { | ||
let eventTarget = document.body.appendChild(document.createComment('')); | ||
let eventListener, eventKey; | ||
export default function() { | ||
let eventTarget, eventListener, eventKey; | ||
|
||
return { | ||
on(type, listener, key) { | ||
eventTarget = eventTarget || document.body.appendChild(document.createComment('')); | ||
eventKey = key; | ||
eventListener = function(e) { listener(e.detail); }; | ||
eventTarget.addEventListener(type, eventListener); | ||
}, | ||
once(type, listener, key) { | ||
eventTarget = eventTarget || document.body.appendChild(document.createComment('')); | ||
eventKey = key; | ||
eventListener = function(e) { listener(e.detail); }; | ||
eventTarget.addEventListener(type, eventListener, { once: true }); | ||
}, | ||
off(type, key) { | ||
if (eventListener && eventKey === key) { | ||
if (eventTarget && eventListener && eventKey === key) { | ||
eventTarget.removeEventListener(type, eventListener); | ||
} | ||
}, | ||
emit(type, detail) { | ||
eventTarget.dispatchEvent(new CustomEvent(type, { detail })); | ||
if (eventTarget) { | ||
eventTarget.dispatchEvent(new CustomEvent(type, { detail })); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
import {EventBus} from 'primevue/utils'; | ||
import EventBus from './EventBus.js'; | ||
|
||
export default EventBus(); |