Skip to content

Commit

Permalink
Apply formatting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mydea authored and github-actions[bot] committed Feb 3, 2023
1 parent 66ddc3b commit e5c5f40
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 74 deletions.
6 changes: 5 additions & 1 deletion packages/rrweb/src/record/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ import { IframeManager } from './iframe-manager';
import { ShadowDomManager } from './shadow-dom-manager';
import { CanvasManager } from './observers/canvas/canvas-manager';
import { StylesheetManager } from './stylesheet-manager';
import { callbackWrapper, registerErrorHandler, unregisterErrorHandler } from './errorHandler';
import {
callbackWrapper,
registerErrorHandler,
unregisterErrorHandler,
} from './errorHandler';

function wrapEvent(e: event): eventWithTime {
return {
Expand Down
150 changes: 78 additions & 72 deletions packages/rrweb/src/record/observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,36 +173,38 @@ function initMoveObserver({
),
callbackThreshold,
);
const updatePosition = callbackWrapper(throttle<MouseEvent | TouchEvent | DragEvent>(
callbackWrapper((evt) => {
const target = getEventTarget(evt);
const { clientX, clientY } = isTouchEvent(evt)
? evt.changedTouches[0]
: evt;
if (!timeBaseline) {
timeBaseline = Date.now();
}
positions.push({
x: clientX,
y: clientY,
id: mirror.getId(target as Node),
timeOffset: Date.now() - timeBaseline,
});
// it is possible DragEvent is undefined even on devices
// that support event 'drag'
wrappedCb(
typeof DragEvent !== 'undefined' && evt instanceof DragEvent
? IncrementalSource.Drag
: evt instanceof MouseEvent
? IncrementalSource.MouseMove
: IncrementalSource.TouchMove,
);
}),
threshold,
{
trailing: false,
},
));
const updatePosition = callbackWrapper(
throttle<MouseEvent | TouchEvent | DragEvent>(
callbackWrapper((evt) => {
const target = getEventTarget(evt);
const { clientX, clientY } = isTouchEvent(evt)
? evt.changedTouches[0]
: evt;
if (!timeBaseline) {
timeBaseline = Date.now();
}
positions.push({
x: clientX,
y: clientY,
id: mirror.getId(target as Node),
timeOffset: Date.now() - timeBaseline,
});
// it is possible DragEvent is undefined even on devices
// that support event 'drag'
wrappedCb(
typeof DragEvent !== 'undefined' && evt instanceof DragEvent
? IncrementalSource.Drag
: evt instanceof MouseEvent
? IncrementalSource.MouseMove
: IncrementalSource.TouchMove,
);
}),
threshold,
{
trailing: false,
},
),
);
const handlers = [
on('mousemove', updatePosition, doc),
on('touchmove', updatePosition, doc),
Expand Down Expand Up @@ -281,33 +283,35 @@ export function initScrollObserver({
observerParam,
'scrollCb' | 'doc' | 'mirror' | 'blockClass' | 'blockSelector' | 'sampling'
>): listenerHandler {
const updatePosition = callbackWrapper(throttle<UIEvent>(
callbackWrapper((evt) => {
const target = getEventTarget(evt);
if (
!target ||
isBlocked(target as Node, blockClass, blockSelector, true)
) {
return;
}
const id = mirror.getId(target as Node);
if (target === doc && doc.defaultView) {
const scrollLeftTop = getWindowScroll(doc.defaultView);
scrollCb({
id,
x: scrollLeftTop.left,
y: scrollLeftTop.top,
});
} else {
scrollCb({
id,
x: (target as HTMLElement).scrollLeft,
y: (target as HTMLElement).scrollTop,
});
}
}),
sampling.scroll || 100,
));
const updatePosition = callbackWrapper(
throttle<UIEvent>(
callbackWrapper((evt) => {
const target = getEventTarget(evt);
if (
!target ||
isBlocked(target as Node, blockClass, blockSelector, true)
) {
return;
}
const id = mirror.getId(target as Node);
if (target === doc && doc.defaultView) {
const scrollLeftTop = getWindowScroll(doc.defaultView);
scrollCb({
id,
x: scrollLeftTop.left,
y: scrollLeftTop.top,
});
} else {
scrollCb({
id,
x: (target as HTMLElement).scrollLeft,
y: (target as HTMLElement).scrollTop,
});
}
}),
sampling.scroll || 100,
),
);
return on('scroll', updatePosition, doc);
}

Expand All @@ -316,21 +320,23 @@ function initViewportResizeObserver({
}: observerParam): listenerHandler {
let lastH = -1;
let lastW = -1;
const updateDimension =callbackWrapper(throttle(
callbackWrapper(() => {
const height = getWindowHeight();
const width = getWindowWidth();
if (lastH !== height || lastW !== width) {
viewportResizeCb({
width: Number(width),
height: Number(height),
});
lastH = height;
lastW = width;
}
}),
200,
));
const updateDimension = callbackWrapper(
throttle(
callbackWrapper(() => {
const height = getWindowHeight();
const width = getWindowWidth();
if (lastH !== height || lastW !== width) {
viewportResizeCb({
width: Number(width),
height: Number(height),
});
lastH = height;
lastW = width;
}
}),
200,
),
);
return on('resize', updateDimension, window);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/rrweb/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,4 @@ export type CrossOriginIframeMessageEventContent<T = eventWithTime> = {
};
export type CrossOriginIframeMessageEvent = MessageEvent<CrossOriginIframeMessageEventContent>;

export type ErrorHandler = (error: unknown) => void | boolean;
export type ErrorHandler = (error: unknown) => void | boolean;

0 comments on commit e5c5f40

Please sign in to comment.