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 { HTMLMetadata } from './html-metadata';
......@@ -28,13 +30,15 @@ const MIN_HTML_WIDTH = 480;
*
* @implements {Integration}
*/
export class HTMLIntegration {
export class HTMLIntegration extends TinyEmitter {
/**
* @param {object} options
* @param {FeatureFlags} options.features
* @param {HTMLElement} [options.container]
*/
constructor({ features, container = document.body }) {
super();
this.features = features;
this.container = container;
this.anchor = anchor;
......
import debounce from 'lodash.debounce';
import { render } from 'preact';
import { TinyEmitter } from 'tiny-emitter';
import { ListenerCollection } from '../../shared/listener-collection';
import {
......@@ -62,7 +63,7 @@ export function isPDF() {
* Integration that works with PDF.js
* @implements {Integration}
*/
export class PDFIntegration {
export class PDFIntegration extends TinyEmitter {
/**
* @param {Annotator} annotator
* @param {object} options
......@@ -72,6 +73,8 @@ export class PDFIntegration {
* re-anchoring to complete when scrolling to an un-rendered page.
*/
constructor(annotator, options = {}) {
super();
this.annotator = annotator;
const window_ = /** @type {HypothesisWindow} */ (window);
......
import { TinyEmitter } from 'tiny-emitter';
import { ListenerCollection } from '../../shared/listener-collection';
import { FeatureFlags } from '../features';
import { onDocumentReady } from '../frame-observer';
......@@ -202,11 +204,13 @@ function makeContentFrameScrollable(frame) {
*
* @implements {Integration}
*/
export class VitalSourceContentIntegration {
export class VitalSourceContentIntegration extends TinyEmitter {
/**
* @param {HTMLElement} container
*/
constructor(container = document.body) {
super();
const features = new FeatureFlags();
// Forcibly enable the side-by-side feature for VS books. This feature is
......
......@@ -140,7 +140,7 @@
* This will only be called if the anchor has at least one highlight (ie.
* `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