Skip to content

Commit 0c32773

Browse files
committed
ensure reselect 5.1 and demo .withTypes
1 parent 77f4f95 commit 0c32773

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

examples/lazy-injection/kitchen-sink/src/features/todos/commentSlice.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { EntityState } from "@reduxjs/toolkit"
21
import { createEntityAdapter, createSelector, nanoid } from "@reduxjs/toolkit"
32
import { createAppSlice } from "../../app/createAppSlice"
43
import { deleteTodo } from "./todoSlice"
@@ -13,9 +12,14 @@ export const commentAdapter = createEntityAdapter<Comment>()
1312

1413
const localisedSelectors = commentAdapter.getSelectors()
1514

15+
const initialState = commentAdapter.getInitialState()
16+
17+
const createCommentSliceSelector =
18+
createSelector.withTypes<typeof initialState>()
19+
1620
export const commentSlice = createAppSlice({
1721
name: "comments",
18-
initialState: commentAdapter.getInitialState(),
22+
initialState,
1923
reducers: {
2024
addComment: {
2125
reducer: commentAdapter.setOne,
@@ -29,7 +33,7 @@ export const commentSlice = createAppSlice({
2933
builder.addCase(deleteTodo, (state, action) => {
3034
commentAdapter.removeMany(
3135
state,
32-
state.ids.filter(id => state.entities[id]?.todoId === action.payload),
36+
state.ids.filter(id => state.entities[id]?.todoId === action.payload)
3337
)
3438
})
3539
},
@@ -39,11 +43,10 @@ export const commentSlice = createAppSlice({
3943
selectCommentEntities: localisedSelectors.selectEntities,
4044
selectCommentIds: localisedSelectors.selectIds,
4145
selectCommentTotal: localisedSelectors.selectTotal,
42-
selectCommentsByTodoId: createSelector(
43-
localisedSelectors.selectAll,
44-
(_state: EntityState<Comment, string>, todoId: string) => todoId,
46+
selectCommentsByTodoId: createCommentSliceSelector(
47+
[localisedSelectors.selectAll, (_state, todoId: string) => todoId],
4548
(comments, todoId) =>
46-
comments.filter(comment => comment.todoId === todoId),
49+
comments.filter(comment => comment.todoId === todoId)
4750
),
4851
},
4952
})

yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26954,9 +26954,9 @@ fsevents@^1.2.7:
2695426954
linkType: hard
2695526955

2695626956
"reselect@npm:^5.0.1":
26957-
version: 5.0.1
26958-
resolution: "reselect@npm:5.0.1"
26959-
checksum: 7663b4c28a0e908e74dc25262e1d813d028b9c2ee96160cb0f40a16f09c5ac632fa16af6bafede7eb0ff16ab2d5bea2cd8814d9a9488e0262b8317fef90b1dc0
26957+
version: 5.1.0
26958+
resolution: "reselect@npm:5.1.0"
26959+
checksum: 5bc9c5d03d7caea00d0c0e24330bf23d91801227346fec1cef6a60988ab8d3dd7cee76e6994ca0915bc1c20845bb2bd929b95753763e0a9db74c0f9dff5cb845
2696026960
languageName: node
2696126961
linkType: hard
2696226962

0 commit comments

Comments
 (0)