Skip to content

Commit

Permalink
fix: use a Map as the domStylesCache
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Jan 1, 2021
1 parent 89f61c2 commit 108918a
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions lib/dom-styles-reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default class DOMStylesReader {
* The cache object
* @access private
*/
this.domStylesCache = {}
this.domStylesCache = new Map()

/**
* Set to true once tokenized
Expand All @@ -38,16 +38,17 @@ export default class DOMStylesReader {
*/
retrieveStyleFromDom (scopes, property, targetNode, cache = true) {
const key = scopes.join(' ')
let cachedData = this.domStylesCache[key]
let cachedData = this.domStylesCache.get(key)

if (cache && (cachedData ? cachedData[property] : undefined) != null) {
if (cache && (cachedData !== undefined ? cachedData[property] : undefined) != null) {
return cachedData[property]
}

this.ensureDummyNodeExistence(targetNode)

if (!cachedData) {
this.domStylesCache[key] = cachedData = {}
if (cachedData === undefined) {
cachedData = {}
this.domStylesCache.set(key, cachedData)
}

let parent = this.dummyNode
Expand All @@ -69,7 +70,10 @@ export default class DOMStylesReader {
value = rotateHue(value, filter)
}

if (value !== '') { cachedData[property] = value }
if (value !== '') {
cachedData[property] = value
this.domStylesCache.set(key, cachedData)
}

this.dummyNode.innerHTML = ''
return value
Expand Down Expand Up @@ -99,7 +103,7 @@ export default class DOMStylesReader {
* used in MinimapElement
*/
invalidateDOMStylesCache () {
this.domStylesCache = {}
this.domStylesCache.clear()
}

/**
Expand Down

0 comments on commit 108918a

Please sign in to comment.