Skip to content

Commit

Permalink
Debouncing resize event (#566)
Browse files Browse the repository at this point in the history
* Debouncing resize event
  • Loading branch information
AbdelrhmanMagdy authored Nov 5, 2024
1 parent f6eb23e commit 6c2de87
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"packages": [
"packages/*"
],
"version": "0.7.55",
"version": "0.7.56",
"npmClient": "yarn",
"useWorkspaces": true
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "clarity",
"private": true,
"version": "0.7.55",
"version": "0.7.56",
"repository": "https://github.com/microsoft/clarity.git",
"author": "Sarvesh Nagpal <[email protected]>",
"license": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions packages/clarity-decode/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "clarity-decode",
"version": "0.7.55",
"version": "0.7.56",
"description": "An analytics library that uses web page interactions to generate aggregated insights",
"author": "Microsoft Corp.",
"license": "MIT",
Expand All @@ -26,7 +26,7 @@
"url": "https://github.com/Microsoft/clarity/issues"
},
"dependencies": {
"clarity-js": "^0.7.55"
"clarity-js": "^0.7.56"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^24.0.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/clarity-devtools/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "clarity-devtools",
"version": "0.7.55",
"version": "0.7.56",
"private": true,
"description": "Adds Clarity debugging support to browser devtools",
"author": "Microsoft Corp.",
Expand All @@ -24,9 +24,9 @@
"url": "https://github.com/Microsoft/clarity/issues"
},
"dependencies": {
"clarity-decode": "^0.7.55",
"clarity-js": "^0.7.55",
"clarity-visualize": "^0.7.55"
"clarity-decode": "^0.7.56",
"clarity-js": "^0.7.56",
"clarity-visualize": "^0.7.56"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/clarity-devtools/static/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"manifest_version": 2,
"name": "Microsoft Clarity Developer Tools",
"description": "Clarity helps you understand how users are interacting with your website.",
"version": "0.7.55",
"version_name": "0.7.55",
"version": "0.7.56",
"version_name": "0.7.56",
"minimum_chrome_version": "50",
"devtools_page": "devtools.html",
"icons": {
Expand Down
2 changes: 1 addition & 1 deletion packages/clarity-js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "clarity-js",
"version": "0.7.55",
"version": "0.7.56",
"description": "An analytics library that uses web page interactions to generate aggregated insights",
"author": "Microsoft Corp.",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/clarity-js/src/core/version.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
let version = "0.7.55";
let version = "0.7.56";
export default version;
13 changes: 11 additions & 2 deletions packages/clarity-js/src/interaction/resize.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { Event } from "@clarity-types/data";
import { ResizeData } from "@clarity-types/interaction";
import { ResizeData, Setting } from "@clarity-types/interaction";
import { clearTimeout, setTimeout } from "@src/core/timeout";
import { bind } from "@src/core/event";
import encode from "./encode";
import { schedule } from "@src/core/task";

export let data: ResizeData;
let timeout: number = null;

export function start(): void {
bind(window, "resize", recompute);
Expand All @@ -18,11 +21,17 @@ function recompute(): void {
width: de && "clientWidth" in de ? Math.min(de.clientWidth, window.innerWidth) : window.innerWidth,
height: de && "clientHeight" in de ? Math.min(de.clientHeight, window.innerHeight) : window.innerHeight,
};
encode(Event.Resize);
clearTimeout(timeout);
timeout = setTimeout(process, Setting.LookAhead, Event.Resize);
}

function process(event: Event): void {
schedule(encode.bind(this, event));
}

export function reset(): void {
data = null;
clearTimeout(timeout);
}

export function stop(): void {
Expand Down
4 changes: 2 additions & 2 deletions packages/clarity-visualize/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "clarity-visualize",
"version": "0.7.55",
"version": "0.7.56",
"description": "An analytics library that uses web page interactions to generate aggregated insights",
"author": "Microsoft Corp.",
"license": "MIT",
Expand All @@ -27,7 +27,7 @@
"url": "https://github.com/Microsoft/clarity/issues"
},
"dependencies": {
"clarity-decode": "^0.7.55"
"clarity-decode": "^0.7.56"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^24.0.0",
Expand Down

0 comments on commit 6c2de87

Please sign in to comment.