Created
July 8, 2018 06:51
-
-
Save sharvit/bd8ed40f9d1d7a2ed74b2bb572876e23 to your computer and use it in GitHub Desktop.
redux selectors naming conventions
This file contains hidden or 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
/* | |
FactChartHelpers.js | |
*/ | |
export const createHostCounterFromFactChartData = (chartData = []) => | |
chartData.length > 0 | |
? chartData | |
.map(item => item[1]) | |
.reduce((accumulator, currentValue) => accumulator + currentValue) | |
: 0; |
This file contains hidden or 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
/* | |
FactChartSelectors.js | |
*/ | |
import { createSelector } from 'reselect'; | |
import { createHostCounterFromFactChartData } from './FactChartHelpers'; | |
export const selectFactChart = state => state.factChart; | |
export const selectFactChartData = createSelector( | |
selectFactChart, | |
factChart => factChart.chartData, | |
); | |
export const selectFactChartHostCounter = createSelector( | |
selectFactChartData, | |
chartData => createHostCounterFromFactChartData(chartData), | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment