While this reads fine:
const addOneListener = memoize(addListener, {
cacheKey: arguments_ => arguments_,
cache: new ManyKeysMap()
});
This is bad practice:
const addOneListener = memoize(() => {
// some
// inline
// long
// function
// which
// is not
// uncommon
return stuff
}), {
cacheKey: arguments_ => arguments_,
cache: new ManyKeysMap()
});
This could be enforced by a linter, since APIs like addEventListener(string, cb, options)
exist natively, but ideally memoize
and p-memoize
should accept a single parameter:
function memoize(details: Callback | Options) {
const {callback, ...options} = typeof details === 'function' ? {callback: details} : details;
}
It complicates types a bit but it requires the much cleaner:
const addOneListener = memoize({
cacheKey: arguments_ => arguments_,
cache: new ManyKeysMap(),
callback: () => {
// some
// inline
// long
// function
// which
// is not
// uncommon
return stuff
}),
});
Personal note: I went through this recently in webext-storage-cache, changing (fn, opts) => {}
to (fnOrOpts) => {}
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too