Last active
August 29, 2015 14:25
-
-
Save panuhorsmalahti/3a133e258c4416d8488d to your computer and use it in GitHub Desktop.
Call a function if the parameters differ
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
// Calls 'f' if the parameters are different from the last call. | |
// NOTE: Implement 'notEqual' yourself | |
const changed = f => { | |
let lastParams = undefined, flag = false; | |
return (...args) => { | |
if (!flag || notEqual(lastParams, args)) { | |
f(args); | |
lastParams = args; | |
flag = true | |
} | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment