mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
Add signal
-support in the EventBus
, and utilize it in the viewer (PR 17964 follow-up)
This mimics the `signal` option that's available for `addEventListener`, see [MDN](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#signal).
This commit is contained in:
parent
5ad42c13ad
commit
702ee7b1e1
3 changed files with 148 additions and 130 deletions
|
@ -143,6 +143,60 @@ describe("event_utils", function () {
|
|||
expect(onceCount).toEqual(1);
|
||||
});
|
||||
|
||||
it("dispatch event to handlers with/without 'signal' option, aborted *before* dispatch", function () {
|
||||
const eventBus = new EventBus();
|
||||
const ac = new AbortController();
|
||||
let multipleCount = 0,
|
||||
noneCount = 0;
|
||||
|
||||
eventBus.on("test", function () {
|
||||
multipleCount++;
|
||||
});
|
||||
eventBus.on(
|
||||
"test",
|
||||
function () {
|
||||
noneCount++;
|
||||
},
|
||||
{ signal: ac.signal }
|
||||
);
|
||||
|
||||
ac.abort();
|
||||
|
||||
eventBus.dispatch("test");
|
||||
eventBus.dispatch("test");
|
||||
eventBus.dispatch("test");
|
||||
|
||||
expect(multipleCount).toEqual(3);
|
||||
expect(noneCount).toEqual(0);
|
||||
});
|
||||
|
||||
it("dispatch event to handlers with/without 'signal' option, aborted *after* dispatch", function () {
|
||||
const eventBus = new EventBus();
|
||||
const ac = new AbortController();
|
||||
let multipleCount = 0,
|
||||
onceCount = 0;
|
||||
|
||||
eventBus.on("test", function () {
|
||||
multipleCount++;
|
||||
});
|
||||
eventBus.on(
|
||||
"test",
|
||||
function () {
|
||||
onceCount++;
|
||||
},
|
||||
{ signal: ac.signal }
|
||||
);
|
||||
|
||||
eventBus.dispatch("test");
|
||||
ac.abort();
|
||||
|
||||
eventBus.dispatch("test");
|
||||
eventBus.dispatch("test");
|
||||
|
||||
expect(multipleCount).toEqual(3);
|
||||
expect(onceCount).toEqual(1);
|
||||
});
|
||||
|
||||
it("should not re-dispatch to DOM", async function () {
|
||||
if (isNodeJS) {
|
||||
pending("Document is not supported in Node.js.");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue