Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date selector always recalculated although Date only changes every 15 mins #122

Closed
pke opened this issue Apr 28, 2016 · 3 comments
Closed

Comments

@pke
Copy link

pke commented Apr 28, 2016

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 ===?

@ellbee
Copy link
Collaborator

ellbee commented Apr 28, 2016

The default equality check is ===

@pke
Copy link
Author

pke commented Apr 28, 2016

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()
)

@pke
Copy link
Author

pke commented Apr 28, 2016

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
)

@pke pke closed this as completed Apr 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants