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

[api-minor] Deprecate getGlobalEventBus and update the "viewer components" examples accordingly #11631

Merged

Conversation

Snuffleupagus
Copy link
Collaborator

@Snuffleupagus Snuffleupagus commented Feb 26, 2020

  • [api-minor] Deprecate getGlobalEventBus and update the "viewer components" examples accordingly

    To avoid outright breaking third-party usages of the "viewer components" the getGlobalEventBus functionality is left intact, but a deprecation message is printed if the function is invoked.

    The various examples are updated to explicitly initialize an EventBus instance, and provide that when initializing the relevant viewer components.

  • Re-factor the EventBus to allow servicing of "external" event listeners after the viewer components have updated

    Since the goal has always been, essentially since the EventBus abstraction was added, to remove all dispatching of DOM events[1] from the viewer components this patch tries to address one thing that came up when updating the examples:
    The DOM events are always dispatched last, and it's thus guaranteed that all internal event listeners have been invoked first.
    However, there's no such guarantees with the general EventBus functionality and the order in which event listeners are invoked is not specified. With the promotion of the EventBus in the examples, over DOM events, it seems like a good idea to at least try to keep this ordering invariant[2] intact.

    Obviously this won't prevent anyone from manually calling the new internal viewer component methods on the EventBus, but hopefully that won't be too common since any existing third-party code would obviously use the on/off methods and that all of the examples shows the correct usage (which should be similarily documented on the "Third party viewer usage" Wiki-page).


    [1] Looking at the various Firefox-tests, I'm not sure that it'll be possible to (easily) re-write all of them to not rely on DOM events (since getting access to PDFViewerApplication might be generally difficult/messy depending on scopes).
    In any case, even if technically feasible, it would most likely add a lot of complication that may not be desireable in the various Firefox-tests. All-in-all, I'd be fine with keeping the DOM events only for the MOZCENTRAL target and gated on Cu.isInAutomation (or similar) rather than a preference.

    [2] I wouldn't expect any real bugs in a custom implementation, simply based on event ordering, but it nonetheless seem like a good idea if any "external" events are still handled last.

@Snuffleupagus Snuffleupagus force-pushed the getGlobalEventBus-deprecate branch 4 times, most recently from 44a0d42 to 1961cf5 Compare February 27, 2020 11:30
@Snuffleupagus Snuffleupagus marked this pull request as ready for review February 27, 2020 11:32
@Snuffleupagus Snuffleupagus mentioned this pull request Feb 27, 2020
3 tasks
…onents" examples accordingly

To avoid outright breaking third-party usages of the "viewer components" the `getGlobalEventBus` functionality is left intact, but a deprecation message is printed if the function is invoked.

The various examples are updated to *explicitly* initialize an `EventBus` instance, and provide that when initializing the relevant viewer components.
@Snuffleupagus Snuffleupagus force-pushed the getGlobalEventBus-deprecate branch 3 times, most recently from cb3796b to f8760ec Compare February 27, 2020 15:37
…ners *after* the viewer components have updated

Since the goal has always been, essentially since the `EventBus` abstraction was added, to remove all dispatching of DOM events[1] from the viewer components this patch tries to address one thing that came up when updating the examples:
The DOM events are always dispatched last, and it's thus guaranteed that all internal event listeners have been invoked first.
However, there's no such guarantees with the general `EventBus` functionality and the order in which event listeners are invoked is *not* specified. With the promotion of the `EventBus` in the examples, over DOM events, it seems like a good idea to at least *try* to keep this ordering invariant[2] intact.

Obviously this won't prevent anyone from manually calling the new *internal* viewer component methods on the `EventBus`, but hopefully that won't be too common since any existing third-party code would obviously use the `on`/`off` methods and that all of the examples shows the *correct* usage (which should be similarily documented on the "Third party viewer usage" Wiki-page).

---
[1] Looking at the various Firefox-tests, I'm not sure that it'll be possible to (easily) re-write all of them to not rely on DOM events (since getting access to `PDFViewerApplication` might be generally difficult/messy depending on scopes).
In any case, even if technically feasible, it would most likely add *a lot* of complication that may not be desireable in the various Firefox-tests. All-in-all, I'd be fine with keeping the DOM events only for the `MOZCENTRAL` target and gated on `Cu.isInAutomation` (or similar) rather than a preference.

[2] I wouldn't expect any *real* bugs in a custom implementation, simply based on event ordering, but it nonetheless seem like a good idea if any "external" events are still handled last.
@Snuffleupagus
Copy link
Collaborator Author

/botio-linux preview

@pdfjsbot
Copy link

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/6c5a9d5961f055f/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/6c5a9d5961f055f/output.txt

Total script time: 2.55 mins

Published

@Snuffleupagus
Copy link
Collaborator Author

/botio unittest

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Received

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

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

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

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

Live output at: http://54.215.176.217:8877/a509b807393f2e8/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux m4)


Success

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

Total script time: 2.69 mins

  • Unit Tests: Passed

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://54.215.176.217:8877/a509b807393f2e8/output.txt

Total script time: 4.81 mins

  • Unit Tests: Passed

@timvandermeij timvandermeij merged commit 52749d1 into mozilla:master Mar 2, 2020
@timvandermeij
Copy link
Contributor

Nice step towards less DOM event usage. Thanks!

@Snuffleupagus Snuffleupagus deleted the getGlobalEventBus-deprecate branch March 2, 2020 22:36
@timvandermeij
Copy link
Contributor

I have also updated https://github.com/mozilla/pdf.js/wiki/Third-party-viewer-usage now.

@Snuffleupagus
Copy link
Collaborator Author

Snuffleupagus commented Mar 2, 2020

I have also updated https://github.com/mozilla/pdf.js/wiki/Third-party-viewer-usage now.

Thanks; I've also got a suggested update to the pre-existing example in that Wiki-page in a commit message for a future patch series (which should obviously not land until after the upcoming release): master...Snuffleupagus:rm-getGlobalEventBus

Edit: Also, since the "EventBus" section seems more tailored to the components (rather than the default viewer as the rest of the page seems mainly concerned with) perhaps reference https://github.com/mozilla/pdf.js/tree/master/examples/components prominently in that section to avoid misunderstandings.

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.

None yet

3 participants