Skip to content

Commit

Permalink
fixed Vite hot reload
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentpayot committed Mar 1, 2024
1 parent 0de1825 commit b606a2f
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions minidenticons.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,26 @@ export function minidenticon(seed="", saturation=DEFAULT_SATURATION, lightness=D
*/
export const minidenticonSvg =
// declared as a pure function to be tree-shaken by the bundler
/*@__PURE__*/globalThis.customElements?.define('minidenticon-svg',
class MinidenticonSvg extends HTMLElement {
static observedAttributes = ['username', 'saturation', 'lightness']
// private fields to allow Terser mangling
static #memoized = {}
#isConnected = false
connectedCallback() {
this.#setContent()
this.#isConnected = true
/*@__PURE__*/globalThis.customElements?.get('minidenticon-svg') ? null :
globalThis.customElements?.define('minidenticon-svg',
class MinidenticonSvg extends HTMLElement {
static observedAttributes = ['username', 'saturation', 'lightness']
// private fields to allow Terser mangling
static #memoized = {}
#isConnected = false
connectedCallback() {
this.#setContent()
this.#isConnected = true
}
// attributeChangedCallback() is called for every observed attribute before connectedCallback()
attributeChangedCallback() { if (this.#isConnected) this.#setContent() }
#setContent() {
const args = MinidenticonSvg.observedAttributes
.map(key => this.getAttribute(key) || undefined)
const memoKey = args.join(',')
this.innerHTML = MinidenticonSvg.#memoized[memoKey] ??=
// @ts-ignore
minidenticon(...args)
}
}
// attributeChangedCallback() is called for every observed attribute before connectedCallback()
attributeChangedCallback() { if (this.#isConnected) this.#setContent() }
#setContent() {
const args = MinidenticonSvg.observedAttributes
.map(key => this.getAttribute(key) || undefined)
const memoKey = args.join(',')
this.innerHTML = MinidenticonSvg.#memoized[memoKey] ??=
// @ts-ignore
minidenticon(...args)
}
}
)
)

0 comments on commit b606a2f

Please sign in to comment.