mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
Replace a bunch of Array.prototype.forEach()
cases with for...of
loops instead
Using `for...of` is a modern and generally much nicer pattern, since it gets rid of unnecessary callback-functions. (In a couple of spots, a "regular" `for` loop had to be used.)
This commit is contained in:
parent
da0e7ea969
commit
da22146b95
14 changed files with 67 additions and 71 deletions
|
@ -775,22 +775,22 @@ class EventBus {
|
|||
let externalListeners;
|
||||
// Making copy of the listeners array in case if it will be modified
|
||||
// during dispatch.
|
||||
eventListeners.slice(0).forEach(({ listener, external, once }) => {
|
||||
for (const { listener, external, once } of eventListeners.slice(0)) {
|
||||
if (once) {
|
||||
this._off(eventName, listener);
|
||||
}
|
||||
if (external) {
|
||||
(externalListeners ||= []).push(listener);
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
listener.apply(null, args);
|
||||
});
|
||||
}
|
||||
// Dispatch any "external" listeners *after* the internal ones, to give the
|
||||
// viewer components time to handle events and update their state first.
|
||||
if (externalListeners) {
|
||||
externalListeners.forEach(listener => {
|
||||
for (const listener of externalListeners) {
|
||||
listener.apply(null, args);
|
||||
});
|
||||
}
|
||||
externalListeners = null;
|
||||
}
|
||||
if (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue