Repository navigation
Run event handlers the way the DOM runs listeners - #566
Merged
Merged
Conversation
Before, an exception in a handler stopped the rest of the event: when it happened in a `done` or `progress` handler, the bar never hid and pace never restarted again. A handler that removed itself or an earlier handler with Pace.off made the next handler get skipped, Pace.off(event) inside a handler threw, and handlers added while an event fired ran right away. Now, as in DOM event dispatch, an event runs the handlers registered when it fires, minus any removed meanwhile. A `once` handler is removed before it runs, and an exception is reported as an uncaught error without stopping pace or the other handlers. It is reported with reportError where the browser has it, so window.onerror keeps the details even when pace.js comes from a CDN; Safari before 15.4 throws it from a microtask instead. Handlers are stored in a map without a prototype, so event names such as "constructor" work too.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Makes
Pace.on/once/off/triggerrun handlers the way the DOM runs event listeners (spec):reportErrorwhere available, sowindow.onerrorkeeps the details when pace.js comes from a CDN), and pace and the other handlers carry on. Before, a throwingdoneorprogresshandler left the bar stuck for the rest of the page's life.Pace.off(event)inside a handler threw.oncehandler is removed before it runs, so it runs once even if it throws or fires its own event again.The README's events section says what happens when a handler throws, and what
offdoes without a handler.Tests:
tests/handlers.spec.mjscovers each case. Eight of its nine tests fail on the previous code; the ninth (a handler removed while the event fires is not called) already passed and guards the new code.