Skip to content

Commit

Permalink
🏷️ [RUMF-1267] rename a few Record-related types
Browse files Browse the repository at this point in the history
* It is a bit unusual to have *Param types. Those suffixes have been
  removed
* MouseInteractions and MediaInteractions enums have been renamed to
  MouseInteractionType and MediaInteractionType to be a bit more
  conventional.
* ViewportResizeDimention have been renamed to ViewportResizeDimension
  • Loading branch information
BenoitZugmeyer committed May 30, 2022
1 parent 96d5f36 commit 2b97076
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 35 deletions.
26 changes: 13 additions & 13 deletions packages/rum/src/domain/record/observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
noop,
} from '@datadog/browser-core'
import { NodePrivacyLevel } from '../../constants'
import type { InputState, MousePosition, MouseInteractionParam } from '../../types'
import { IncrementalSource, MediaInteractions, MouseInteractions } from '../../types'
import type { InputState, MousePosition, MouseInteraction } from '../../types'
import { IncrementalSource, MediaInteractionType, MouseInteractionType } from '../../types'
import { getNodePrivacyLevel, shouldMaskNode } from './privacy'
import { getElementInputValue, getSerializedNodeId, hasSerializedNode } from './serializationUtils'
import type {
Expand Down Expand Up @@ -113,15 +113,15 @@ function initMoveObserver(cb: MousemoveCallBack): ListenerHandler {
}

const eventTypeToMouseInteraction = {
[DOM_EVENT.MOUSE_UP]: MouseInteractions.MouseUp,
[DOM_EVENT.MOUSE_DOWN]: MouseInteractions.MouseDown,
[DOM_EVENT.CLICK]: MouseInteractions.Click,
[DOM_EVENT.CONTEXT_MENU]: MouseInteractions.ContextMenu,
[DOM_EVENT.DBL_CLICK]: MouseInteractions.DblClick,
[DOM_EVENT.FOCUS]: MouseInteractions.Focus,
[DOM_EVENT.BLUR]: MouseInteractions.Blur,
[DOM_EVENT.TOUCH_START]: MouseInteractions.TouchStart,
[DOM_EVENT.TOUCH_END]: MouseInteractions.TouchEnd,
[DOM_EVENT.MOUSE_UP]: MouseInteractionType.MouseUp,
[DOM_EVENT.MOUSE_DOWN]: MouseInteractionType.MouseDown,
[DOM_EVENT.CLICK]: MouseInteractionType.Click,
[DOM_EVENT.CONTEXT_MENU]: MouseInteractionType.ContextMenu,
[DOM_EVENT.DBL_CLICK]: MouseInteractionType.DblClick,
[DOM_EVENT.FOCUS]: MouseInteractionType.Focus,
[DOM_EVENT.BLUR]: MouseInteractionType.Blur,
[DOM_EVENT.TOUCH_START]: MouseInteractionType.TouchStart,
[DOM_EVENT.TOUCH_END]: MouseInteractionType.TouchEnd,
}
function initMouseInteractionObserver(
cb: MouseInteractionCallBack,
Expand All @@ -133,7 +133,7 @@ function initMouseInteractionObserver(
return
}
const { clientX, clientY } = isTouchEvent(event) ? event.changedTouches[0] : event
const position: MouseInteractionParam = {
const position: MouseInteraction = {
id: getSerializedNodeId(target),
type: eventTypeToMouseInteraction[event.type as keyof typeof eventTypeToMouseInteraction],
x: clientX,
Expand Down Expand Up @@ -339,7 +339,7 @@ function initMediaInteractionObserver(
}
mediaInteractionCb({
id: getSerializedNodeId(target),
type: event.type === DOM_EVENT.PLAY ? MediaInteractions.Play : MediaInteractions.Pause,
type: event.type === DOM_EVENT.PLAY ? MediaInteractionType.Play : MediaInteractionType.Pause,
})
}
return addEventListeners(document, [DOM_EVENT.PLAY, DOM_EVENT.PAUSE], handler, { capture: true, passive: true }).stop
Expand Down
16 changes: 8 additions & 8 deletions packages/rum/src/domain/record/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import type {
Record,
MousePosition,
IncrementalSource,
MouseInteractionParam,
MouseInteraction,
ScrollPosition,
StyleSheetRuleParam,
ViewportResizeDimention,
MediaInteractionParam,
StyleSheetRule,
ViewportResizeDimension,
MediaInteraction,
MutationPayload,
InputState,
} from '../../types'
Expand Down Expand Up @@ -84,17 +84,17 @@ export type MousemoveCallBack = (
source: typeof IncrementalSource.MouseMove | typeof IncrementalSource.TouchMove
) => void

export type MouseInteractionCallBack = (d: MouseInteractionParam) => void
export type MouseInteractionCallBack = (d: MouseInteraction) => void

export type ScrollCallback = (p: ScrollPosition) => void

export type StyleSheetRuleCallback = (s: StyleSheetRuleParam) => void
export type StyleSheetRuleCallback = (s: StyleSheetRule) => void

export type ViewportResizeCallback = (d: ViewportResizeDimention) => void
export type ViewportResizeCallback = (d: ViewportResizeDimension) => void

export type InputCallback = (v: InputState & { id: number }) => void

export type MediaInteractionCallback = (p: MediaInteractionParam) => void
export type MediaInteractionCallback = (p: MediaInteraction) => void

export type FocusCallback = (data: FocusRecord['data']) => void

Expand Down
28 changes: 14 additions & 14 deletions packages/rum/src/types/record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ export interface MousemoveData {

export type MouseInteractionData = {
source: typeof IncrementalSource.MouseInteraction
} & MouseInteractionParam
} & MouseInteraction

export type ScrollData = {
source: typeof IncrementalSource.Scroll
} & ScrollPosition

export type ViewportResizeData = {
source: typeof IncrementalSource.ViewportResize
} & ViewportResizeDimention
} & ViewportResizeDimension

export type InputData = {
source: typeof IncrementalSource.Input
Expand All @@ -119,11 +119,11 @@ export type InputData = {

export type MediaInteractionData = {
source: typeof IncrementalSource.MediaInteraction
} & MediaInteractionParam
} & MediaInteraction

export type StyleSheetRuleData = {
source: typeof IncrementalSource.StyleSheetRule
} & StyleSheetRuleParam
} & StyleSheetRule

export type IncrementalData =
| MutationData
Expand Down Expand Up @@ -174,14 +174,14 @@ export interface MousePosition {
timeOffset: number
}

export interface MouseInteractionParam {
type: MouseInteractions
export interface MouseInteraction {
type: MouseInteractionType
id: number
x: number
y: number
}

export const MouseInteractions = {
export const MouseInteractionType = {
MouseUp: 0,
MouseDown: 1,
Click: 2,
Expand All @@ -193,30 +193,30 @@ export const MouseInteractions = {
TouchEnd: 9,
} as const

export type MouseInteractions = typeof MouseInteractions[keyof typeof MouseInteractions]
export type MouseInteractionType = typeof MouseInteractionType[keyof typeof MouseInteractionType]

export interface ScrollPosition {
id: number
x: number
y: number
}

export interface ViewportResizeDimention {
export interface ViewportResizeDimension {
width: number
height: number
}

export type InputState = { text: string } | { isChecked: boolean }

export const MediaInteractions = {
export const MediaInteractionType = {
Play: 0,
Pause: 1,
} as const

export type MediaInteractions = typeof MediaInteractions[keyof typeof MediaInteractions]
export type MediaInteractionType = typeof MediaInteractionType[keyof typeof MediaInteractionType]

export interface MediaInteractionParam {
type: MediaInteractions
export interface MediaInteraction {
type: MediaInteractionType
id: number
}

Expand All @@ -229,7 +229,7 @@ export interface StyleSheetDeleteRule {
index: number | number[]
}

export interface StyleSheetRuleParam {
export interface StyleSheetRule {
id: number
removes?: StyleSheetDeleteRule[]
adds?: StyleSheetAddRule[]
Expand Down

0 comments on commit 2b97076

Please sign in to comment.