Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-factor the dispatching of "attachmentsloaded" events, when the PDF document contains no "regular" attachments #12163

Merged

Conversation

Snuffleupagus
Copy link
Collaborator

  • Use a DocumentFragment when building the attachmentsView in PDFAttachmentViewer.render

    This approach is already used in other parts of the code-base, see e.g. PDFOutlineViewer, and has the advantage of only invalidating the DOM once rather than for every attachment item.

  • Re-factor the dispatching of "attachmentsloaded" events, when the PDF document contains no "regular" attachments

    Since the attachment fetching/parsing is already asynchronous, possibly delaying the dispatching of an "attachmentsloaded" event should thus not be a problem in general.
    Note that in some cases, i.e. PDF documents with no "regular" attachments and only FileAttachment annotations, we'll thus no longer dispatch an "attachmentsloaded" event when attachmentsCount === 0 and instead wait for the FileAttachment parsing to finish. (The use of a timeout still guarantees that an "attachmentsloaded" event is eventually dispatched though.)

    This patch considerably simplifies the "attachmentsloaded" event handler, in PDFSidebar, since the details are now abstracted away from the consumer.

    Finally, add a check in _appendAttachment to ensure (indirectly) that the FileAttachment annotation is actually relevant for the active document.

…achmentViewer.render`

This approach is already used in other parts of the code-base, see e.g. `PDFOutlineViewer`, and has the advantage of only invalidating the DOM once rather than for every attachment item.
… document contains no "regular" attachments

Since the attachment fetching/parsing is already asynchronous, possibly delaying the dispatching of an "attachmentsloaded" event should thus not be a problem in general.
Note that in some cases, i.e. PDF documents with no "regular" attachments and only FileAttachment annotations, we'll thus no longer dispatch an "attachmentsloaded" event when `attachmentsCount === 0` and instead wait for the FileAttachment parsing to finish. (The use of a timeout still guarantees that an "attachmentsloaded" event is *eventually* dispatched though.)

This patch *considerably* simplifies the "attachmentsloaded" event handler, in `PDFSidebar`, since the details are now abstracted away from the consumer.

Finally, add a check in `_appendAttachment` to ensure (indirectly) that the FileAttachment annotation is actually relevant for the active document.
@Snuffleupagus
Copy link
Collaborator Author

/botio-linux preview

@pdfjsbot
Copy link

pdfjsbot commented Aug 3, 2020

From: Bot.io (Linux m4)


Received

Command cmd_preview from @Snuffleupagus received. Current queue size: 0

Live output at: http://54.67.70.0:8877/b0da5d5fc2fe904/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Aug 3, 2020

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/b0da5d5fc2fe904/output.txt

Total script time: 3.50 mins

Published

@timvandermeij timvandermeij merged commit 85982c4 into mozilla:master Aug 4, 2020
@timvandermeij
Copy link
Contributor

I agree that this is a simpler approach. Thanks!

@Snuffleupagus Snuffleupagus deleted the improve-PDFAttachmentViewer-render branch August 4, 2020 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants