import { createSelector , createSlice } from '@reduxjs/toolkit' ; import { RootState } from 'app/rootReducer' ; export type Todo = { id : string ; description : string ; isCompleted : boolean ; } ; export type TodosState = { entities : Todo [ ] ; loading : 'idle' | 'pending' ; currentRequestId : string | undefined ; error : any ; } ; const initialState = { entities : [ ] , loading : 'idle' , currentRequestId : undefined , error : null , } ; export const todosSlice = createSlice ( { name : 'todos' , initialState , reducers : { } , extraReducers : ( ) => { } , } ) ; export const selectTodos = ( state ) => state . firestore . ordered . todos ; export const selectTodosCount = createSelector ( selectTodos , ( todos ) => todos . length ) ; export const selectActiveTodosCount = createSelector ( selectTodos , ( todos ) => todos && todos . filter ( ( todo ) => ! todo . isCompleted ) . length ) ; export const selectCompleteTodosCount = createSelector ( selectTodos , ( todos ) => todos && todos . filter ( ( todo ) => todo . isCompleted ) . length ) ; export default todosSlice . reducer ;