Created
November 27, 2018 15:49
-
-
Save themouette/d86ebbf341f23ee9c9f32495bea88f0e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const whyIsItRecalculating = ( | |
funcName, | |
...fieldNames | |
) => decoratedFunc => { | |
let prevValues; | |
return (...values) => { | |
// eslint-disable-next-line no-console | |
console.group(`whyIsItRecalculating ${funcName}`); | |
if (prevValues) { | |
if (prevValues.length < values.length) { | |
// eslint-disable-next-line no-console | |
console.log( | |
'received more values than last time: %d vs %d', | |
prevValues.length, | |
values.length | |
); | |
} else if (prevValues.length > values.length) { | |
// eslint-disable-next-line no-console | |
console.log( | |
'received less values than last time: %d vs %d', | |
prevValues.length, | |
values.length | |
); | |
} | |
let i; | |
for (i = 0; i < prevValues.length; i += 1) { | |
if (prevValues[i] !== values[i]) { | |
// eslint-disable-next-line no-console | |
console.log( | |
`Argument ${i} ("${fieldNames[i] || | |
'unknown'}") changed from`, | |
prevValues[i], | |
'to', | |
values[i] | |
); | |
} | |
} | |
} | |
// eslint-disable-next-line no-console | |
console.groupEnd(); | |
prevValues = values; | |
return decoratedFunc(...values); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment