-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from Chamindu36/dev
Add optimizations and memoization with redux to categories context.
- Loading branch information
Showing
9 changed files
with
48 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import CATEGORIES_ACTION_TYPES from './category.types'; | ||
import { createAction } from '../../utils/reducer/reducer.utils'; | ||
|
||
export const setCategoriesMap = (categoriesMap) => | ||
createAction(CATEGORIES_ACTION_TYPES.SET_CATEGORIES_MAP, categoriesMap); | ||
export const setCategories = (categoriesArray) => | ||
createAction(CATEGORIES_ACTION_TYPES.SET_CATEGORIES, categoriesArray); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,17 @@ | ||
export const selectCategoriesMap = (state) => state.categories.categoriesMap; | ||
import { createSelector } from "reselect"; | ||
|
||
const selectCategoryReducer = (state) => state.categories; | ||
|
||
export const selectCategories = createSelector( | ||
[selectCategoryReducer], | ||
(categoriesSlice) => categoriesSlice.categories | ||
); | ||
|
||
export const selectCategoriesMap = createSelector( | ||
[selectCategories], | ||
(categories) => | ||
categories.reduce((acc, { title, items }) => { | ||
acc[title.toLowerCase()] = items; | ||
return acc; | ||
}, {}) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
const CATEGORIES_ACTION_TYPES = { | ||
SET_CATEGORIES_MAP: 'categories/SET_CATEGORIES_MAP', | ||
SET_CATEGORIES: 'categories/SET_CATEGORIES', | ||
}; | ||
|
||
export default CATEGORIES_ACTION_TYPES; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters