Skip to content

Instantly share code, notes, and snippets.

@gordonbrander
Created September 28, 2023 02:15
Show Gist options
  • Save gordonbrander/4a3f35565390b9edc1c56f7eef21b000 to your computer and use it in GitHub Desktop.
Save gordonbrander/4a3f35565390b9edc1c56f7eef21b000 to your computer and use it in GitHub Desktop.
prop.js - make DOM fast with a write-through cache
// Set property of element.
// Uses a write-through cache to only set
// when value actually changes.
export const prop = (el, key, value) => {
let cacheKey = Symbol.from(`prop.${key}`)
if (el[cacheKey] != value) {
el[cacheKey] = value
el[key] = value
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment