Created
December 26, 2018 19:06
-
-
Save bjankord/44a25736cb37fdfe34462c87fdd8131b to your computer and use it in GitHub Desktop.
memoized-custom-properties-check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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