Commit 3675cea5 authored by Eduardo Sanz García's avatar Eduardo Sanz García Committed by Eduardo

Added/improved types

I added more specific types to services, that was otherwise listed as
`Object`.
parent 0eba1843
...@@ -10,7 +10,7 @@ import SidebarContentError from './SidebarContentError'; ...@@ -10,7 +10,7 @@ import SidebarContentError from './SidebarContentError';
/** /**
* @typedef AnnotationViewProps * @typedef AnnotationViewProps
* @prop {() => any} onLogin * @prop {() => any} onLogin
* @prop {Object} [loadAnnotationsService] - Injected service * @prop {ReturnType<import('../services/load-annotations').default>} loadAnnotationsService - Injected service
*/ */
/** /**
......
...@@ -15,8 +15,8 @@ import PaginatedThreadList from './PaginatedThreadList'; ...@@ -15,8 +15,8 @@ import PaginatedThreadList from './PaginatedThreadList';
/** /**
* @typedef NotebookViewProps * @typedef NotebookViewProps
* @prop {Object} [loadAnnotationsService] - Injected service * @prop {ReturnType<import('../services/load-annotations').default>} loadAnnotationsService - Injected service
* @prop {Object} [streamer] - Injected service * @prop {import('../services/streamer').default} streamer - Injected service
*/ */
/** /**
...@@ -69,7 +69,7 @@ function NotebookView({ loadAnnotationsService, streamer }) { ...@@ -69,7 +69,7 @@ function NotebookView({ loadAnnotationsService, streamer }) {
// Establish websocket connection // Establish websocket connection
useEffect(() => { useEffect(() => {
if (streamer && hasFetchedProfile) { if (hasFetchedProfile) {
streamer.connect({ applyUpdatesImmediately: false }); streamer.connect({ applyUpdatesImmediately: false });
} }
}, [hasFetchedProfile, streamer]); }, [hasFetchedProfile, streamer]);
......
...@@ -16,9 +16,9 @@ import ThreadList from './ThreadList'; ...@@ -16,9 +16,9 @@ import ThreadList from './ThreadList';
* @typedef SidebarViewProps * @typedef SidebarViewProps
* @prop {() => any} onLogin * @prop {() => any} onLogin
* @prop {() => any} onSignUp * @prop {() => any} onSignUp
* @prop {Object} [frameSync] - Injected service * @prop {import('../services/frame-sync').default} frameSync - Injected service
* @prop {Object} [loadAnnotationsService] - Injected service * @prop {ReturnType<import('../services/load-annotations').default>} loadAnnotationsService - Injected service
* @prop {Object} [streamer] - Injected service * @prop {import('../services/streamer').default} streamer - Injected service
*/ */
/** /**
......
...@@ -9,8 +9,8 @@ import ThreadList from './ThreadList'; ...@@ -9,8 +9,8 @@ import ThreadList from './ThreadList';
/** /**
* @typedef StreamViewProps * @typedef StreamViewProps
* @prop {Object} [api] - Injected service * @prop {ReturnType<import('../services/api').default>} api - Injected service
* @prop {Object} [toastMessenger] - Injected service * @prop {ReturnType<import('../services/toast-messenger').default>} toastMessenger - Injected service
*/ */
/** /**
......
...@@ -56,9 +56,9 @@ function stripInternalProperties(obj) { ...@@ -56,9 +56,9 @@ function stripInternalProperties(obj) {
* Function which makes an API request. * Function which makes an API request.
* *
* @callback APICallFunction * @callback APICallFunction
* @param {any} [params] - A map of URL and query string parameters to include with the request. * @param {Record<string, any>} params - A map of URL and query string parameters to include with the request.
* @param {any} [data] - The body of the request. * @param {Object} [data] - The body of the request.
* @param {APICallOptions} options * @param {APICallOptions} [options]
* @return {Promise<any|APIResponse>} * @return {Promise<any|APIResponse>}
*/ */
......
...@@ -162,7 +162,7 @@ export default function groups( ...@@ -162,7 +162,7 @@ export default function groups(
}); });
} }
/* /**
* Fetch a specific group. * Fetch a specific group.
* *
* @param {string} id * @param {string} id
......
...@@ -29,6 +29,12 @@ import { SearchClient } from '../search-client'; ...@@ -29,6 +29,12 @@ import { SearchClient } from '../search-client';
import { isReply } from '../helpers/annotation-metadata'; import { isReply } from '../helpers/annotation-metadata';
/**
* @param {ReturnType<import('./api').default>} api
* @param {import('../store').SidebarStore} store
* @param {import('./streamer').default} streamer
* @param {import('./stream-filter').default} streamFilter
*/
// @inject // @inject
export default function loadAnnotationsService( export default function loadAnnotationsService(
api, api,
...@@ -83,7 +89,7 @@ export default function loadAnnotationsService( ...@@ -83,7 +89,7 @@ export default function loadAnnotationsService(
const searchOptions = { const searchOptions = {
incremental: true, incremental: true,
maxResults: maxResults ?? null, maxResults,
separateReplies: false, separateReplies: false,
// Annotations are fetched in order of creation by default. This is expected // Annotations are fetched in order of creation by default. This is expected
...@@ -97,8 +103,8 @@ export default function loadAnnotationsService( ...@@ -97,8 +103,8 @@ export default function loadAnnotationsService(
// //
// If the backend would allow us to sort on document location, we could do even better. // If the backend would allow us to sort on document location, we could do even better.
sortBy: /** @type {SortBy} */ (sortBy ?? 'created'), sortBy,
sortOrder: /** @type {SortOrder} */ (sortOrder ?? 'asc'), sortOrder,
}; };
searchClient = new SearchClient(api.search, searchOptions); searchClient = new SearchClient(api.search, searchOptions);
......
/**
* @typedef {'equals'|'one_of'} Operator
*/
/** /**
* Filter clause against which annotation updates are tested before being * Filter clause against which annotation updates are tested before being
* sent to the client. * sent to the client.
* *
* @typedef FilterClause * @typedef FilterClause
* @prop {string} field * @prop {'/group'|'/id'|'/references'|'/uri'} field
* @prop {Operator} operator * @prop {'equals'|'one_of'} operator
* @prop {any} value * @prop {string|string[]} value
* @prop {boolean} case_sensitive - TODO: Backend doesn't use this at present, * @prop {boolean} case_sensitive - TODO: Backend doesn't use this at present,
* but it seems important for certain fields (eg. ID). * but it seems important for certain fields (eg. ID).
*/ */
...@@ -56,10 +52,10 @@ export default class StreamFilter { ...@@ -56,10 +52,10 @@ export default class StreamFilter {
/** /**
* Add a matching clause to the configuration. * Add a matching clause to the configuration.
* *
* @param {string} field - Field to filter by * @param {FilterClause['field']} field - Field to filter by
* @param {Operator} operator - How to filter * @param {FilterClause['operator']} operator - How to filter
* @param {any} value - Value to match * @param {FilterClause['value']} value - Value to match
* @param {boolean} caseSensitive - Whether matching should be case sensitive * @param {FilterClause['case_sensitive']} caseSensitive - Whether matching should be case sensitive
*/ */
addClause(field, operator, value, caseSensitive = false) { addClause(field, operator, value, caseSensitive = false) {
this.filter.clauses.push({ this.filter.clauses.push({
......
...@@ -9,6 +9,12 @@ import { watch } from '../util/watch'; ...@@ -9,6 +9,12 @@ import { watch } from '../util/watch';
* Open a new WebSocket connection to the Hypothesis push notification service. * Open a new WebSocket connection to the Hypothesis push notification service.
* Only one websocket connection may exist at a time, any existing socket is * Only one websocket connection may exist at a time, any existing socket is
* closed. * closed.
*
* @param {import('../store').SidebarStore} store
* @param {ReturnType<import('./oauth-auth').default>} auth
* @param {ReturnType<import('./groups').default>} groups
* @param {ReturnType<import('./session').default>} session
* @param {Record<string, any>} settings
*/ */
// @inject // @inject
export default function Streamer(store, auth, groups, session, settings) { export default function Streamer(store, auth, groups, session, settings) {
......
...@@ -80,7 +80,7 @@ export default function toastMessenger(store) { ...@@ -80,7 +80,7 @@ export default function toastMessenger(store) {
* Add an error toast message with `messageText` * Add an error toast message with `messageText`
* *
* @param {string} messageText * @param {string} messageText
* @param {MessageOptions} options * @param {MessageOptions} [options]
*/ */
const error = (messageText, options) => { const error = (messageText, options) => {
addMessage('error', messageText, options); addMessage('error', messageText, options);
...@@ -90,7 +90,7 @@ export default function toastMessenger(store) { ...@@ -90,7 +90,7 @@ export default function toastMessenger(store) {
* Add a success toast message with `messageText` * Add a success toast message with `messageText`
* *
* @param {string} messageText * @param {string} messageText
* @param {MessageOptions} options * @param {MessageOptions} [options]
*/ */
const success = (messageText, options) => { const success = (messageText, options) => {
addMessage('success', messageText, options); addMessage('success', messageText, options);
...@@ -100,7 +100,7 @@ export default function toastMessenger(store) { ...@@ -100,7 +100,7 @@ export default function toastMessenger(store) {
* Add a warn/notice toast message with `messageText` * Add a warn/notice toast message with `messageText`
* *
* @param {string} messageText * @param {string} messageText
* @param {MessageOptions} options * @param {MessageOptions} [options]
*/ */
const notice = (messageText, options) => { const notice = (messageText, options) => {
addMessage('notice', messageText, options); addMessage('notice', messageText, options);
......
...@@ -342,7 +342,7 @@ function highlightAnnotations(ids) { ...@@ -342,7 +342,7 @@ function highlightAnnotations(ids) {
/** /**
* Remove annotations from the currently displayed set. * Remove annotations from the currently displayed set.
* *
* @param {Annotation[]} annotations - * @param {AnnotationStub[]} annotations -
* Annotations to remove. These may be complete annotations or stubs which * Annotations to remove. These may be complete annotations or stubs which
* only contain an `id` property. * only contain an `id` property.
*/ */
......
...@@ -97,7 +97,6 @@ function createDraft(annotation, changes) { ...@@ -97,7 +97,6 @@ function createDraft(annotation, changes) {
* *
* An empty draft has no text and no reference tags. * An empty draft has no text and no reference tags.
*/ */
function deleteNewAndEmptyDrafts() { function deleteNewAndEmptyDrafts() {
const { removeAnnotations } = require('./annotations'); const { removeAnnotations } = require('./annotations');
......
...@@ -83,8 +83,8 @@ const actions = actionTypes(update); ...@@ -83,8 +83,8 @@ const actions = actionTypes(update);
* has been notified about but has not yet applied. * has been notified about but has not yet applied.
* *
* @param {Object} args * @param {Object} args
* @param {Annotation[]} args.updatedAnnotations * @param {Annotation[]} [args.updatedAnnotations]
* @param {Annotation[]} args.deletedAnnotations * @param {Annotation[]} [args.deletedAnnotations]
*/ */
function receiveRealTimeUpdates({ function receiveRealTimeUpdates({
updatedAnnotations = [], updatedAnnotations = [],
......
...@@ -8,8 +8,8 @@ ...@@ -8,8 +8,8 @@
* {url: '/things/foo', params: {q: 'bar'}} * {url: '/things/foo', params: {q: 'bar'}}
* *
* @param {string} url * @param {string} url
* @param {Object} params * @param {Record<string, any>} params
* @return {{ url: string, params: Object }} * @return {{ url: string, params: Record<string, any>}}
*/ */
export function replaceURLParams(url, params) { export function replaceURLParams(url, params) {
const unusedParams = {}; const unusedParams = {};
......
...@@ -38,7 +38,7 @@ import shallowEqual from 'shallowequal'; ...@@ -38,7 +38,7 @@ import shallowEqual from 'shallowequal';
* *
* Values are compared using strict equality (`===`). * Values are compared using strict equality (`===`).
* *
* @param {(callback: Function) => Function} subscribe - Function used to * @param {(callback: () => void) => Function} subscribe - Function used to
* subscribe to notifications of _potential_ changes in the watched values. * subscribe to notifications of _potential_ changes in the watched values.
* @param {Function|Array<Function>} watchFns - A function or array of functions * @param {Function|Array<Function>} watchFns - A function or array of functions
* which return the current watched values * which return the current watched values
......
...@@ -60,7 +60,7 @@ export default class Socket extends TinyEmitter { ...@@ -60,7 +60,7 @@ export default class Socket extends TinyEmitter {
minTimeout: RECONNECT_MIN_DELAY * 2, minTimeout: RECONNECT_MIN_DELAY * 2,
// Don't retry forever -- fail permanently after 10 retries // Don't retry forever -- fail permanently after 10 retries
retries: 10, retries: 10,
// Randomize retry times to minimise the thundering herd effect // Randomize retry times to minimize the thundering herd effect
randomize: true, randomize: true,
}); });
...@@ -76,7 +76,7 @@ export default class Socket extends TinyEmitter { ...@@ -76,7 +76,7 @@ export default class Socket extends TinyEmitter {
return; return;
} }
const err = new Error( const err = new Error(
'WebSocket closed abnormally, code: ' + event.code `WebSocket closed abnormally, code: ${event.code}`
); );
console.warn(err); console.warn(err);
onAbnormalClose(err); onAbnormalClose(err);
......
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