mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-20 15:18:08 +02:00
Merge pull request #17967 from Snuffleupagus/eventBus-signal
Add `signal`-support in the `EventBus`, and utilize it in the viewer (PR 17964 follow-up)
This commit is contained in:
commit
bda98b91cb
7 changed files with 246 additions and 223 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