Skip to content

Commit 9bb035e

Browse files
committed
remove map from entityAdapter
1 parent 7fc98bb commit 9bb035e

File tree

7 files changed

+5
-118
lines changed

7 files changed

+5
-118
lines changed

src/entities/models.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ export interface Dictionary<T> extends DictionaryNum<T> {
3535
*/
3636
export type Update<T> = { id: EntityId; changes: Partial<T> }
3737

38-
/**
39-
* @alpha
40-
*/
41-
export type EntityMap<T> = (entity: T) => T
42-
4338
/**
4439
* @alpha
4540
*/
@@ -53,7 +48,7 @@ export interface EntityDefinition<T> {
5348
sortComparer: false | Comparer<T>
5449
}
5550

56-
type PreventAny<S, T> = IsAny<S, EntityState<T>, S>
51+
export type PreventAny<S, T> = IsAny<S, EntityState<T>, S>
5752

5853
export interface EntityStateAdapter<T> {
5954
addOne<S extends EntityState<T>>(state: PreventAny<S, T>, entity: T): S
@@ -123,8 +118,6 @@ export interface EntityStateAdapter<T> {
123118
state: PreventAny<S, T>,
124119
entities: PayloadAction<T[]>
125120
): S
126-
127-
map<S extends EntityState<T>>(state: PreventAny<S, T>, map: EntityMap<T>): S
128121
}
129122

130123
export interface EntitySelectors<T, V> {

src/entities/sorted_state_adapter.test.ts

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -331,40 +331,6 @@ describe('Sorted State Adapter', () => {
331331
})
332332
})
333333

