Skip to content

Commit 679cef1

Browse files
committed
wip: promising bug fixes
1 parent 29cce74 commit 679cef1

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

demo/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
const sum = document.createElement('summary');
3030
det.append(sum);
3131
const d = db[tag][hash];
32-
sum.textContent = tag + ' ' + (identity(eDb.h2e.get(hash)) || ' ') + ' (' + hash + ')';
32+
sum.textContent = tag + ' ' + (Array.from(eDb.h2e.get(hash)?.keys()?.map(identity)).join(', ') || ' ') + ' (' + hash + ')';
3333
det.addEventListener('toggle', () => {if (det.children.length < 2) det.append(...display(db[tag][hash]))})
3434
elements.push(det);
3535
}
@@ -93,7 +93,7 @@
9393
const det = document.createElement('details');
9494
const sum = document.createElement('summary');
9595
det.append(sum);
96-
sum.textContent = tag + ' ' + (identity(eDb.h2e.get(hash)) || ' ') + ' (' + hash + ')';
96+
sum.textContent = tag + ' ' + (Array.from(eDb.h2e.get(hash)?.keys()?.map(identity)).join(', ') || ' ') + ' (' + hash + ')';
9797
det.addEventListener('toggle', () => {if (det.children.length < 2) det.append(...display(db[tag][hash]))})
9898
details.append(det);
9999
}

hash.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const attributes: {
5757

5858
interface ElementDB {
5959
e2h: WeakMap<Element, string>;
60-
h2e: Map<string, Element>;
60+
h2e: Map<string, Set<Element>>;
6161
}
6262

6363
export function hasher(
@@ -257,10 +257,9 @@ export function hasher(
257257
const digest = xxh.h64ToString(JSON.stringify(description));
258258
if (!(tag in db)) db[tag] = {};
259259
if (!(digest in db[tag])) db[tag][digest] = description;
260-
if (!eDb.h2e.has(digest)) {
261-
eDb.h2e.set(digest, e);
262-
eDb.e2h.set(e, digest);
263-
}
260+
if (!eDb.h2e.has(digest)) eDb.h2e.set(digest, new Set<Element>().add(e));
261+
else if (!eDb.h2e.get(digest)!.has(e)) eDb.h2e.get(digest)!.add(e);
262+
if (!eDb.e2h.has(e)) eDb.e2h.set(e, digest);
264263
return digest;
265264
}
266265

0 commit comments

Comments
 (0)