-
-
Notifications
You must be signed in to change notification settings - Fork 56
Open
Description
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) => {}
Metadata
Metadata
Assignees
Labels
No labels