Skip to content

Commit d0357ed

Browse files
committed
refactor: define Grouper.comparator and create a dummy default one
1 parent 23f1a36 commit d0357ed

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

src/Query/Filter/Field.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { Comparator } from '../Sorter';
33
import * as RegExpTools from '../../lib/RegExpTools';
44
import { Grouper } from '../Grouper';
55
import type { GrouperFunction } from '../Grouper';
6+
import type { Task } from './../../Task';
67
import type { FilterOrErrorMessage } from './Filter';
78

89
/**
@@ -287,7 +288,7 @@ export abstract class Field {
287288
* @param reverse - false for normal group order, true for reverse group order.
288289
*/
289290
public createGrouper(reverse: boolean): Grouper {
290-
return new Grouper(this.fieldNameSingular(), this.grouper(), reverse);
291+
return new Grouper(this.fieldNameSingular(), this.grouper(), reverse, this.defaultComparator);
291292
}
292293

293294
/**
@@ -309,4 +310,8 @@ export abstract class Field {
309310
public createReverseGrouper(): Grouper {
310311
return this.createGrouper(true);
311312
}
313+
314+
protected defaultComparator: Comparator = (_a: Task, _b: Task) => {
315+
return 0;
316+
};
312317
}

src/Query/Filter/MultiTextField.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export abstract class MultiTextField extends TextField {
6464
* This overloads {@link Field.createGrouper} to put a plural field name in the {@link Grouper.property}.
6565
*/
6666
public createGrouper(reverse: boolean): Grouper {
67-
return new Grouper(this.fieldNamePlural(), this.grouper(), reverse);
67+
return new Grouper(this.fieldNamePlural(), this.grouper(), reverse, this.defaultComparator);
6868
}
6969

7070
protected grouperRegExp(): RegExp {

src/Query/Grouper.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Task } from '../Task';
2+
import type { Comparator } from './Sorter';
23

34
/**
45
* A group-naming function, that takes a Task object and returns zero or more
@@ -39,9 +40,12 @@ export class Grouper {
3940
*/
4041
public readonly reverse: boolean;
4142

42-
constructor(property: string, grouper: GrouperFunction, reverse: boolean) {
43+
public readonly comparator: Comparator;
44+
45+
constructor(property: string, grouper: GrouperFunction, reverse: boolean, comparator: Comparator) {
4346
this.property = property;
4447
this.grouper = grouper;
4548
this.reverse = reverse;
49+
this.comparator = comparator;
4650
}
4751
}

0 commit comments

Comments
 (0)