reselect
reselect copied to clipboard
Date selector always recalculated although Date only changes every 15 mins
I have this interval selector:
export const getDateTime = minuteInterval => {
const coeff = 1000 * 60 * minuteInterval
const now = new Date()
return new Date(Math.floor(now.getTime() / coeff) * coeff)
}
export const selectDateTime = () => getDateTime(15)
Other selectors using this as an input keep re-evaluating even in between those 15 minutes the DateTime selector actually changes. How does reselect detect a change? Does it use == or ===?
The default equality check is ===
Hmmm. That would explain it of course. getDateTime(15) == getDateTime(15) but getDateTime(15) !== getDateTime(15)
~~Any idea how to solve this kind of problem?~~ Maybe like this?:
export const selectDateTime = createSelectorCreator(
defaultMomoize,
(a,b) => a.getTime() === b.getTime()
)
This seems to do the trick. Is it ok?
const dateEqualSelector = createSelectorCreator(
defaultMemoize,
(a,b) => {
return a.getTime() === b.getTime()
}
)
const intervalSelector = () => getDateTime(15)
export const selectDateTime = dateEqualSelector(
intervalSelector,
(interval) => interval
)