[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.
This commit is contained in:
parent
c12ea21c14
commit
7fd5f2dd61
@ -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;
|
||||
|
@ -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.
|
||||
|
@ -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));
|
||||
|
@ -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 = "";
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user