diff --git a/package.json b/package.json index 9dceffb..678523b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@antv/util", - "version": "3.3.5", + "version": "3.3.6", "license": "MIT", "sideEffects": false, "main": "lib/index.js", @@ -90,7 +90,6 @@ }, "dependencies": { "fast-deep-equal": "^3.1.3", - "flru": "^1.0.2", "gl-matrix": "^3.3.0", "tslib": "^2.3.1" }, diff --git a/src/lodash/memoize.ts b/src/lodash/memoize.ts index 5b2b430..97a0ef6 100644 --- a/src/lodash/memoize.ts +++ b/src/lodash/memoize.ts @@ -1,6 +1,49 @@ -import flru from 'flru'; import isFunction from './is-function'; +function flru(max: number) { + let num, curr, prev; + const limit = max || 1; + + function keep(key, value) { + if (++num > limit) { + prev = curr; + reset(1); + ++num; + } + curr[key] = value; + } + + function reset(isPartial?: number) { + num = 0; + curr = Object.create(null); + isPartial || (prev = Object.create(null)); + } + + reset(); + + return { + clear: reset, + has: function (key) { + return curr[key] !== void 0 || prev[key] !== void 0; + }, + get: function (key) { + var val = curr[key]; + if (val !== void 0) return val; + if ((val = prev[key]) !== void 0) { + keep(key, val); + return val; + } + }, + set: function (key, value) { + if (curr[key] !== void 0) { + curr[key] = value; + } else { + keep(key, value); + } + }, + }; +} + /** * _.memoize(calColor); * _.memoize(calColor, (...args) => args[0]);