Skip to content

Commit

Permalink
typescript width
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Dec 1, 2023
1 parent eaca753 commit 6b160e6
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/client/width.js → src/client/width.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Override the width definition to use main instead of body (and also use a
// ResizeObserver instead of listening for window resize events).
export function width({Generators}) {
return Generators.observe((notify) => {
let width;
return Generators.observe((notify: (width: number) => void) => {
let width: number;
const observer = new ResizeObserver(([entry]) => {
const w = entry.contentRect.width;
if (w !== width) notify((width = w));
});
observer.observe(document.querySelector("main"));
observer.observe(document.querySelector<HTMLElement>("main")!);
return () => observer.disconnect();
});
}

0 comments on commit 6b160e6

Please sign in to comment.