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

Equivalent implementation of re-reselect for cache-key #579

Open
gamegee opened this issue Jun 16, 2022 · 1 comment
Open

Equivalent implementation of re-reselect for cache-key #579

gamegee opened this issue Jun 16, 2022 · 1 comment

Comments

@gamegee
Copy link

gamegee commented Jun 16, 2022

Hi, this is more a question than a real issue.

I am not sure how I should implement reselect to have the same behavior as re-reselect with the cache-key.

Here is a simple example of a selector that may be used a lot of time in my app, so I want to prevent any re-computation of myExpensiveComputation if the selectBookById has no changed.

In re-reselect

import createCachedSelector from 're-reselect'

const selectBookById = (state, id: string) => state.books[id]
const myExpensiveComputation = () => // stuff

const myCachedSelector = createCachedSelector(
  selectBookById,
  myExpensiveComputation
)((_, id) => id)) // here is the cache key

In reselect 4.1.0

import { createSelector } from 'reselect'

const selectBookById = (state, id: string) => state.books[id]
const myExpensiveComputation = () => // stuff

const myCachedSelector = createSelector(
  selectBookById,
  myExpensiveComputation,
  {
    memoizeOptions: {
      maxSize: 50, // Set size to 50, so if multiple components are connected to the same selector, it will not recompute
    }
  }
)
@aryaemami59
Copy link
Contributor

I believe this one has been resolved by #649, due to weakMapMemoize providing an effectively infinite cache size out of the box.

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