Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix duplicates in crdt.Set

`crdt.Set` can have duplicate rows in it if you do

```js
doc.add({ id: "foo", type: "in-set" })
doc.add({ id: "foo", type: "in-set" })
```

Both of those additions trigger the `doc.sets.emit("type")` event
thus getting the same row in a set twice.

This patch ensures the row isn't in the set before it's added.
  • Loading branch information...
commit d8bdb6b0e7b3985fb580c4f0650a5a25b400d38b 1 parent 3c67697
Raynos (Jake Verbaten) Raynos authored
Showing with 4 additions and 0 deletions.
  1. +4 −0 set.js
4 set.js
View
@@ -57,6 +57,10 @@ function Set(doc, key, value) {
}
function add(row) {
+ if (rows[row.id]) {
+ return
+ }
+
array.push(row)
rows[row.id] = row
set.emit('add', row)
Please sign in to comment.
Something went wrong with that request. Please try again.