Skip to content

Commit 248892a

Browse files
committed
Merge branch 'create-slice-creators' into entity-methods-creator
2 parents f03c2d9 + 82c9262 commit 248892a

File tree

5 files changed

+27
-28
lines changed

5 files changed

+27
-28
lines changed

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

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

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

1920
beforeEach(() => {
20-
slice = entitySliceEnhancer({
21+
const indieSlice = entitySliceEnhancer({
2122
name: 'book',
2223
selectId: (book: BookModel) => book.id,
2324
})
25+
slice = indieSlice
2426
})
2527

2628
it('exposes oneAdded', () => {
27-
const action = slice.actions.oneAdded(AClockworkOrange)
28-
const oneAdded = slice.reducer(undefined, action)
29-
expect(oneAdded.entities[AClockworkOrange.id]).toBe(AClockworkOrange)
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)
3037
})
3138
})
3239

33-
interface EntitySliceArgs<
34-
T,
35-
Id extends EntityId,
36-
CaseReducers extends SliceCaseReducers<EntityState<T, Id>>,
37-
> {
40+
interface EntitySliceArgs<T, Id extends EntityId> {
3841
name: string
3942
selectId: IdSelector<T, Id>
40-
modelReducer?: ValidateSliceCaseReducers<EntityState<T, Id>, CaseReducers>
43+
modelReducer?: SliceCaseReducers<T>
4144
}
4245

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

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 '../models'
2-
import { createEntityAdapter } from '../create_adapter'
1+
import type { EntityAdapter } from '../index'
2+
import { createEntityAdapter } from '../index'
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 '../models'
2-
import { createEntityAdapter } from '../create_adapter'
1+
import type { EntityAdapter } from '../index'
2+
import { createEntityAdapter } from '../index'
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 '../models'
3-
import { createEntityAdapter } from '../create_adapter'
2+
import type { EntityAdapter, EntityState } from '../index'
3+
import { createEntityAdapter } from '../index'
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: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,3 @@ 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)