Skip to content

Commit a9552cf

Browse files
committed
Improve types in sidebar/helpers/view-filter.js
1 parent 7ec8715 commit a9552cf

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/sidebar/helpers/view-filter.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
/**
1111
* @typedef {import('../../types/api').Annotation} Annotation
12+
* @typedef {import('../util/search-filter').Facet} Facet
1213
*/
1314

1415
import { quote } from './annotation-metadata';
@@ -26,6 +27,7 @@ import * as unicodeUtils from '../util/unicode';
2627
* @prop {(term: any, value: any) => boolean} match
2728
*/
2829

30+
/** @param {Annotation} ann */
2931
function displayName(ann) {
3032
if (!ann.user_info) {
3133
return '';
@@ -35,6 +37,9 @@ function displayName(ann) {
3537

3638
/**
3739
* Normalize a field value or query term for comparison.
40+
*
41+
* @template {string|number} T
42+
* @param {T} val
3843
*/
3944
function normalize(val) {
4045
if (typeof val !== 'string') {
@@ -53,7 +58,7 @@ function normalize(val) {
5358
class TermFilter {
5459
/**
5560
* @param {string} field - Name of field to match
56-
* @param {string} term - Query term
61+
* @param {string|number} term - Query term
5762
* @param {Checker} checker - Functions for extracting term values from
5863
* an annotation and checking whether they match a query term.
5964
*/
@@ -63,6 +68,11 @@ class TermFilter {
6368
this.checker = checker;
6469
}
6570

71+
/**
72+
* Return true if an annotation matches this filter.
73+
*
74+
* @param {Annotation} ann
75+
*/
6676
matches(ann) {
6777
const checker = this.checker;
6878
if (checker.autofalse && checker.autofalse(ann)) {
@@ -94,6 +104,11 @@ class BinaryOpFilter {
94104
this.filters = filters;
95105
}
96106

107+
/**
108+
* Return true if an annotation matches this filter.
109+
*
110+
* @param {Annotation} ann
111+
*/
97112
matches(ann) {
98113
if (this.operator === 'and') {
99114
return this.filters.every(filter => filter.matches(ann));
@@ -154,8 +169,7 @@ const fieldMatchers = {
154169
* Filters a set of annotations.
155170
*
156171
* @param {Annotation[]} annotations
157-
* @param {object} filters - Faceted filter generated by
158-
* `generateFacetedFilter`.
172+
* @param {Record<string, Facet>} filters - Faceted filter generated by `generateFacetedFilter`
159173
* @return {string[]} IDs of matching annotations.
160174
*/
161175
export function filterAnnotations(annotations, filters) {

0 commit comments

Comments
 (0)