From 7fd5f2dd61a4ae906fcc09b2371fbbb5484af1e6 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 27 Feb 2020 15:02:03 +0100 Subject: [PATCH] [api-minor] Remove the `getGlobalEventBus` viewer functionality (PR 11631 follow-up) The correct/intended way of working with the "viewer components" is by providing an `EventBus` instance upon initialization, and the `getGlobalEventBus` was only added for backwards compatibility. Note, for example, that using `getGlobalEventBus` doesn't really work at all well with a use-case where there's *multiple* `PDFViewer` instances on a one page, since it may then be difficult/impossible to tell which viewer a particular event originated from. All of the "viewer components" examples have been previously updated, such that there's no longer any code/examples which relies on the now removed `getGlobalEventBus` functionality. --- web/base_viewer.js | 3 +-- web/pdf_find_bar.js | 4 ++-- web/pdf_find_controller.js | 4 ++-- web/pdf_history.js | 3 +-- web/pdf_link_service.js | 4 ++-- web/pdf_page_view.js | 3 +-- web/text_layer_builder.js | 3 +-- web/ui_utils.js | 12 ------------ 8 files changed, 10 insertions(+), 26 deletions(-) diff --git a/web/base_viewer.js b/web/base_viewer.js index f57cafe66..09257ac5a 100644 --- a/web/base_viewer.js +++ b/web/base_viewer.js @@ -17,7 +17,6 @@ import { CSS_UNITS, DEFAULT_SCALE, DEFAULT_SCALE_VALUE, - getGlobalEventBus, getVisibleElements, isPortraitOrientation, isValidRotation, @@ -145,7 +144,7 @@ class BaseViewer { this.container = options.container; this.viewer = options.viewer || options.container.firstElementChild; - this.eventBus = options.eventBus || getGlobalEventBus(); + this.eventBus = options.eventBus; this.linkService = options.linkService || new SimpleLinkService(); this.downloadManager = options.downloadManager || null; this.findController = options.findController || null; diff --git a/web/pdf_find_bar.js b/web/pdf_find_bar.js index 2a42d8573..c444c2541 100644 --- a/web/pdf_find_bar.js +++ b/web/pdf_find_bar.js @@ -13,8 +13,8 @@ * limitations under the License. */ -import { getGlobalEventBus, NullL10n } from "./ui_utils.js"; import { FindState } from "./pdf_find_controller.js"; +import { NullL10n } from "./ui_utils.js"; const MATCHES_COUNT_LIMIT = 1000; @@ -38,7 +38,7 @@ class PDFFindBar { this.findResultsCount = options.findResultsCount || null; this.findPreviousButton = options.findPreviousButton || null; this.findNextButton = options.findNextButton || null; - this.eventBus = eventBus || getGlobalEventBus(); + this.eventBus = eventBus; this.l10n = l10n; // Add event listeners to the DOM elements. diff --git a/web/pdf_find_controller.js b/web/pdf_find_controller.js index 1bc3a203b..2068de152 100644 --- a/web/pdf_find_controller.js +++ b/web/pdf_find_controller.js @@ -13,9 +13,9 @@ * limitations under the License. */ -import { getGlobalEventBus, scrollIntoView } from "./ui_utils.js"; import { createPromiseCapability } from "pdfjs-lib"; import { getCharacterType } from "./pdf_find_utils.js"; +import { scrollIntoView } from "./ui_utils.js"; const FindState = { FOUND: 0, @@ -69,7 +69,7 @@ class PDFFindController { */ constructor({ linkService, eventBus }) { this._linkService = linkService; - this._eventBus = eventBus || getGlobalEventBus(); + this._eventBus = eventBus; this._reset(); eventBus._on("findbarclose", this._onFindBarClose.bind(this)); diff --git a/web/pdf_history.js b/web/pdf_history.js index 4e8127b15..96f240bfc 100644 --- a/web/pdf_history.js +++ b/web/pdf_history.js @@ -14,7 +14,6 @@ */ import { - getGlobalEventBus, isValidRotation, parseQueryString, waitOnEventOrTimeout, @@ -59,7 +58,7 @@ class PDFHistory { */ constructor({ linkService, eventBus }) { this.linkService = linkService; - this.eventBus = eventBus || getGlobalEventBus(); + this.eventBus = eventBus; this._initialized = false; this._fingerprint = ""; diff --git a/web/pdf_link_service.js b/web/pdf_link_service.js index dc8d95732..97e0eb53e 100644 --- a/web/pdf_link_service.js +++ b/web/pdf_link_service.js @@ -13,7 +13,7 @@ * limitations under the License. */ -import { getGlobalEventBus, parseQueryString } from "./ui_utils.js"; +import { parseQueryString } from "./ui_utils.js"; /** * @typedef {Object} PDFLinkServiceOptions @@ -44,7 +44,7 @@ class PDFLinkService { externalLinkEnabled = true, ignoreDestinationZoom = false, } = {}) { - this.eventBus = eventBus || getGlobalEventBus(); + this.eventBus = eventBus; this.externalLinkTarget = externalLinkTarget; this.externalLinkRel = externalLinkRel; this.externalLinkEnabled = externalLinkEnabled; diff --git a/web/pdf_page_view.js b/web/pdf_page_view.js index f0fb4528c..710e316cc 100644 --- a/web/pdf_page_view.js +++ b/web/pdf_page_view.js @@ -17,7 +17,6 @@ import { approximateFraction, CSS_UNITS, DEFAULT_SCALE, - getGlobalEventBus, getOutputScale, NullL10n, RendererType, @@ -92,7 +91,7 @@ class PDFPageView { this.useOnlyCssZoom = options.useOnlyCssZoom || false; this.maxCanvasPixels = options.maxCanvasPixels || MAX_CANVAS_PIXELS; - this.eventBus = options.eventBus || getGlobalEventBus(); + this.eventBus = options.eventBus; this.renderingQueue = options.renderingQueue; this.textLayerFactory = options.textLayerFactory; this.annotationLayerFactory = options.annotationLayerFactory; diff --git a/web/text_layer_builder.js b/web/text_layer_builder.js index 6c3be2f54..715135da0 100644 --- a/web/text_layer_builder.js +++ b/web/text_layer_builder.js @@ -13,7 +13,6 @@ * limitations under the License. */ -import { getGlobalEventBus } from "./ui_utils.js"; import { renderTextLayer } from "pdfjs-lib"; const EXPAND_DIVS_TIMEOUT = 300; // ms @@ -45,7 +44,7 @@ class TextLayerBuilder { enhanceTextSelection = false, }) { this.textLayerDiv = textLayerDiv; - this.eventBus = eventBus || getGlobalEventBus(); + this.eventBus = eventBus; this.textContent = null; this.textContentItemsStr = []; this.textContentStream = null; diff --git a/web/ui_utils.js b/web/ui_utils.js index 1ef9c45ef..1841860dd 100644 --- a/web/ui_utils.js +++ b/web/ui_utils.js @@ -884,17 +884,6 @@ class EventBus { } } -let globalEventBus = null; -function getGlobalEventBus(dispatchToDOM = false) { - console.error( - "getGlobalEventBus is deprecated, use a manually created EventBus instance instead." - ); - if (!globalEventBus) { - globalEventBus = new EventBus({ dispatchToDOM }); - } - return globalEventBus; -} - function clamp(v, min, max) { return Math.min(Math.max(v, min), max); } @@ -1013,7 +1002,6 @@ export { SpreadMode, NullL10n, EventBus, - getGlobalEventBus, clamp, ProgressBar, getPDFFileNameFromURL,