Skip to content

Commit

Permalink
Added strict context binding to the debounced function
Browse files Browse the repository at this point in the history
# See - sindresorhus/debounce#8. The debounced function has a strict context comparison that breaks when applied in the resize listener
  • Loading branch information
oleksandr-danylchenko committed Aug 30, 2024
1 parent 6b19a83 commit 3d7e09c
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/text-annotator/src/SelectionHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export const createSelectionHandler = (
// select events don't have offsetX/offsetY - reuse last up/down)
selection.userSelect(currentTarget.annotation, lastPointerDown);
}
}, 10)
}, 10).bind(undefined);

document.addEventListener('selectionchange', onSelectionChange);

Expand Down
2 changes: 1 addition & 1 deletion packages/text-annotator/src/highlight/baseRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export const createBaseRenderer = (
currentPainter.reset();

redraw();
}, 10);
}, 10).bind(undefined);

window.addEventListener('resize', onResize);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const createRenderer = (container: HTMLElement): RendererImplementation => {
});
});

const onResize = debounce(() => resetCanvas(canvas), 10);
const onResize = debounce(() => resetCanvas(canvas), 10).bind(undefined);

window.addEventListener('resize', onResize);

Expand Down

0 comments on commit 3d7e09c

Please sign in to comment.