warns if wrapped function is not memoized
npm install --save warn-if-not-memoized
var warnIfNotMemoized = require('warn-if-not-memoized')
Returns a wrapper for fn
that will log a warning if successive calls to fn
return values that are !==
but are
deeply equal according to options.isEqual
(which defaults to lodash.isequal
).
The wrapper will return its previous return value if it is deeply equal to the next value fn
returns.
isEqual
((a: any, b: any) => boolean
): returnstrue
ifa
andb
are deeply equal (default:lodash.isequal
)logError
((message: string) => any
): logs the warning message (default:console.error
)functionName
(string
): the name of the function to use in the warning messagecreateWarningMessage
((info: {functionName: ?string, arguments: Array<any>, returnValue: any, prevReturnValue: any}) => string
): creates a warning message whenfn
is determined to be not memoized.
Set warnIfNotMemoized.bypass = true
in production to make warnIfNotMemoized
return fn
without wrapping it.
These are the global defaults for options
. The actual values warnIfNotMemoized
uses are:
require('lodash.defaults')({}, options, warnIfNotMemoized.defaultOptions)