Skip to content

Commit 58df106

Browse files
committed
Remove removeMany(predicate) overload
1 parent edc481a commit 58df106

File tree

6 files changed

+5
-62
lines changed

6 files changed

+5
-62
lines changed

src/entities/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ export {
55
EntityAdapter,
66
Update,
77
EntityMap,
8-
Predicate,
98
IdSelector,
109
Comparer
1110
} from './models'

src/entities/models.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ export interface UpdateNum<T> {
4242
*/
4343
export type Update<T> = UpdateStr<T> | UpdateNum<T>
4444

45-
/**
46-
* @alpha
47-
*/
48-
export type Predicate<T> = (entity: T) => boolean
49-
5045
/**
5146
* @alpha
5247
*/
@@ -96,8 +91,6 @@ export interface EntityStateAdapter<T> {
9691
state: S,
9792
keys: TypeOrPayloadAction<number[]>
9893
): S
99-
/** @deprecated Should not pass functions inside of Redux actions */
100-
removeMany<S extends EntityState<T>>(state: S, predicate: Predicate<T>): S
10194

10295
removeAll<S extends EntityState<T>>(state: S): S
10396

src/entities/sorted_state_adapter.test.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -151,23 +151,6 @@ describe('Sorted State Adapter', () => {
151151
})
152152
})
153153

154-
it('should let you remove many entities by a predicate from the state', () => {
155-
const withAll = adapter.setAll(state, [
156-
TheGreatGatsby,
157-
AClockworkOrange,
158-
AnimalFarm
159-
])
160-
161-
const withoutMany = adapter.removeMany(withAll, p => p.id.startsWith('a'))
162-
163-
expect(withoutMany).toEqual({
164-
ids: [TheGreatGatsby.id],
165-
entities: {
166-
[TheGreatGatsby.id]: TheGreatGatsby
167-
}
168-
})
169-
})
170-
171154
it('should let you remove all entities from the state', () => {
172155
const withAll = adapter.setAll(state, [
173156
TheGreatGatsby,

src/entities/unsorted_state_adapter.test.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -117,23 +117,6 @@ describe('Unsorted State Adapter', () => {
117117
})
118118
})
119119

120-
it('should let you remove many entities by a predicate from the state', () => {
121-
const withAll = adapter.setAll(state, [
122-
TheGreatGatsby,
123-
AClockworkOrange,
124-
AnimalFarm
125-
])
126-
127-
const withoutMany = adapter.removeMany(withAll, p => p.id.startsWith('a'))
128-
129-
expect(withoutMany).toEqual({
130-
ids: [TheGreatGatsby.id],
131-
entities: {
132-
[TheGreatGatsby.id]: TheGreatGatsby
133-
}
134-
})
135-
})
136-
137120
it('should let you remove all entities from the state', () => {
138121
const withAll = adapter.setAll(state, [
139122
TheGreatGatsby,

src/entities/unsorted_state_adapter.ts

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
EntityStateAdapter,
44
IdSelector,
55
Update,
6-
Predicate,
76
EntityMap
87
} from './models'
98
import { createStateOperator } from './state_adapter'
@@ -47,33 +46,20 @@ export function createUnsortedStateAdapter<T>(selectId: IdSelector<T>): any {
4746
return removeManyMutably([key], state)
4847
}
4948

50-
function removeManyMutably(keys: T[], state: R): void
51-
function removeManyMutably(predicate: Predicate<T>, state: R): void
52-
function removeManyMutably(
53-
keysOrPredicate: any[] | Predicate<T>,
54-
state: any
55-
): void {
56-
let keysToRemove: any[] = []
57-
58-
if (keysOrPredicate instanceof Array) {
59-
keysToRemove = keysOrPredicate
60-
} else {
61-
keysToRemove = state.ids.filter((key: any) =>
62-
keysOrPredicate(state.entities[key])
63-
)
64-
}
65-
49+
function removeManyMutably(keys: any[], state: R): void {
6650
let didMutate = false
6751

68-
keysToRemove.forEach(key => {
52+
keys.forEach(key => {
6953
if (key in state.entities) {
7054
delete state.entities[key]
7155
didMutate = true
7256
}
7357
})
7458

7559
if (didMutate) {
76-
state.ids = state.ids.filter((id: any) => id in state.entities)
60+
// Work around TS not letting us call array methods if it's not a single known type
61+
const ids = state.ids as string[]
62+
state.ids = ids.filter((id: any) => id in state.entities)
7763
}
7864
}
7965

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ export {
6969
EntityAdapter,
7070
Update,
7171
EntityMap,
72-
Predicate,
7372
IdSelector,
7473
Comparer
7574
} from './entities/models'

0 commit comments

Comments
 (0)