mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Re-factor the LoopbackPort
class to use *proper* private fields
This commit is contained in:
parent
7404091787
commit
499610779e
1 changed files with 9 additions and 10 deletions
|
@ -1853,34 +1853,33 @@ class PDFPageProxy {
|
|||
}
|
||||
|
||||
class LoopbackPort {
|
||||
constructor() {
|
||||
this._listeners = [];
|
||||
this._deferred = Promise.resolve();
|
||||
}
|
||||
#listeners = [];
|
||||
|
||||
#deferred = Promise.resolve();
|
||||
|
||||
postMessage(obj, transfers) {
|
||||
const event = {
|
||||
data: structuredClone(obj, transfers),
|
||||
};
|
||||
|
||||
this._deferred.then(() => {
|
||||
for (const listener of this._listeners) {
|
||||
this.#deferred.then(() => {
|
||||
for (const listener of this.#listeners) {
|
||||
listener.call(this, event);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
addEventListener(name, listener) {
|
||||
this._listeners.push(listener);
|
||||
this.#listeners.push(listener);
|
||||
}
|
||||
|
||||
removeEventListener(name, listener) {
|
||||
const i = this._listeners.indexOf(listener);
|
||||
this._listeners.splice(i, 1);
|
||||
const i = this.#listeners.indexOf(listener);
|
||||
this.#listeners.splice(i, 1);
|
||||
}
|
||||
|
||||
terminate() {
|
||||
this._listeners.length = 0;
|
||||
this.#listeners.length = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue