Commit eca91b43 authored by Robert Knight's avatar Robert Knight

Convert src/sidebar/services to ES modules

Use the convert-to-es-modules script from the frontend-toolkit repo to
convert services to ES modules.
parent 248458e4
......@@ -70,7 +70,7 @@ function clientType(win, settings = {}) {
* application.
*/
// @ngInject
function analytics($window, settings) {
export default function analytics($window, settings) {
const category = clientType($window, settings);
const noop = () => {};
......@@ -119,5 +119,3 @@ function analytics($window, settings) {
}
analytics.events = events;
module.exports = analytics;
const angular = require('angular');
import angular from 'angular';
const events = require('../events');
import events from '../events';
function getExistingAnnotation(store, id) {
return store.getState().annotations.annotations.find(function(annot) {
......@@ -10,7 +10,7 @@ function getExistingAnnotation(store, id) {
// Wraps the annotation store to trigger events for the CRUD actions
// @ngInject
function annotationMapper($rootScope, store, api) {
export default function annotationMapper($rootScope, store, api) {
function loadAnnotations(annotations, replies) {
annotations = annotations.concat(replies || []);
......@@ -73,5 +73,3 @@ function annotationMapper($rootScope, store, api) {
flagAnnotation: flagAnnotation,
};
}
module.exports = annotationMapper;
const SearchClient = require('../search-client');
import SearchClient from '../search-client';
// @ngInject
function annotations(annotationMapper, api, store, streamer, streamFilter) {
export default function annotations(
annotationMapper,
api,
store,
streamer,
streamFilter
) {
let searchClient = null;
/**
......@@ -57,5 +63,3 @@ function annotations(annotationMapper, api, store, streamer, streamFilter) {
load,
};
}
module.exports = annotations;
const { retryPromiseOperation } = require('../util/retry');
import { retryPromiseOperation } from '../util/retry';
/**
* A service which fetches and caches API route metadata.
*/
// @ngInject
function apiRoutes(settings) {
export default function apiRoutes(settings) {
// Cache of route name => route metadata from API root.
let routeCache;
// Cache of links to pages on the service fetched from the API's "links"
......@@ -57,5 +57,3 @@ function apiRoutes(settings) {
return { routes, links };
}
module.exports = apiRoutes;
const get = require('lodash.get');
const queryString = require('query-string');
import get from 'lodash.get';
import * as queryString from 'query-string';
const { replaceURLParams } = require('../util/url');
import { replaceURLParams } from '../util/url';
/**
* Translate the response from a failed API call into an Error-like object.
......@@ -189,7 +189,7 @@ function createAPICall(
* not use authentication.
*/
// @ngInject
function api(apiRoutes, auth, store) {
export default function api(apiRoutes, auth, store) {
const links = apiRoutes.routes();
let clientId = null;
......@@ -247,5 +247,3 @@ function api(apiRoutes, auth, store) {
// from the `apiRoutes` service.
};
}
module.exports = api;
......@@ -9,12 +9,13 @@
* change at any time and should write code accordingly. Feature flags should
* not be cached, and should not be interrogated only at setup time.
*/
const events = require('../events');
const bridgeEvents = require('../../shared/bridge-events');
const warnOnce = require('../../shared/warn-once');
import bridgeEvents from '../../shared/bridge-events';
import warnOnce from '../../shared/warn-once';
import events from '../events';
// @ngInject
function features($rootScope, bridge, session) {
export default function features($rootScope, bridge, session) {
const _sendFeatureFlags = function() {
const userFeatures = session.state.features;
bridge.call(bridgeEvents.FEATURE_FLAGS_UPDATED, userFeatures || {});
......@@ -59,5 +60,3 @@ function features($rootScope, bridge, session) {
flagEnabled: flagEnabled,
};
}
module.exports = features;
......@@ -3,7 +3,7 @@
*/
// @ngInject
function flash(toastr) {
export default function flash(toastr) {
return {
info: toastr.info.bind(toastr),
success: toastr.success.bind(toastr),
......@@ -11,5 +11,3 @@ function flash(toastr) {
error: toastr.error.bind(toastr),
};
}
module.exports = flash;
const debounce = require('lodash.debounce');
import debounce from 'lodash.debounce';
const events = require('../events');
const bridgeEvents = require('../../shared/bridge-events');
const metadata = require('../util/annotation-metadata');
const uiConstants = require('../ui-constants');
import bridgeEvents from '../../shared/bridge-events';
import events from '../events';
import uiConstants from '../ui-constants';
import * as metadata from '../util/annotation-metadata';
/**
* @typedef FrameInfo
......
......@@ -11,13 +11,13 @@ const DEFAULT_ORGANIZATION = {
encodeURIComponent(require('../../images/icons/logo.svg')),
};
const events = require('../events');
const { awaitStateChange } = require('../util/state');
const { combineGroups } = require('../util/groups');
const serviceConfig = require('../service-config');
import events from '../events';
import serviceConfig from '../service-config';
import { combineGroups } from '../util/groups';
import { awaitStateChange } from '../util/state';
// @ngInject
function groups(
export default function groups(
$rootScope,
store,
api,
......@@ -372,5 +372,3 @@ function groups(
focus: focus,
};
}
module.exports = groups;
......@@ -25,7 +25,7 @@ class InMemoryStorage {
* in third-party iframes.
*/
// @ngInject
function localStorage($window) {
export default function localStorage($window) {
let storage;
let testKey = 'hypothesis.testKey';
......@@ -63,5 +63,3 @@ function localStorage($window) {
},
};
}
module.exports = localStorage;
const events = require('../events');
const { resolve } = require('../util/url');
const serviceConfig = require('../service-config');
import events from '../events';
import serviceConfig from '../service-config';
import { resolve } from '../util/url';
/**
* @typedef RefreshOptions
......@@ -21,7 +21,7 @@ const serviceConfig = require('../service-config');
* Interaction with OAuth endpoints in the annotation service is delegated to
* the `OAuthClient` class.
*/
function auth(
export default function auth(
$rootScope,
$window,
OAuthClient,
......@@ -311,5 +311,3 @@ auth.$inject = [
'localStorage',
'settings',
];
module.exports = auth;
......@@ -23,7 +23,7 @@ const STORAGE_KEY = 'hypothesis.privacy';
* annotations to local storage.
*/
// @ngInject
function Permissions(localStorage) {
export default function Permissions(localStorage) {
const self = this;
function defaultLevel() {
......@@ -125,5 +125,3 @@ function Permissions(localStorage) {
return perms[action].indexOf(userid) !== -1;
};
}
module.exports = Permissions;
const buildThread = require('../build-thread');
const events = require('../events');
const memoize = require('../util/memoize');
const metadata = require('../util/annotation-metadata');
const tabs = require('../util/tabs');
import buildThread from '../build-thread';
import events from '../events';
import * as metadata from '../util/annotation-metadata';
import memoize from '../util/memoize';
import * as tabs from '../util/tabs';
function truthyKeys(map) {
return Object.keys(map).filter(function(k) {
......@@ -37,7 +37,12 @@ const sortFns = {
* The root thread is then displayed by viewer.html
*/
// @ngInject
function RootThread($rootScope, store, searchFilter, viewFilter) {
export default function RootThread(
$rootScope,
store,
searchFilter,
viewFilter
) {
/**
* Build the root conversation thread from the given UI state.
*
......@@ -145,5 +150,3 @@ function RootThread($rootScope, store, searchFilter, viewFilter) {
*/
this.thread = memoize(buildRootThread);
}
module.exports = RootThread;
......@@ -259,11 +259,9 @@ function generateFacetedFilter(searchtext, focusFilters = {}) {
* filter annotations displayed to the user or fetched from the API.
*/
// @ngInject
function searchFilter() {
export default function searchFilter() {
return {
toObject,
generateFacetedFilter,
};
}
module.exports = searchFilter;
const urlUtil = require('../util/url');
import * as urlUtil from '../util/url';
/**
* A function that returns an absolute URL given a link name and params, by
......@@ -31,7 +31,7 @@ const urlUtil = require('../util/url');
*
* @ngInject
*/
function serviceUrl(store, apiRoutes) {
export default function serviceUrl(store, apiRoutes) {
apiRoutes
.links()
.then(store.updateLinks)
......@@ -63,5 +63,3 @@ function serviceUrl(store, apiRoutes) {
return url.url;
};
}
module.exports = serviceUrl;
const events = require('../events');
const retryUtil = require('../util/retry');
const sentry = require('../util/sentry');
import events from '../events';
import * as retryUtil from '../util/retry';
import * as sentry from '../util/sentry';
const CACHE_TTL = 5 * 60 * 1000; // 5 minutes
......@@ -19,7 +19,7 @@ const CACHE_TTL = 5 * 60 * 1000; // 5 minutes
*
* @ngInject
*/
function session(
export default function session(
$rootScope,
analytics,
store,
......@@ -187,6 +187,4 @@ function session(
update,
};
}
module.exports = session;
} // 5 minutes
......@@ -5,7 +5,7 @@
* See https://github.com/hypothesis/h/blob/master/h/streamer/filter.py
* for the schema.
*/
class StreamFilter {
export default class StreamFilter {
constructor() {
this.resetFilter();
}
......@@ -47,5 +47,3 @@ class StreamFilter {
return this;
}
}
module.exports = StreamFilter;
const queryString = require('query-string');
const uuid = require('node-uuid');
import uuid from 'node-uuid';
import * as queryString from 'query-string';
const warnOnce = require('../../shared/warn-once');
const Socket = require('../websocket');
import warnOnce from '../../shared/warn-once';
import Socket from '../websocket';
/**
* Open a new WebSocket connection to the Hypothesis push notification service.
......@@ -19,7 +18,7 @@ const Socket = require('../websocket');
* @param settings - Application settings
*/
// @ngInject
function Streamer(
export default function Streamer(
$rootScope,
annotationMapper,
store,
......@@ -236,5 +235,3 @@ function Streamer(
this.reconnect = reconnect;
this.setConfig = setConfig;
}
module.exports = Streamer;
......@@ -13,7 +13,7 @@
* on frequency of usage.
*/
// @ngInject
function tags(localStorage) {
export default function tags(localStorage) {
const TAGS_LIST_KEY = 'hypothesis.user.tags.list';
const TAGS_MAP_KEY = 'hypothesis.user.tags.map';
......@@ -78,5 +78,3 @@ function tags(localStorage) {
store,
};
}
module.exports = tags;
const analyticsService = require('../analytics');
import analyticsService from '../analytics';
describe('analytics', function() {
let $windowStub;
......
const angular = require('angular');
const immutable = require('seamless-immutable');
import angular from 'angular';
import immutable from 'seamless-immutable';
const annotationMapperFactory = require('../annotation-mapper');
const storeFactory = require('../../store');
const events = require('../../events');
import events from '../../events';
import storeFactory from '../../store';
import annotationMapperFactory from '../annotation-mapper';
describe('annotationMapper', function() {
const sandbox = sinon.createSandbox();
......
const EventEmitter = require('tiny-emitter');
import EventEmitter from 'tiny-emitter';
const annotations = require('../annotations');
const { $imports } = require('../annotations');
import annotations from '../annotations';
import { $imports } from '../annotations';
let searchClients;
let longRunningSearchClient = false;
......
const apiRoutesFactory = require('../api-routes');
import apiRoutesFactory from '../api-routes';
// Abridged version of the response returned by https://hypothes.is/api,
// with the domain name changed.
......
const fetchMock = require('fetch-mock');
import fetchMock from 'fetch-mock';
const apiFactory = require('../api');
import apiFactory from '../api';
// API route directory.
//
......
const features = require('../features');
const { $imports } = require('../features');
const events = require('../../events');
const bridgeEvents = require('../../../shared/bridge-events');
import bridgeEvents from '../../../shared/bridge-events';
import events from '../../events';
import features from '../features';
import { $imports } from '../features';
describe('h:features - sidebar layer', function() {
let fakeBridge;
......
const flash = require('../flash');
import flash from '../flash';
describe('sidebar.flash', () => {
['info', 'success', 'warning', 'error'].forEach(method => {
......
const angular = require('angular');
const EventEmitter = require('tiny-emitter');
const annotationFixtures = require('../../test/annotation-fixtures');
const events = require('../../events');
const createFakeStore = require('../../test/fake-redux-store');
const { default: FrameSync, formatAnnot } = require('../frame-sync');
const uiConstants = require('../../ui-constants');
import angular from 'angular';
import EventEmitter from 'tiny-emitter';
import events from '../../events';
import * as annotationFixtures from '../../test/annotation-fixtures';
import createFakeStore from '../../test/fake-redux-store';
import uiConstants from '../../ui-constants';
import FrameSync, { formatAnnot } from '../frame-sync';
const fixtures = {
ann: Object.assign({ $tag: 't1' }, annotationFixtures.defaultAnnotation()),
......
const events = require('../../events');
const fakeReduxStore = require('../../test/fake-redux-store');
const groups = require('../groups');
import events from '../../events';
import fakeReduxStore from '../../test/fake-redux-store';
import groups from '../groups';
/**
* Generate a truth table containing every possible combination of a set of
......
const angular = require('angular');
const service = require('../local-storage');
import angular from 'angular';
import service from '../local-storage';
function windowWithLocalStoragePropertyThatThrows() {
const win = {};
......
const angular = require('angular');
import angular from 'angular';
const authFactory = require('../oauth-auth');
const events = require('../../events');
const FakeWindow = require('../../util/test/fake-window');
import events from '../../events';
import FakeWindow from '../../util/test/fake-window';
import authFactory from '../oauth-auth';
const DEFAULT_TOKEN_EXPIRES_IN_SECS = 1000;
const TOKEN_KEY = 'hypothesis.oauth.hypothes%2Eis.token';
......
const Permissions = require('../permissions');
import Permissions from '../permissions';
const userid = 'acct:flash@gord.on';
......
const angular = require('angular');
const immutable = require('seamless-immutable');
const annotationFixtures = require('../../test/annotation-fixtures');
const events = require('../../events');
const uiConstants = require('../../ui-constants');
const rootThreadFactory = require('../root-thread');
const { $imports } = require('../root-thread');
import angular from 'angular';
import immutable from 'seamless-immutable';
import events from '../../events';
import * as annotationFixtures from '../../test/annotation-fixtures';
import uiConstants from '../../ui-constants';
import rootThreadFactory from '../root-thread';
import { $imports } from '../root-thread';
const fixtures = immutable({
emptyThread: {
......
const searchFilterFactory = require('../search-filter');
import searchFilterFactory from '../search-filter';
const searchFilter = searchFilterFactory();
......
const serviceUrlFactory = require('../service-url');
const { $imports } = require('../service-url');
import serviceUrlFactory from '../service-url';
import { $imports } from '../service-url';
/** Return a fake store object. */
function fakeStore() {
......
const angular = require('angular');
import angular from 'angular';
const events = require('../../events');
const { events: analyticsEvents } = require('../analytics');
const sessionFactory = require('../session');
const { $imports } = require('../session');
import events from '../../events';
import { events as analyticsEvents } from '../analytics';
import sessionFactory from '../session';
import { $imports } from '../session';
const mock = angular.mock;
......
const StreamFilter = require('../stream-filter');
import StreamFilter from '../stream-filter';
describe('sidebar/services/stream-filter', () => {
describe('#addClause', () => {
......
const EventEmitter = require('tiny-emitter');
import EventEmitter from 'tiny-emitter';
const Streamer = require('../streamer');
const { $imports } = require('../streamer');
import Streamer from '../streamer';
import { $imports } from '../streamer';
const fixtures = {
createNotification: {
......
const angular = require('angular');
import angular from 'angular';
const tagsFactory = require('../tags');
import tagsFactory from '../tags';
const TAGS_LIST_KEY = 'hypothesis.user.tags.list';
const TAGS_MAP_KEY = 'hypothesis.user.tags.map';
......
const unicodeFactory = require('../unicode');
import unicodeFactory from '../unicode';
const unicode = unicodeFactory();
......
const ViewFilter = require('../view-filter');
import ViewFilter from '../view-filter';
function isoDateWithAge(age) {
return new Date(Date.now() - age * 1000).toISOString();
......
......@@ -10,11 +10,9 @@
const COMBINING_MARKS = /[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08E4-\u08FE\u0900-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C01-\u0C03\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C82\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D02\u0D03\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u18A9\u1920-\u192B\u1930-\u193B\u19B0-\u19C0\u19C8\u19C9\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1DC0-\u1DE6\u1DFC-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C4\uA8E0-\uA8F1\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE26]/g;
// @ngInject
function unicode() {
export default function unicode() {
return {
normalize: str => str.normalize('NFKD'),
fold: str => str.replace(COMBINING_MARKS, ''),
};
}
module.exports = unicode;
const { quote } = require('../util/annotation-metadata');
import { quote } from '../util/annotation-metadata';
// Prevent Babel inserting helper code after `@ngInject` comment below which
// breaks browserify-ngannotate.
......@@ -20,7 +20,7 @@ function displayName(ann) {
* which do not match the filter are then hidden.
*/
// @ngInject
function viewFilter(unicode) {
export default function viewFilter(unicode) {
/**
* Normalize a field value or query term for comparison.
*/
......@@ -176,5 +176,3 @@ function viewFilter(unicode) {
.map(ann => ann.id);
};
}
module.exports = viewFilter;
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