334-
it('should let you map over entities in the state', () => {
335-
const firstChange = { ...TheGreatGatsby, title: 'First change' }
336-
const secondChange = { ...AClockworkOrange, title: 'Second change' }
337-
338-
const withMany = adapter.setAll(state, [
339-
TheGreatGatsby,
340-
AClockworkOrange,
341-
AnimalFarm
342-
])
343-
344-
const withUpdates = adapter.map(withMany, book =>
345-
book.title === TheGreatGatsby.title
346-
? firstChange
347-
: book.title === AClockworkOrange.title
348-
? secondChange
349-
: book
350-
)
351-
352-
expect(withUpdates).toEqual({
353-
ids: [AnimalFarm.id, TheGreatGatsby.id, AClockworkOrange.id],
354-
entities: {
355-
[AnimalFarm.id]: AnimalFarm,
356-
[TheGreatGatsby.id]: {
357-
...TheGreatGatsby,
358-
...firstChange
359-
},
360-
[AClockworkOrange.id]: {
361-
...AClockworkOrange,
362-
...secondChange
363-
}
364-
}
365-
})
366-
})
367-
368334
it('should let you add one entity to the state with upsert()', () => {
369335
const withOneEntity = adapter.upsertOne(state, TheGreatGatsby)
370336
expect(withOneEntity).toEqual({

src/entities/sorted_state_adapter.ts

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ import {
33
IdSelector,
44
Comparer,
55
EntityStateAdapter,
6-
Update,
7-
EntityMap,
8-
EntityId
6+
Update
97
} from './models'
108
import { createStateOperator } from './state_adapter'
119
import { createUnsortedStateAdapter } from './unsorted_state_adapter'
@@ -72,21 +70,6 @@ export function createSortedStateAdapter<T>(
7270
}
7371
}
7472

75-
function mapMutably(updatesOrMap: EntityMap<T>, state: R): void {
76-
const updates: Update<T>[] = state.ids.reduce(
77-
(changes: Update<T>[], id: EntityId) => {
78-
const change = updatesOrMap(state.entities[id]!)
79-
if (change !== state.entities[id]) {
80-
changes.push({ id, changes: change })
81-
}
82-
return changes
83-
},
84-
[]
85-
)
86-
87-
updateManyMutably(updates, state)
88-
}
89-
9073
function upsertOneMutably(entity: T, state: R): void {
9174
return upsertManyMutably([entity], state)
9275
}
@@ -151,7 +134,6 @@ export function createSortedStateAdapter<T>(
151134
setAll: createStateOperator(setAllMutably),
152135
addMany: createStateOperator(addManyMutably),
153136
updateMany: createStateOperator(updateManyMutably),
154-
upsertMany: createStateOperator(upsertManyMutably),
155-
map: createStateOperator(mapMutably)
137+
upsertMany: createStateOperator(upsertManyMutably)
156138
}
157139
}

src/entities/unsorted_state_adapter.test.ts

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -250,40 +250,6 @@ describe('Unsorted State Adapter', () => {
250250
expect(entities.c).toBeTruthy()
251251
})
252252

253-
it('should let you map over entities in the state', () => {
254-
const firstChange = { ...TheGreatGatsby, title: 'First change' }
255-
const secondChange = { ...AClockworkOrange, title: 'Second change' }
256-
257-
const withMany = adapter.setAll(state, [
258-
TheGreatGatsby,
259-
AClockworkOrange,
260-
AnimalFarm
261-
])
262-
263-
const withUpdates = adapter.map(withMany, book =>
264-
book.title === TheGreatGatsby.title
265-
? firstChange
266-
: book.title === AClockworkOrange.title
267-
? secondChange
268-
: book
269-
)
270-
271-
expect(withUpdates).toEqual({
272-
ids: [TheGreatGatsby.id, AClockworkOrange.id, AnimalFarm.id],
273-
entities: {
274-
[TheGreatGatsby.id]: {
275-
...TheGreatGatsby,
276-
...firstChange
277-
},
278-
[AClockworkOrange.id]: {
279-
...AClockworkOrange,
280-
...secondChange
281-
},
282-
[AnimalFarm.id]: AnimalFarm
283-
}
284-
})
285-
})
286-
287253
it('should let you add one entity to the state with upsert()', () => {
288254
const withOneEntity = adapter.upsertOne(state, TheGreatGatsby)
289255
expect(withOneEntity).toEqual({

src/entities/unsorted_state_adapter.ts

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
EntityStateAdapter,
44
IdSelector,
55
Update,
6-
EntityMap,
76
EntityId
87
} from './models'
98
import { createStateOperator } from './state_adapter'
@@ -57,7 +56,7 @@ export function createUnsortedStateAdapter<T>(
5756
}
5857
}
5958

60-
function removeAll<S extends R>(state: S): S {
59+
function removeAll(state: R): any {
6160
return Object.assign({}, state, {
6261
ids: [],
6362
entities: {}
@@ -120,22 +119,6 @@ export function createUnsortedStateAdapter<T>(
120119
}
121120
}
122121

123-
function mapMutably(map: EntityMap<T>, state: R): void {
124-
const changes: Update<T>[] = state.ids.reduce(
125-
(changes: Update<T>[], id: EntityId) => {
126-
const change = map(state.entities[id]!)
127-
if (change !== state.entities[id]) {
128-
changes.push({ id, changes: change })
129-
}
130-
return changes
131-
},
132-
[]
133-
)
134-
const updates = changes.filter(({ id }) => id in state.entities)
135-
136-
return updateManyMutably(updates, state)
137-
}
138-
139122
function upsertOneMutably(entity: T, state: R): void {
140123
return upsertManyMutably([entity], state)
141124
}
@@ -167,7 +150,6 @@ export function createUnsortedStateAdapter<T>(
167150
upsertOne: createStateOperator(upsertOneMutably),
168151
upsertMany: createStateOperator(upsertManyMutably),
169152
removeOne: createStateOperator(removeOneMutably),
170-
removeMany: createStateOperator(removeManyMutably),
171-
map: createStateOperator(mapMutably)
153+
removeMany: createStateOperator(removeManyMutably)
172154
}
173155
}

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ export {
7575
EntityState,
7676
EntityAdapter,
7777
Update,
78-
EntityMap,
7978
IdSelector,
8079
Comparer
8180
} from './entities/models'

type-tests/files/createEntityAdapter.typetest.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ function extractReducers<T>(
1919
sortComparer,
2020
getInitialState,
2121
getSelectors,
22-
map,
2322
...rest
2423
} = adapter
2524
return rest

0 commit comments

Comments
 (0)