UNPKG

just-animate

Version:
28 lines (27 loc) 771 B
import { _ } from './constants'; export function memoize(func) { const cache = []; return function () { const args = arguments; for (var h = 0, hlen = cache.length; h < hlen; h++) { var keys = cache[h].args; var ilen = args.length; if (keys.length !== ilen) { continue; } var matches = 0; for (var i = 0; i < ilen; i++) { if (keys[i] !== args[i]) { break; } ++matches; } if (matches === ilen) { return cache[h].value; } } var value = func.apply(_, args); cache.push({ args, value }); return value; }; }