Created
February 9, 2017 16:05
-
-
Save mattkelley/eba07d1bb3d6ff92a5adc64d6e2c0548 to your computer and use it in GitHub Desktop.
overriding the default Event system in favor of a more performant, feature rich event emitter (eventemitter3)
This file contains 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
import EventEmitter from 'eventemitter3' | |
import pdfjs from 'pdfjs-dist' | |
const el = document.getElementById('my-viewer') | |
// create instance of EventEmitter 3 | |
const eventBus = new EventEmitter() | |
// create a document Viewer and pass our event emitter instance | |
// see: https://github.com/mozilla/pdfjs-dist/blob/master/web/pdf_viewer.js#L2593 | |
const viewer = pdfjs.PDFViewer({ | |
container: el, | |
eventBus: eventBus | |
}) | |
// now when the viewer emits an event it emits it on eventemitter isntance, not the DOM element | |
ee.on('pagechange', function(e) { | |
console.log('the page changed', e) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment