Skip to content

Commit 6dac1d2

Browse files
committed
Actually pass index comparators through
1 parent 33ea7a2 commit 6dac1d2

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/entities/create_adapter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function createEntityAdapter<T>(
2828
const stateFactory = createInitialStateFactory<T, IndexComparers<T>>(indices)
2929
const selectorsFactory = createSelectorsFactory<T>()
3030
const stateAdapter = sortComparer
31-
? createSortedStateAdapter(selectId, sortComparer as Comparer<T>)
31+
? createSortedStateAdapter(selectId, sortComparer as Comparer<T>, indices)
3232
: createUnsortedStateAdapter(selectId)
3333

3434
return {

src/entities/sorted_state_adapter.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import {
44
Comparer,
55
EntityStateAdapter,
66
Update,
7-
EntityId
7+
EntityId,
8+
IndexComparers
89
} from './models'
910
import { createStateOperator } from './state_adapter'
1011
import { createUnsortedStateAdapter } from './unsorted_state_adapter'
@@ -16,7 +17,8 @@ import {
1617

1718
export function createSortedStateAdapter<T>(
1819
selectId: IdSelector<T>,
19-
sort: Comparer<T>
20+
sort: Comparer<T>,
21+
indices: IndexComparers<T> = {}
2022
): EntityStateAdapter<T> {
2123
type R = EntityState<T>
2224

@@ -131,8 +133,6 @@ export function createSortedStateAdapter<T>(
131133
}
132134
}
133135

134-
const indexComparers: Record<string, Comparer<T>> = {}
135-
136136
function merge(models: T[], state: R): void {
137137
models.sort(sort)
138138

@@ -149,8 +149,8 @@ export function createSortedStateAdapter<T>(
149149
sort
150150
)
151151

152-
for (let key in indexComparers) {
153-
updateSortedIds(state.indices, key, allEntities, indexComparers[key])
152+
for (let key in indices) {
153+
updateSortedIds(state.indices, key, allEntities, indices[key])
154154
}
155155
}
156156

0 commit comments

Comments
 (0)