Giter VIP home page Giter VIP logo

Comments (6)

dankolesnikov avatar dankolesnikov commented on August 21, 2024

@dheera I've faced a similar problem today when solving a data inconsistency bug, what I understand is that this library does not honor dict args however I was able to fix it by providing { length: false } argument like this: export const getData = memoizee(getDataRaw, { length: false });,
This actually caused a pretty big problem for us because we were getting incorrect data.

@medikoo can you please shine some light here? Is this package actively maintained? If I open a PR to fix this would you able to review/approve and rerelease?

from memoizee.

medikoo avatar medikoo commented on August 21, 2024

@dheera @dankolesnikov I'm not sure how I missed this issue (btw, yes this package is maintained). Sorry for responding so late

Yes, currently there's no dedicated option for that, but it can be achieved relatively simply. See: https://github.com/medikoo/memoizee/blob/master/README.md#memoizing-on-dictionary-object-hash-arguments

from memoizee.

dankolesnikov avatar dankolesnikov commented on August 21, 2024

thank you so much for a quick response @medikoo !

  1. I am curious why not support this functionality out of the box? is there a design intention around that?
  2. Could you please explain why does this solution make things work? memoizee(getDataRaw, { length: false });
    The function signature is of getRawData:
const getDataRaw = (effectiveDate: Date, filter: Record<string, any> | Knex.QueryCallback = {}) => {...}

Additionally, @dheera @medikoo I've realized that the cause for my bug stemmed from the fact that filter argument had a default value rather than being an object/dict, if I remove that everything works.

@medikoo The problem I face is that I am dealing with auto-generated code and I don't have good control of the arguments (and their ordering) of the functions I pass into memoizee, hence the solution you linked might not work well normalizer: function(args) { // args is arguments object as accessible in memoized function return JSON.stringify(deepSortedEntries(args[0])); }, here args[0] is problematic for me as I don't know the position of the arguments that's dict.
Refactoring the entire code base to remove the default value is also not realistic but could you please explain why { length: false } makes everything work? That would be the easiest solution for me but it's critical I understand the implications of this parameter. Thank you again!

from memoizee.

medikoo avatar medikoo commented on August 21, 2024

I am curious why not support this functionality out of the box? is there a design intention around that?

I think it might be nice to support it out of the box, but when we speak of well designed generic solution, it may appear it's not trival to implement, e.g. we may want to go beyond JSON, to e.g. support well types as BigInt, etc. or recognise properly non JSON objects in collection (while after JSON stringification they're just cleared).

You've already noticed that plain simple solution as proposed in docs, is too optimistic for your case

So main problems I see is:

  1. It's time taking to make it right (have a well thought general approach).
  2. Current codebase is pretty old, and I'd prefer to refactor it into v1, before adding new functionalities (see: #73)

Could you please explain why does this solution make things work?

Sorry, I don't understand this question

here args[0] is problematic for me as I don't know the position of the arguments that's dict.

In that case I believe you need to normalize against whole args and not just args[0]

from memoizee.

dankolesnikov avatar dankolesnikov commented on August 21, 2024

@medikoo Thank you so much for quick replies!
I've turned export const getData = memoizee(getDataRaw); into export const getData = memoizee(getDataRaw, { length: false }); and it fixed all my problems with dict argument not working correctly but I don't fully understand why, documentation is not very clear. Can you please shine some light on what does { length: false } do under the hood?

from memoizee.

medikoo avatar medikoo commented on August 21, 2024

I've turned export const getData = memoizee(getDataRaw); into export const getData = memoizee(getDataRaw, { length: false }); and it fixed all my problems with dict argument

I see. length: false, changes the approach on what arguments are taken into account when memoizing.

If function signature is (effectiveDate, filter: {}, then memoization is evaluated against only first argument (as function length is 1), with false, memoizer always takes all passed arguments and evaluates on that. It's documented here: https://github.com/medikoo/memoizee#arguments-length

from memoizee.

Related Issues (20)

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.