Skip to content

Commit

Permalink
Debounce MutationObserver callback for performance improvements
Browse files Browse the repository at this point in the history
Debounce the `_update` method to improve browser performance in
responding to DOM mutations (PDF annotation highlights re-draw
more smoothly).
  • Loading branch information
lyzadanger committed Sep 25, 2020
1 parent 03f1821 commit 14d5b72
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/annotator/plugin/pdf.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Plugin = require('../plugin')
debounce = require('lodash.debounce')

{ default: RenderingStates } = require('../pdfjs-rendering-states')

Expand All @@ -16,7 +17,7 @@ module.exports = class PDF extends Plugin

@pdfMetadata = new PDFMetadata(PDFViewerApplication)

@observer = new MutationObserver((mutations) => this._update())
@observer = new MutationObserver(debounce(this._update.bind(this), 100))
@observer.observe(@pdfViewer.viewer, {
attributes: true
attributeFilter: ['data-loaded']
Expand Down

0 comments on commit 14d5b72

Please sign in to comment.