Skip to content

Instantly share code, notes, and snippets.

@bjankord
Created December 26, 2018 19:06
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 bjankord/44a25736cb37fdfe34462c87fdd8131b to your computer and use it in GitHub Desktop.
Save bjankord/44a25736cb37fdfe34462c87fdd8131b to your computer and use it in GitHub Desktop.
memoized-custom-properties-check
/* Didn't notice any perf improvement with memozing this, actually saw a regression
memoized custom property check, may see improvement if called more frequently */
const customPropertyCheck = () => {
let cache = {};
console.log(cache);
return () => {
if ('customProperties' in cache) {
console.log('Fetching from cache');
return cache['customProperties'];
}
else {
console.log('Calculating result');
let result = window.CSS && CSS.supports("color", "var(--color)");
cache['customProperties'] = result;
return result;
}
}
}
const cp = customPropertyCheck();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment