Fix conflict on removed values in repository

This commit is contained in:
Jon Staab
2024-10-18 15:55:56 -07:00
parent b34e4923a8
commit 538a7c51af
3 changed files with 12 additions and 19 deletions
+1 -1
View File
@@ -3635,7 +3635,7 @@
},
"packages/app": {
"name": "@welshman/app",
"version": "0.0.16",
"version": "0.0.17",
"license": "MIT",
"dependencies": {
"@welshman/dvm": "~0.0.10",
+1
View File
@@ -191,6 +191,7 @@ export const deriveEventsMapped = <T>(repository: Repository, {
for (const update of updates) {
for (const event of update.added.values()) {
added.set(event.id, event)
removed.delete(event.id)
}
for (const id of update.removed) {
+10 -18
View File
@@ -32,24 +32,7 @@ export class Repository<E extends HashedEvent = TrustedEvent> extends Emitter {
}
load = (events: E[], chunkSize = 1000) => {
this.clear()
const added = []
for (const eventsChunk of chunk(chunkSize, events)) {
for (const event of eventsChunk) {
if (this.publish(event, {shouldNotify: false})) {
added.push(event)
}
}
}
const removed = new Set(this.deletes.keys())
this.emit('update', {added, removed})
}
clear = () => {
const removed = new Set(this.eventsById.keys())
this.eventsById.clear()
@@ -60,7 +43,16 @@ export class Repository<E extends HashedEvent = TrustedEvent> extends Emitter {
this.eventsByAuthor.clear()
this.deletes.clear()
this.emit('update', {added: [], removed})
for (const eventsChunk of chunk(chunkSize, events)) {
for (const event of eventsChunk) {
if (this.publish(event, {shouldNotify: false})) {
added.push(event)
removed.delete(event.id)
}
}
}
this.emit('update', {added, removed})
}
// API