Skip to content

Commit

Permalink
Move listener-collection.js to src/shared
Browse files Browse the repository at this point in the history
`src/shared/port-rpc.js` depended on
`src/annotation/util/listener-collection.js`. Files in the `src/shared`
folder should not have dependencies on `src/annotation`.

`ListenerCollection` is a very general utility and the placement in
`src/shared` seems correct.

I took the opportunity to reorder the imports according to our
conventions.
  • Loading branch information
esanzgar committed Sep 3, 2021
1 parent 8384de2 commit c91cbf0
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 20 deletions.
5 changes: 3 additions & 2 deletions src/annotator/bucket-bar.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { render } from 'preact';
import Buckets from './components/Buckets';

import { ListenerCollection } from '../shared/listener-collection';

import Buckets from './components/Buckets';
import { anchorBuckets } from './util/buckets';
import { ListenerCollection } from './util/listener-collection';

/**
* @typedef BucketBarOptions
Expand Down
10 changes: 5 additions & 5 deletions src/annotator/guest.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Adder } from './adder';
import { CrossFrame } from './cross-frame';
import { HTMLIntegration } from './integrations/html';
import { PDFIntegration } from './integrations/pdf';
import { ListenerCollection } from '../shared/listener-collection';

import { Adder } from './adder';
import { TextRange } from './anchoring/text-range';
import { CrossFrame } from './cross-frame';
import {
getHighlightsContainingNode,
highlightRange,
Expand All @@ -12,10 +11,11 @@ import {
setHighlightsFocused,
setHighlightsVisible,
} from './highlighter';
import { HTMLIntegration } from './integrations/html';
import { PDFIntegration } from './integrations/pdf';
import * as rangeUtil from './range-util';
import { SelectionObserver } from './selection-observer';
import { normalizeURI } from './util/url';
import { ListenerCollection } from './util/listener-collection';

/**
* @typedef {import('./util/emitter').EventBus} EventBus
Expand Down
2 changes: 1 addition & 1 deletion src/annotator/integrations/pdf.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import debounce from 'lodash.debounce';
import { render } from 'preact';

import { ListenerCollection } from '../../shared/listener-collection';
import {
RenderingStates,
anchor,
Expand All @@ -10,7 +11,6 @@ import {
import { isInPlaceholder, removePlaceholder } from '../anchoring/placeholder';
import WarningBanner from '../components/WarningBanner';
import { createShadowRoot } from '../util/shadow-root';
import { ListenerCollection } from '../util/listener-collection';
import { offsetRelativeTo, scrollElement } from '../util/scroll';

import { PDFMetadata } from './pdf-metadata';
Expand Down
2 changes: 1 addition & 1 deletion src/annotator/selection-observer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ListenerCollection } from './util/listener-collection';
import { ListenerCollection } from '../shared/listener-collection';

/**
* Return the current selection or `null` if there is no selection or it is empty.
Expand Down
10 changes: 5 additions & 5 deletions src/annotator/sidebar.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import Hammer from 'hammerjs';

import events from '../shared/bridge-events';
import { ListenerCollection } from '../shared/listener-collection';

import annotationCounts from './annotation-counts';
import sidebarTrigger from './sidebar-trigger';
import BucketBar from './bucket-bar';
import { createSidebarConfig } from './config/sidebar';
import events from '../shared/bridge-events';
import features from './features';

import sidebarTrigger from './sidebar-trigger';
import { ToolbarController } from './toolbar';
import { createShadowRoot } from './util/shadow-root';
import BucketBar from './bucket-bar';
import { ListenerCollection } from './util/listener-collection';

/**
* @typedef {import('./guest').default} Guest
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/shared/port-rpc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ListenerCollection } from '../annotator/util/listener-collection';
import { ListenerCollection } from './listener-collection';

/*
This module was adapted from `index.js` in https://github.com/substack/frame-rpc.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ListenerCollection } from '../../util/listener-collection';
import { ListenerCollection } from '../listener-collection';

describe('ListenerCollection', () => {
let listeners;
Expand Down
6 changes: 3 additions & 3 deletions src/sidebar/components/ThreadList.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { useEffect, useLayoutEffect, useMemo, useState } from 'preact/hooks';
import debounce from 'lodash.debounce';

import { useStoreProxy } from '../store/use-store';
import { ListenerCollection } from '../../shared/listener-collection';
import { isHighlight } from '../helpers/annotation-metadata';
import { getElementHeightWithMargins } from '../util/dom';
import {
calculateVisibleThreads,
THREAD_DIMENSION_DEFAULTS,
} from '../helpers/visible-threads';
import { useStoreProxy } from '../store/use-store';
import { getElementHeightWithMargins } from '../util/dom';

import ThreadCard from './ThreadCard';
import { ListenerCollection } from '../../annotator/util/listener-collection';

/** @typedef {import('../helpers/build-thread').Thread} Thread */

Expand Down
2 changes: 1 addition & 1 deletion src/sidebar/util/observe-element-size.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ListenerCollection } from '../../annotator/util/listener-collection';
import { ListenerCollection } from '../../shared/listener-collection';

/**
* Watch for changes in the size (`clientWidth` and `clientHeight`) of
Expand Down

0 comments on commit c91cbf0

Please sign in to comment.