addEventListener: "once" option does not have any effect if called on instance

WebViewer Version: @pdftron/pdfjs-express-viewer 8.2.1

Do you have an issue with a specific file(s)? No
Can you reproduce using one of our samples or online demos? No
Are you using the WebViewer server? No
Does the issue only happen on certain browsers? No
Is your issue related to a front-end framework? No
Is your issue related to annotations? No

Please give a brief summary of your issue:

instance.addEventListener does not respect the “once” option

Please describe your issue and provide steps to reproduce it:

I wanted to a ‘documentLoaded’ event listener to the web viewer, that is only executed one time and then gets removed. While the event callback got executed fine, the ‘once’ option was ignored and the callback got called multiple times.

Please provide a link to a minimal sample where the issue is reproducible:

This callback works, but ignores the ‘once’ option:

instance.addEventListener('documentLoaded', () => { }, { once: true })

While here, everything works as advertised:

instance.Core.documentViewer.addEventListener('documentLoaded', () => { }, { once: true })

Either the former can be fixed, or the documentation should state the difference.

Hi Andre,

The instance.addEventListener is deprecated and actually maps to the UI’s event handler.
As you can see from the API definition, UI.addEventListener API does not take in options and therefore they are not handled by the function.

This is for now expected behaviour.
Please use the second example you provided to add a documentLoaded listener that only gets called once.

Best Regards,
Ahmad Moaaz
Software Developer
PDFTron Systems, Inc.

Thanks for clarifying! The namespaces are a still a bit confusing to me…
So the functions on instance itself should not be used at all anymore? I somehow missed that.

Hi Andre,

Yes, that is correct. The functions directly under the instance namespace are deprecated and will be removed in version 9.0

All those functions can now be accessed under either the UI namespace or the Core namespace depending on what it corresponds with.

Best Regards,
Ahmad Moaaz
Software Developer
PDFTron Systems, Inc.