Coder Social home page Coder Social logo

Comments (4)

heyimalex avatar heyimalex commented on May 18, 2024

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.

jedwards1211 avatar jedwards1211 commented on May 18, 2024

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.

heyimalex avatar heyimalex commented on May 18, 2024

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.

heyimalex avatar heyimalex commented on May 18, 2024

Actually I like zero open issues ahahahahahahahahahahahaha

from reselect-map.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.