Skip to content

Instantly share code, notes, and snippets.

@mattkelley
Created February 9, 2017 16:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattkelley/eba07d1bb3d6ff92a5adc64d6e2c0548 to your computer and use it in GitHub Desktop.
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)
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