2022-10-01 16:09:20 -04:00
|
|
|
export class ChangeList<T>{
|
2022-10-09 16:58:08 -04:00
|
|
|
private set = new Set<T>();
|
2022-10-01 16:09:20 -04:00
|
|
|
|
|
|
|
public get changeCount() {
|
|
|
|
return this.set.size;
|
|
|
|
}
|
|
|
|
|
|
|
|
public get hasChanges() {
|
|
|
|
return this.changeCount > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public handleChange(item: T) {
|
|
|
|
if (!this.set.delete(item))
|
|
|
|
this.set.add(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
public getChanges() {
|
|
|
|
return this.set.values();
|
|
|
|
}
|
|
|
|
|
|
|
|
public map<R>(mapper: (v: T, idx: number, arr: T[]) => R): R[] {
|
|
|
|
return [...this.getChanges()].map(mapper);
|
|
|
|
}
|
|
|
|
}
|