Attempt to simplify the signature of the PDFSidebar constructor, by moving the eventBus parameter from the options object and removing the PDFOutlineViewer dependency

This is similar to the format used by a number of other viewer components, and should simplify the `PDFSidebar` initialization slightly.
Furthermore, by using the `eventBus` it's no longer necessary for `PDFSidebar` to have a direct dependency on `PDFOutlineViewer`.

There's still room for improvement here, but this patch is at least a start (since it's not clear to me how best to handle the viewers).
This commit is contained in:
Jonas Jenwald 2018-10-02 13:08:24 +02:00
parent 3f3ddaf541
commit 8eda8c27f8
3 changed files with 7 additions and 9 deletions

View File

@ -396,9 +396,7 @@ let PDFViewerApplication = {
let sidebarConfig = Object.create(appConfig.sidebar);
sidebarConfig.pdfViewer = this.pdfViewer;
sidebarConfig.pdfThumbnailViewer = this.pdfThumbnailViewer;
sidebarConfig.pdfOutlineViewer = this.pdfOutlineViewer;
sidebarConfig.eventBus = eventBus;
this.pdfSidebar = new PDFSidebar(sidebarConfig, this.l10n);
this.pdfSidebar = new PDFSidebar(sidebarConfig, eventBus, this.l10n);
this.pdfSidebar.onToggled = this.forceRendering.bind(this);
this.pdfSidebarResizer = new PDFSidebarResizer(appConfig.sidebarResizer,

View File

@ -39,6 +39,8 @@ class PDFOutlineViewer {
this.eventBus = eventBus;
this.reset();
eventBus.on('toggleoutlinetree', this.toggleOutlineTree.bind(this));
}
reset() {

View File

@ -29,12 +29,10 @@ const SidebarView = {
* @typedef {Object} PDFSidebarOptions
* @property {PDFViewer} pdfViewer - The document viewer.
* @property {PDFThumbnailViewer} pdfThumbnailViewer - The thumbnail viewer.
* @property {PDFOutlineViewer} pdfOutlineViewer - The outline viewer.
* @property {HTMLDivElement} outerContainer - The outer container
* (encasing both the viewer and sidebar elements).
* @property {HTMLDivElement} viewerContainer - The viewer container
* (in which the viewer element is placed).
* @property {EventBus} eventBus - The application event bus.
* @property {HTMLButtonElement} toggleButton - The button used for
* opening/closing the sidebar.
* @property {HTMLButtonElement} thumbnailButton - The button used to show
@ -56,9 +54,10 @@ const SidebarView = {
class PDFSidebar {
/**
* @param {PDFSidebarOptions} options
* @param {EventBus} eventBus - The application event bus.
* @param {IL10n} l10n - Localization service.
*/
constructor(options, l10n = NullL10n) {
constructor(options, eventBus, l10n = NullL10n) {
this.isOpen = false;
this.active = SidebarView.THUMBS;
this.isInitialViewSet = false;
@ -71,11 +70,9 @@ class PDFSidebar {
this.pdfViewer = options.pdfViewer;
this.pdfThumbnailViewer = options.pdfThumbnailViewer;
this.pdfOutlineViewer = options.pdfOutlineViewer;
this.outerContainer = options.outerContainer;
this.viewerContainer = options.viewerContainer;
this.eventBus = options.eventBus;
this.toggleButton = options.toggleButton;
this.thumbnailButton = options.thumbnailButton;
@ -88,6 +85,7 @@ class PDFSidebar {
this.disableNotification = options.disableNotification || false;
this.eventBus = eventBus;
this.l10n = l10n;
this._addEventListeners();
@ -397,7 +395,7 @@ class PDFSidebar {
this.switchView(SidebarView.OUTLINE);
});
this.outlineButton.addEventListener('dblclick', () => {
this.pdfOutlineViewer.toggleOutlineTree();
this.eventBus.dispatch('toggleoutlinetree', { source: this, });
});
this.attachmentsButton.addEventListener('click', () => {