Hi javascript coders!,
I have some code that I have been trying to figure out. It is basically an application in d3 that colours the map of a country based on data and according to some chosen threshold. A program is said to be written in particular pattern which is said to be:
//program pattern
const compose = (...fns) => (arg) =>
fns.reduce((composed, f) => f(composed), arg)
Also this compose function is used in the main function of a file
var drawMap = (categoryName, subCategory, subSubCategory, colorFunction=defaultColorFunction) => {
var getArrayOfCategory = getArrayOfCategoryByName(categoryName),
colorArrayBuilder = createColorArrayBuilder(colorFunction),
d3SvgMap = d3.select("svg#svg2"),
colorMap = createColorMap(d3SvgMap),
hoverTipString = subSubCategory + " " + subCategory.toLowerCase(),
hoverEffects = addHoverEffects(d3SvgMap)(hoverTipString),
currentRenderArray = getCurrentRenderArray(C.defaultMainCategory, subCategory, subSubCategory),
d3SvgPyramid = d3.select("svg#"+C.pyramidSvgId),
pyramidChart = drawPyramidChart(d3SvgPyramid),
handler = compose(
currentRenderArray,
hoverEffects,
colorArrayBuilder,
pyramidChart,
colorMap
)
getArrayOfCategory(handler)
}
Can anybody explain this pattern to me like in simple words and tell me what the purpose of the handler function is in drawMap.
Im really stuck to understand this so any help would be apreciated.
Thank in advance
Aucun commentaire:
Enregistrer un commentaire