Commit c5bfe0c9 authored by Robert Knight's avatar Robert Knight

Turn integrations into event emitters

This will allow integrations to report events such as a change in the
loaded document or metadata.
parent 28a96914
import { TinyEmitter } from 'tiny-emitter';
import { anchor, describe } from '../anchoring/html'; import { anchor, describe } from '../anchoring/html';
import { HTMLMetadata } from './html-metadata'; import { HTMLMetadata } from './html-metadata';
...@@ -28,13 +30,15 @@ const MIN_HTML_WIDTH = 480; ...@@ -28,13 +30,15 @@ const MIN_HTML_WIDTH = 480;
* *
* @implements {Integration} * @implements {Integration}
*/ */
export class HTMLIntegration { export class HTMLIntegration extends TinyEmitter {
/** /**
* @param {object} options * @param {object} options
* @param {FeatureFlags} options.features * @param {FeatureFlags} options.features
* @param {HTMLElement} [options.container] * @param {HTMLElement} [options.container]
*/ */
constructor({ features, container = document.body }) { constructor({ features, container = document.body }) {
super();
this.features = features; this.features = features;
this.container = container; this.container = container;
this.anchor = anchor; this.anchor = anchor;
......
import debounce from 'lodash.debounce'; import debounce from 'lodash.debounce';
import { render } from 'preact'; import { render } from 'preact';
import { TinyEmitter } from 'tiny-emitter';
import { ListenerCollection } from '../../shared/listener-collection'; import { ListenerCollection } from '../../shared/listener-collection';
import { import {
...@@ -62,7 +63,7 @@ export function isPDF() { ...@@ -62,7 +63,7 @@ export function isPDF() {
* Integration that works with PDF.js * Integration that works with PDF.js
* @implements {Integration} * @implements {Integration}
*/ */
export class PDFIntegration { export class PDFIntegration extends TinyEmitter {
/** /**
* @param {Annotator} annotator * @param {Annotator} annotator
* @param {object} options * @param {object} options
...@@ -72,6 +73,8 @@ export class PDFIntegration { ...@@ -72,6 +73,8 @@ export class PDFIntegration {
* re-anchoring to complete when scrolling to an un-rendered page. * re-anchoring to complete when scrolling to an un-rendered page.
*/ */
constructor(annotator, options = {}) { constructor(annotator, options = {}) {
super();
this.annotator = annotator; this.annotator = annotator;
const window_ = /** @type {HypothesisWindow} */ (window); const window_ = /** @type {HypothesisWindow} */ (window);
......
import { TinyEmitter } from 'tiny-emitter';
import { ListenerCollection } from '../../shared/listener-collection'; import { ListenerCollection } from '../../shared/listener-collection';
import { FeatureFlags } from '../features'; import { FeatureFlags } from '../features';
import { onDocumentReady } from '../frame-observer'; import { onDocumentReady } from '../frame-observer';
...@@ -202,11 +204,13 @@ function makeContentFrameScrollable(frame) { ...@@ -202,11 +204,13 @@ function makeContentFrameScrollable(frame) {
* *
* @implements {Integration} * @implements {Integration}
*/ */
export class VitalSourceContentIntegration { export class VitalSourceContentIntegration extends TinyEmitter {
/** /**
* @param {HTMLElement} container * @param {HTMLElement} container
*/ */
constructor(container = document.body) { constructor(container = document.body) {
super();
const features = new FeatureFlags(); const features = new FeatureFlags();
// Forcibly enable the side-by-side feature for VS books. This feature is // Forcibly enable the side-by-side feature for VS books. This feature is
......
...@@ -140,7 +140,7 @@ ...@@ -140,7 +140,7 @@
* This will only be called if the anchor has at least one highlight (ie. * This will only be called if the anchor has at least one highlight (ie.
* `anchor.highlights` is a non-empty array) * `anchor.highlights` is a non-empty array)
* *
* @typedef {Destroyable & IntegrationBase} Integration * @typedef {Destroyable & TinyEmitter & IntegrationBase} Integration
*/ */
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment