Skip to content

Commit

Permalink
golf a few things
Browse files Browse the repository at this point in the history
  • Loading branch information
EskiMojo14 committed Jun 28, 2024
1 parent 09c36a2 commit f0088d3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
10 changes: 4 additions & 6 deletions packages/toolkit/src/entities/sorted_state_adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export function createSortedStateAdapter<T, Id extends EntityId>(
return false
}

for (let i = 0; i < a.length && i < b.length; i++) {
for (let i = 0; i < a.length; i++) {
if (a[i] === b[i]) {
continue
}
Expand All @@ -191,7 +191,7 @@ export function createSortedStateAdapter<T, Id extends EntityId>(
replacedIds?: boolean,
) => void

const mergeInsertion: MergeFunction = (
const mergeFunction: MergeFunction = (
state,
addedItems,
appliedUpdates,
Expand All @@ -202,9 +202,9 @@ export function createSortedStateAdapter<T, Id extends EntityId>(

const stateEntities = state.entities as Record<Id, T>

let ids = currentIds
let ids: Iterable<Id> = currentIds
if (replacedIds) {
ids = Array.from(new Set(currentIds))
ids = new Set(currentIds)
}

let sortedEntities: T[] = []
Expand Down Expand Up @@ -241,8 +241,6 @@ export function createSortedStateAdapter<T, Id extends EntityId>(
}
}

const mergeFunction: MergeFunction = mergeInsertion

return {
removeOne,
removeMany,
Expand Down
4 changes: 1 addition & 3 deletions packages/toolkit/src/entities/unsorted_state_adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,7 @@ export function createUnsortedStateAdapter<T, Id extends EntityId>(
// Spreads ignore falsy values, so this works even if there isn't
// an existing update already at this key
changes: {
...(updatesPerEntity[update.id]
? updatesPerEntity[update.id].changes
: null),
...updatesPerEntity[update.id]?.changes,
...update.changes,
},
}
Expand Down

0 comments on commit f0088d3

Please sign in to comment.