I have a selector that returns an array. The elements in the array themselves have derived data. I essentially need a recursive memoization selector that returns a derived array composed of derived elements.
my current attempt is:
export const selectEntitesWithAssetBuffers = createSelector(
[selectSceneEntities, getAssets],
(entities, loadedAssets) => {
return entities.map((entity) => {
entity.buffers = entity.assets.map((assetName) => {
return loadedAssets[assetName].arrayBuffer;
})
return entity;
})
}
)
My concerns here are anytime entities
or loadedAssets
change this will recompute the entire list. What I'm expecting to setup is something like a selectEntityWithBuffer
that would get passed to the entities.map
. Ideally, I want this to only recompute when an entity.assets
array changes.
Reselect allows you to provide custom equality definitions to your selectors.
Now you can use this new
selectSceneEntitiesByAssetsComparator
in place of the previousselectSceneEntities
in the above code you provided and it will only re-run when the equality check incompareByAssets
fails.Feel free to further update that comparator function if a strict comparison of
assets === assets
doesn't suite your needs.