Skip to content

Commit 7df80d5

Browse files
committed
pass localised selectors to createSlice
1 parent 3bf655b commit 7df80d5

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,31 +33,27 @@ export const commentSlice = createAppSlice({
3333
builder.addCase(deleteTodo, (state, action) => {
3434
commentAdapter.removeMany(
3535
state,
36-
state.ids.filter(id => state.entities[id]?.todoId === action.payload)
36+
state.ids.filter(id => state.entities[id]?.todoId === action.payload),
3737
)
3838
})
3939
},
4040
selectors: {
41-
selectAllComments: localisedSelectors.selectAll,
42-
selectCommentById: localisedSelectors.selectById,
43-
selectCommentEntities: localisedSelectors.selectEntities,
44-
selectCommentIds: localisedSelectors.selectIds,
45-
selectCommentTotal: localisedSelectors.selectTotal,
41+
...localisedSelectors,
4642
selectCommentsByTodoId: createCommentSliceSelector(
4743
[localisedSelectors.selectAll, (_state, todoId: string) => todoId],
4844
(comments, todoId) =>
49-
comments.filter(comment => comment.todoId === todoId)
45+
comments.filter(comment => comment.todoId === todoId),
5046
),
5147
},
5248
})
5349

5450
export const { addComment, deleteComment } = commentSlice.actions
5551

5652
export const {
57-
selectAllComments,
58-
selectCommentById,
59-
selectCommentEntities,
60-
selectCommentIds,
61-
selectCommentTotal,
53+
selectAll: selectAllComments,
54+
selectById: selectCommentById,
55+
selectEntities: selectCommentEntities,
56+
selectIds: selectCommentIds,
57+
selectTotal: selectCommentTotal,
6258
selectCommentsByTodoId,
6359
} = commentSlice.selectors

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { createEntityAdapter, nanoid } from "@reduxjs/toolkit"
22
import { createAppSlice } from "../../app/createAppSlice"
3-
import type { RootState } from "../../app/store"
43

54
export interface Todo {
65
id: string
@@ -21,6 +20,9 @@ export const todoSlice = createAppSlice({
2120
},
2221
deleteTodo: todoAdapter.removeOne,
2322
},
23+
selectors: {
24+
...todoAdapter.getSelectors(),
25+
},
2426
})
2527

2628
export const { addTodo, deleteTodo } = todoSlice.actions
@@ -31,4 +33,4 @@ export const {
3133
selectEntities: selectTodoEntities,
3234
selectIds: selectTodoIds,
3335
selectTotal: selectTodoTotal,
34-
} = todoAdapter.getSelectors((state: RootState) => todoSlice.selectSlice(state))
36+
} = todoSlice.selectors

0 commit comments

Comments
 (0)