Skip to content

Commit 0252d80

Browse files
committed
Document caveats with update operations
1 parent 7b46be4 commit 0252d80

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

docs/api/createEntityAdapter.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,14 @@ const bookIds = simpleSelectors.selectIds(store.getState().books)
290290
const allBooks = globalizedSelectors.selectAll(store.getState())
291291
```
292292

293+
## Notes
294+
295+
### Applying Multiple Updates
296+
297+
If `updateMany()` is called with multiple updates targeted to the same ID, they will be merged into a single update, with later updates overwriting the earlier ones.
298+
299+
For both `updateOne()` and `updateMany()`, changing the ID of one existing entity to match the ID of a second existing entity will cause the first to replace the second completely.
300+
293301
## Examples
294302

295303
Exercising several of the CRUD methods and selectors:

src/entities/unsorted_state_adapter.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ export function createUnsortedStateAdapter<T>(selectId: IdSelector<T>): any {
110110
if (update.id in state.entities) {
111111
// If there are multiple updates to one entity, merge them together
112112
updatesPerEntity[update.id] = {
113+
// Spreads ignore falsy values, so this works even if there isn't
114+
// an existing update already at this key
113115
...updatesPerEntity[update.id],
114116
...update
115117
}

0 commit comments

Comments
 (0)