openreplay/frontend/app/player/common/ListWalkerWithMarks.ts
Andrey Babushkin fd5c0c9747
Add lokalisation (#3092)
* applied eslint

* add locales and lint the project

* removed error boundary

* updated locales

* fix min files

* fix locales
2025-03-06 17:43:15 +01:00

54 lines
1 KiB
TypeScript

import type { Timed } from './types';
import ListWalker from './ListWalker';
type CheckFn<T> = (t: T) => boolean;
export default class ListWalkerWithMarks<
T extends Timed,
> extends ListWalker<T> {
private _markCountNow: number = 0;
private _markCount: number = 0;
constructor(
private isMarked: CheckFn<T>,
initialList: T[] = [],
) {
super(initialList);
this._markCount = initialList.reduce(
(n, item) => (isMarked(item) ? n + 1 : n),
0,
);
}
append(item: T) {
if (this.isMarked(item)) {
this._markCount++;
}
super.append(item);
}
protected moveNext() {
const val = super.moveNext();
if (val && this.isMarked(val)) {
this._markCountNow++;
}
return val;
}
protected movePrev() {
const val = super.movePrev();
if (val && this.isMarked(val)) {
this._markCountNow--;
}
return val;
}
get markedCountNow(): number {
return this._markCountNow;
}
get markedCount(): number {
return this._markCount;
}
}