Skip to content

Instantly share code, notes, and snippets.

@panuhorsmalahti
Last active August 29, 2015 14:25
Show Gist options
  • Save panuhorsmalahti/3a133e258c4416d8488d to your computer and use it in GitHub Desktop.
Save panuhorsmalahti/3a133e258c4416d8488d to your computer and use it in GitHub Desktop.
Call a function if the parameters differ
// 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