medikoo / memoizee

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

`resolvers` are called inconsistently #52

Closed seansfkelley closed 8 years ago

seansfkelley commented 8 years ago

Depending on the length of resolvers, they may or may not be called before passing the results to the wrapped function:

> m = require('memoizee')
[Function]
// 1-arg, 1-resolver
> m(function(arg) { console.log('arguments:', arg); }, { resolvers: [ () => 'foo' ] })('a')
arguments: a
undefined
// 2-arg, 2-resolver
> m(function(arg1, arg2) { console.log('arguments:', arg1, arg2); }, { resolvers: [ () => 'foo', () => 'bar' ] })('a', 'b')
arguments: foo bar
undefined
// 1-arg, 2-resolver
> m(function(arg) { console.log('arguments:', arg); }, { resolvers: [ () => 'foo', () => 'bar' ] })('a')
arguments: foo
undefined

The docs are a little unclear on the exact semantics of resolvers, but I take it to mean that the wrapped function should never receive the output of resolvers as it is here.

medikoo commented 8 years ago

@seanohollaren Firstly, sorry for replying that late, Github notifications failed for me, and it's today I noticed that issue.

What you describe was result of ugly bug. Fixed with https://github.com/medikoo/memoizee/commit/9f86b198f993c0e2469fb8cf151ce5baf09ddadd Published as v0.3.10

Thank you!