tailwindcss/src/util/useMemo.js
Robin Malfait eac11cf57d
Performance improvements + memory leak fix (#3032)
* fix memory leak

* add optional condition to hasAtRule

* use known tree to handle `@apply` when required `@tailwind` at rules exists

Otherwise we will generate the lookup tree.

* only generate the missing `@tailwind` atrules when using `@apply`

* update perf config to reflect 2.0 changes

* update changelog

* ensure lookup tree is correctly cached based on used tailwind atrules
2020-12-11 15:03:49 +01:00

25 lines
412 B
JavaScript

import { shared } from './disposables'
export function useMemo(cb, keyResolver) {
let cache = new Map()
function clearCache() {
cache.clear()
shared.add(clearCache)
}
shared.add(clearCache)
return (...args) => {
let key = keyResolver(...args)
if (cache.has(key)) {
return cache.get(key)
}
let result = cb(...args)
cache.set(key, result)
return result
}
}