From ffa890dfd2d77f94b7cf88408b52c9a9b0dbdb67 Mon Sep 17 00:00:00 2001 From: Dave Lockhart Date: Thu, 24 Jan 2019 10:52:24 -0500 Subject: [PATCH] querySelector is faster than innerHTML --- d2l-icon.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/d2l-icon.js b/d2l-icon.js index d1f14c7..a996670 100644 --- a/d2l-icon.js +++ b/d2l-icon.js @@ -65,7 +65,7 @@ $_documentContainer.innerHTML = ` } - + `; document.head.appendChild($_documentContainer.content); @@ -105,7 +105,11 @@ Polymer({ _iconChanged: function(icon) { var parts = (icon || '').split(':'); - this._iconName = parts.pop(); + var iconName = parts.pop(); + if (iconName !== this._iconName) { + this._d2lIconName = undefined; + } + this._iconName = iconName; this._iconsetName = parts.pop() || this._DEFAULT_ICONSET; this._updateIcon(); }, @@ -127,9 +131,11 @@ Polymer({ this._iconset = /** @type {?Polymer.Iconset} */ ( this._meta.byKey(this._iconsetName)); if (this._iconset) { - var d2lIcon = this._iconset.innerHTML.indexOf(`d2l-icon-${this._iconName}`) > -1; - var iconName = d2lIcon ? (`d2l-icon-${this._iconName}`) : this._iconName; - this._iconset.applyIcon(this, iconName, this.theme); + if (!this._d2lIconName) { + this._d2lIconName = this._iconset.querySelector(`#d2l-icon-${this._iconName}`) ? + (`d2l-icon-${this._iconName}`) : this._iconName; + } + this._iconset.applyIcon(this, this._d2lIconName, this.theme); this.unlisten(window, 'iron-iconset-added', '_updateIcon'); } else { this.listen(window, 'iron-iconset-added', '_updateIcon');