feat(nbstore): new doc sync engine (#8918)

This commit is contained in:
EYHN
2024-12-07 08:05:02 +00:00
parent fafacdb265
commit f54f6e88cb
23 changed files with 1252 additions and 43 deletions
@@ -0,0 +1,38 @@
export class ClockMap {
max: Date = new Date(0);
constructor(private readonly map: Map<string, Date>) {
for (const value of map.values()) {
if (value.getTime() > this.max.getTime()) {
this.max = value;
}
}
}
get(id: string): Date {
return this.map.get(id) ?? new Date(0);
}
set(id: string, value: Date) {
this.map.set(id, value);
if (value.getTime() > this.max.getTime()) {
this.max = value;
}
}
setIfBigger(id: string, value: Date) {
if (value.getTime() > this.get(id).getTime()) {
this.set(id, value);
return true;
}
return false;
}
clear() {
this.map.clear();
this.max = new Date(0);
}
keys() {
return Array.from(this.map.keys());
}
}