Skip to content

Commit a6b8727

Browse files
committed
Revert "reset more entity files"
This reverts commit 82c9262.
1 parent 248892a commit a6b8727

File tree

5 files changed

+28
-27
lines changed

5 files changed

+28
-27
lines changed

packages/toolkit/src/entities/tests/entity_slice_enhancer.test.ts

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,47 +7,44 @@ import {
77
} from '@reduxjs/toolkit'
88
import type {
99
PayloadAction,
10-
Slice,
1110
SliceCaseReducers,
12-
UnknownAction,
11+
ValidateSliceCaseReducers,
1312
} from '../..'
1413
import type { EntityId, EntityState, IdSelector } from '../models'
15-
import type { BookModel } from './fixtures/book'
14+
import { AClockworkOrange, type BookModel } from './fixtures/book'
1615

1716
describe('Entity Slice Enhancer', () => {
18-
let slice: Slice<EntityState<BookModel, BookModel['id']>>
17+
let slice: ReturnType<typeof entitySliceEnhancer<BookModel, string>>
1918

2019
beforeEach(() => {
21-
const indieSlice = entitySliceEnhancer({
20+
slice = entitySliceEnhancer({
2221
name: 'book',
2322
selectId: (book: BookModel) => book.id,
2423
})
25-
slice = indieSlice
2624
})
2725

2826
it('exposes oneAdded', () => {
29-
const book = {
30-
id: '0',
31-
title: 'Der Steppenwolf',
32-
author: 'Herman Hesse',
33-
}
34-
const action = slice.actions.oneAdded(book)
35-
const oneAdded = slice.reducer(undefined, action as UnknownAction)
36-
expect(oneAdded.entities['0']).toBe(book)
27+
const action = slice.actions.oneAdded(AClockworkOrange)
28+
const oneAdded = slice.reducer(undefined, action)
29+
expect(oneAdded.entities[AClockworkOrange.id]).toBe(AClockworkOrange)
3730
})
3831
})
3932

40-
interface EntitySliceArgs<T, Id extends EntityId> {
33+
interface EntitySliceArgs<
34+
T,
35+
Id extends EntityId,
36+
CaseReducers extends SliceCaseReducers<EntityState<T, Id>>,
37+
> {
4138
name: string
4239
selectId: IdSelector<T, Id>
43-
modelReducer?: SliceCaseReducers<T>
40+
modelReducer?: ValidateSliceCaseReducers<EntityState<T, Id>, CaseReducers>
4441
}
4542

46-
function entitySliceEnhancer<T, Id extends EntityId>({
47-
name,
48-
selectId,
49-
modelReducer,
50-
}: EntitySliceArgs<T, Id>) {
43+
function entitySliceEnhancer<
44+
T,
45+
Id extends EntityId,
46+
CaseReducers extends SliceCaseReducers<EntityState<T, Id>> = {},
47+
>({ name, selectId, modelReducer }: EntitySliceArgs<T, Id, CaseReducers>) {
5148
const modelAdapter = createEntityAdapter({
5249
selectId,
5350
})

packages/toolkit/src/entities/tests/entity_state.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { EntityAdapter } from '../index'
2-
import { createEntityAdapter } from '../index'
1+
import type { EntityAdapter } from '../models'
2+
import { createEntityAdapter } from '../create_adapter'
33
import type { PayloadAction } from '../../createAction'
44
import { createAction } from '../../createAction'
55
import { createSlice } from '../../createSlice'

packages/toolkit/src/entities/tests/state_adapter.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { EntityAdapter } from '../index'
2-
import { createEntityAdapter } from '../index'
1+
import type { EntityAdapter } from '../models'
2+
import { createEntityAdapter } from '../create_adapter'
33
import type { PayloadAction } from '../../createAction'
44
import { configureStore } from '../../configureStore'
55
import { createSlice } from '../../createSlice'

packages/toolkit/src/entities/tests/state_selectors.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createDraftSafeSelectorCreator } from '../../createDraftSafeSelector'
2-
import type { EntityAdapter, EntityState } from '../index'
3-
import { createEntityAdapter } from '../index'
2+
import type { EntityAdapter, EntityState } from '../models'
3+
import { createEntityAdapter } from '../create_adapter'
44
import type { EntitySelectors } from '../models'
55
import type { BookModel } from './fixtures/book'
66
import { AClockworkOrange, AnimalFarm, TheGreatGatsby } from './fixtures/book'

packages/toolkit/src/entities/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,7 @@ export function splitAddedUpdatedEntities<T, Id extends EntityId>(
5555
}
5656
return [added, updated]
5757
}
58+
59+
export function capitalize<S extends string>(str: S) {
60+
return str && (str.replace(str[0], str[0].toUpperCase()) as Capitalize<S>)
61+
}

0 commit comments

Comments
 (0)