Skip to content

Instantly share code, notes, and snippets.

@AutoSponge
Last active January 21, 2016 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AutoSponge/eed990b3f02c523a025f to your computer and use it in GitHub Desktop.
Save AutoSponge/eed990b3f02c523a025f to your computer and use it in GitHub Desktop.
memoize that allows functions and understands context
import {List} from 'immutable'
export default fn => {
const cache = {}
const cacheKey = List()
return function (...args) {
const hashCode = cacheKey.push(this, ...args).hashCode()
if (!(hashCode in cache)) {
cache[hashCode] = fn.apply(this, args)
}
return cache[hashCode]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment