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

Introducing EventBus for the viewer UI. #7254

Merged
merged 2 commits into from
Apr 28, 2016

Conversation

yurydelendik
Copy link
Contributor

@yurydelendik yurydelendik commented Apr 26, 2016

Goal is to reduce amount of callback and dependencies in the application modules. Currently we use DOM events, but they are inconsistent. Replacing all of that with custom EventBus -- we will have one per application. If event bus is not provided, it will use (legacy) global one, which will relay events for the DOM.

Future work will include replacing direct binding between button events with sending DOM events to the event bus, then processing them from app, e.g. toolbar and secondary toolbar will send a presentation mode event, which will be relayed to the presentation mode module (notice that this event shall be handled sync too, which is the reason why we cannot choose async event bus).

Blocks #7204 and #7205

var eventBus = new EventBus();
var count = 0;
eventBus.on('test', function () {
count++;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this line needs to be indented with one more space

@yurydelendik yurydelendik force-pushed the eventbus branch 2 times, most recently from fd0eaf7 to ecb023d Compare April 26, 2016 18:31
renderingQueue: pdfRenderingQueue,
linkService: pdfLinkService,
downloadManager: downloadManager
});
}, eventBus);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PDFViewer takes only one parameter options and you're already passing the event bus in the options object, so this change does not appear to be required.

}(this, function (exports, uiUtils) {
var EventBus = uiUtils.EventBus;

// Attaching to the application event bus to displach events to the DOM for
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I think you mean "dispatch events" here

@@ -384,6 +384,46 @@ function getPDFFileNameFromURL(url) {
return suggestedFilename || 'document.pdf';
}

/**
* Simple event bus for an application. The listener are attached using the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: listener_s_ are attached

@Snuffleupagus
Copy link
Collaborator

It seems that an eventBus option isn't passed to PDFLinkService, meaning the pagemode/namedaction events won't work.

window.addEventListener('presentationmodechanged', function(evt) {
if (!evt.detail.active && !evt.detail.switchInProgress &&
self.eventBus.on('presentationmodechanged', function(e) {
if (!e.active && !e.switchInProgress &&
self.isThumbnailViewVisible) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I think that this condition will now fit on one line.

@yurydelendik
Copy link
Contributor Author

It seems that an eventBus option isn't passed to PDFLinkService,

Fixed

@timvandermeij
Copy link
Contributor

/botio-linux preview

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

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

Live output at: http://107.21.233.14:8877/14c13b0714ced29/output.txt

@timvandermeij
Copy link
Contributor

/botio unittest

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

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

Live output at: http://107.22.172.223:8877/90540c83462160f/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

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

Live output at: http://107.21.233.14:8877/80648a52743af1e/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/80648a52743af1e/output.txt

Total script time: 1.52 mins

  • Unit Tests: Passed

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://107.22.172.223:8877/90540c83462160f/output.txt

Total script time: 1.82 mins

  • Unit Tests: Passed

eventBus.dispatch('test');
expect(count).toEqual(2);
});
it('dispatch event multiple handlers', function () {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: 'dispatch event to multiple handlers'.


eventBus.on('resize', webViewerResize);
eventBus.on('localized', webViewerLocalized);
eventBus.on('fileinputchange', webViewerFileInputChange);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function that is referenced here is placed within a GENERIC preprocessor tag, shouldn't this line be too, in order to prevent any possible issues?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Fixed.

PDFViewerApplication.findBar.dispatchEvent('again',
cmd === 5 || cmd === 12);
PDFViewerApplication.eventBus.dispatch('findagain',
cmd === 5 || cmd === 12);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look right, and it stops Ctrl+G from working in the preview.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Fixed.

@Snuffleupagus
Copy link
Collaborator

/botio-windows preview

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

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

Live output at: http://107.22.172.223:8877/f738ff8efdbdcd2/output.txt

@Snuffleupagus
Copy link
Collaborator

/botio unittest

@pdfjsbot
Copy link

From: Bot.io (Windows)


Received

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

Live output at: http://107.22.172.223:8877/79bc67cfaae176e/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux)


Received

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

Live output at: http://107.21.233.14:8877/c6991f8c2f789b2/output.txt

@pdfjsbot
Copy link

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/c6991f8c2f789b2/output.txt

Total script time: 1.54 mins

  • Unit Tests: Passed

@pdfjsbot
Copy link

From: Bot.io (Windows)


Success

Full output at http://107.22.172.223:8877/79bc67cfaae176e/output.txt

Total script time: 1.75 mins

  • Unit Tests: Passed

@Snuffleupagus Snuffleupagus merged commit 61a4c74 into mozilla:master Apr 28, 2016
@Snuffleupagus
Copy link
Collaborator

This looks great, thank you for the patch!

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.

4 participants