vanillajs-browser-helpers
Version:
Collection of convenience code snippets (helpers) that aims to make it a little easier to work with vanilla JS in the browser
17 lines (16 loc) • 435 B
JavaScript
let _cache = new WeakMap();
export const resetCache = () => { _cache = new WeakMap(); };
export default function elmData(elm, key, data) {
let elmCache = _cache.get(elm);
if (!key) {
return elmCache;
}
if (data !== undefined) {
if (!elmCache) {
elmCache = {};
_cache.set(elm, elmCache);
}
elmCache[key] = data;
}
return elmCache?.[key];
}