Comments (4)
In a lot of cases it's probably more straightforward to just use a function that determines the cache key for a given element.
Eh, it's kind of nuanced. I don't have any usage stats to support this, but I imagine that the common case is that the objects in the array are immutable. When that's the case, keying the elements doesn't achieve much, since most elements stay referentially equal across calls.
Not that I'm shutting this down, just discussing. Here's a proof of concept that I think would work.
export const keyedArrayMemoize = (fn, {equalityCheck, keyBy}) =>
memoizeMap(fn, {
unique: true,
equalityCheck,
mapper(rows, callback) {
return rows.map(v => callback(keyBy(v), v));
}
});
from reselect-map.
Yeah that's a good point.
I came to this library from code I had written to manually instantiate and apply a rather complex selector to each value in an array, and I get some benefit from applying the previous selector for a given key if the value for that key changed but none of its contents relevant to the selector changed (assuming a way to create a custom selector for each key were provided by this library).
However, after converting that selector to an unmemoized function and using it with reselect-map
, I don't seem to have any performance problems, so it's debatable whether it's worth the extra complexity in most cases.
from reselect-map.
Yeah, composition with caching is hard in general. I'll leave this issue open in case anyone else is interested in a similar thing, but probably won't move forward since the current code handles the common case well enough.
from reselect-map.
Actually I like zero open issues ahahahahahahahahahahahaha
from reselect-map.
Related Issues (12)
- Complex transformations HOT 8
- Customizing the selector created for each element HOT 1
- Running into issues trying out the examples HOT 6
- createListSelector and createMapSelector are missing from typescript definitions HOT 2
- Is there any way to customize the equalityCheck? HOT 1
- missing typings for memorize functions
- Add array index as a final argument to createArraySelector combiner HOT 4
- How does memoization work? HOT 5
- Including the key in the mapper function HOT 12
- Incorrect peer dependency HOT 1
- Add typescript type definition file HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reselect-map.