Skip to content

Instantly share code, notes, and snippets.

@lusan
Created March 18, 2017 10:44
Show Gist options
  • Save lusan/7b6ed2bc0d41e9e7a6004e879c7ec4e8 to your computer and use it in GitHub Desktop.
Save lusan/7b6ed2bc0d41e9e7a6004e879c7ec4e8 to your computer and use it in GitHub Desktop.
/*
This piece has been taken from React.js Conf 2015 - Immutable Data and React
*/
function memoize(fn) {
var prevArg;
var prevResult;
return function(arg) {
return arg === prevArg ?
prevResult :
(prevArg = arg,
prevResult = fn.call(this, arg));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment