medikoo / memoizee

Complete memoize/cache solution for JavaScript
ISC License
1.73k stars 61 forks source link

Resolver result is incorrectly passed to function #56

Closed moeriki closed 8 years ago

moeriki commented 8 years ago

Since the 0.3.10 update my memoized function incorrectly returns the result of the resolver instead of passing on the input.

My simplified code.

const memoized = (func) =>
  memoizee(func, {
    resolvers: [(params) => JSON.stringify(params)],
  })

function queryResource(params) {
  console.log(typeof params, params)
}

const query = memoized(queryResource)

query({ limit: 10 })

Expected

object { limit: 10 } 

Actual

string "{ limit: 10 }"

I understand from the commits that a bug in the resolvers has been fixed. Should I update the implementation of my resolver or would this be a regression?

medikoo commented 8 years ago

@Moeriki Yes unfortunately you relied on bug in previous versions.. Resolvers are supposed to normalize the argument which is then passed in resolved form to memoized function.

What you probably wanted to use was normalize option. Unfortunately it's not documented well yet, for now see explanation here

I'm closing it, but if still there's something clear please let me know.

moeriki commented 8 years ago

I suspected something like this :) Thanks for the clarification. I updated my code.

const memoized = (func) =>
  memoize(func, {
    normalizer: ([params]) => JSON.stringify(params),
  })