I have recently got stucked at a place where I want to call a function that is accessing the store values inside a selector.
So the scenario is something like this, inside a selector I'm having some initial values but during a particular functionality I want to update the selector response with some extra attributes which I'm getting from a function. So that, at the end I got the initial values with some modifications, is it possible and how should we approach the problem?
Will be providing code snippet of the selector, function
In the selectOngoingFee selector I want to call constructData function and for a special condition I need the selector to manipulate the returnObj. I couldn't show you the exact implementation, actually I was stuck at the very first step so if I get to know how I can I call constructData and pass store in that will be very helpful.
selectAccountFeeRate is another selector which gives the result as {
aofValue: {
pensionFee: {
amount: '7',
type: 'AOF',
taxIncluded: 'NO'
}
}
}
const constructData = (store, accountNumber) => {
const pensionSavingAOF = selectAccountFeeRate(state, accountNumber) || {}
const pensionSavingData = {
fees: [{
feeType: 'AOF',
value: pensionSavingAOF.aofValue.pensionFee.amount,
isVatIncluded: pensionSavingAOF.aofValue.pensionFee.taxIncluded === YES
}]
}
return {
pensionSaving: pensionSavingData
}
}
const selectOngoingFee = createSelector([selectRetrievedQuoteDetails], (quoteDetails)) => {
const {
ongoingFee
} = quoteDetails || {}
const pensionSaving = {
fees: []
}
if (!isEmpty(ongoingFee)) {
ongoingFee.forEach((item) => {
const data = {
feeType: 'AOF',
value: item.amount,
isVatIncluded: item.taxIncluded
}
if (item.accountType === 'PENSION_SAVING_ACCOUNT') {
pensionSaving.fees.push(data)
}
})
}
const returnObj = {
...(pensionSaving.fees.length ? {
pensionSaving
} : {})
}
return returnObj
}
Although I have asked this question but after reading a lot of data. I came to know that the only way is to create another function, pass the constructData and select OngoingFee as arguments and manipulate it. Hope my understanding is correct here.