Skip to content

Commit

Permalink
Add note for onAdd's second param
Browse files Browse the repository at this point in the history
  • Loading branch information
francislavoie authored Dec 18, 2023
1 parent 4a3f4c2 commit d93f173
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/state/schema-callbacks.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ The `onAdd` callback is called with the new instance and its key on holder objec
end)
```

!!! Note "Avoiding doubled-up callbacks"
You may notice that `onAdd` is called multiple times when an entry is inserted. This is because the "add" callback is called immediately by default for existing items in the collection. When the collection is nested within another schema instance, this can cause doubling. To fix this, set the second argument of `onAdd` to false (e.g. `.onAdd(callback, false)`). See [#147](https://github.com/colyseus/schema/issues/147#issuecomment-1538684941).

---

#### `onRemove (item, key)`
Expand Down

0 comments on commit d93f173

Please sign in to comment.