Skip to content

Commit

Permalink
Request the document lazily
Browse files Browse the repository at this point in the history
  • Loading branch information
sunesimonsen committed Dec 18, 2023
1 parent 98efae9 commit 0049ac9
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,30 @@ class CSSTemplate {
this._content = content;
this._hash = hash;
this._rendered = null;
}

const hashes = getHashes();
get _hashString() {
if (!this.cachedHashString) {
const hashes = getHashes();

while (hashes.has(this._hash) && hashes.get(this._hash) !== content) {
this._hash++;
}
while (
hashes.has(this._hash) &&
hashes.get(this._hash) !== this._content
) {
this._hash++;
}

if (!hashes.has(this._hash)) {
hashes.set(this._hash, this._content);
}

if (!hashes.has(this._hash)) {
hashes.set(this._hash, content);
const hashString = Math.abs(this._hash).toString(16);
this._cachedHashString = hashString.match(/^[0-9]/)
? `c${hashString}`
: hashString;
}

const hashString = Math.abs(this._hash).toString(16);
this._hashString = hashString.match(/^[0-9]/)
? `c${hashString}`
: hashString;
return this._cachedHashString;
}

_render() {
Expand Down

0 comments on commit 0049ac9

Please sign in to comment.