mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 01:10:08 +02:00
Support the once
option, when registering EventBus
listeners
This follows the same principle as the `once` option that exists in the native `addEventListener` method, and will thus automatically remove an `EventBus` listener when it's invoked; see https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Parameters Finally, this patch also tweaks some the existing `EventBus`-code to use modern features such as optional chaining and logical assignment operators.
This commit is contained in:
parent
3e34281e3b
commit
739d7c6d77
4 changed files with 60 additions and 26 deletions
|
@ -76,11 +76,13 @@ class PDFHistory {
|
|||
this.eventBus._on("pagesinit", () => {
|
||||
this._isPagesLoaded = false;
|
||||
|
||||
const onPagesLoaded = evt => {
|
||||
this.eventBus._off("pagesloaded", onPagesLoaded);
|
||||
this._isPagesLoaded = !!evt.pagesCount;
|
||||
};
|
||||
this.eventBus._on("pagesloaded", onPagesLoaded);
|
||||
this.eventBus._on(
|
||||
"pagesloaded",
|
||||
evt => {
|
||||
this._isPagesLoaded = !!evt.pagesCount;
|
||||
},
|
||||
{ once: true }
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue