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