From 2ac86346076210eb757c796abccae473a1ece9e8 Mon Sep 17 00:00:00 2001 From: Yanzhen Yu Date: Wed, 1 Apr 2026 12:00:00 +0800 Subject: [PATCH] re-add addCustomEvent function via function property --- src/index.ts | 5 ++++- src/record/index.ts | 30 +++++++++++++++--------------- typings/index.d.ts | 3 ++- typings/record/index.d.ts | 4 +++- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/index.ts b/src/index.ts index ccc0e8e8..2aa2e0ad 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -import record, { addCustomEvent } from './record'; +import record from './record'; import { Replayer } from './replay'; import { mirror } from './utils'; @@ -8,4 +8,7 @@ export { MouseInteractions, ReplayerEvents, } from './types'; + +const { addCustomEvent } = record; + export { record, addCustomEvent, Replayer, mirror }; diff --git a/src/record/index.ts b/src/record/index.ts index 3d1dd7fa..c769a4d4 100644 --- a/src/record/index.ts +++ b/src/record/index.ts @@ -25,21 +25,6 @@ function wrapEvent(e: event): eventWithTime { let wrappedEmit!: (e: eventWithTime, isCheckout?: boolean) => void; -export function addCustomEvent(tag: string, payload: T) { - if (!wrappedEmit) { - throw new Error('please add custom event after start recording'); - } - wrappedEmit( - wrapEvent({ - type: EventType.Custom, - data: { - tag, - payload, - }, - }), - ); -} - function record(options: recordOptions = {}): listenerHandler | undefined { const { emit, @@ -228,4 +213,19 @@ function record(options: recordOptions = {}): listenerHandler | undefined { } } +record.addCustomEvent = (tag: string, payload: T) => { + if (!wrappedEmit) { + throw new Error('please add custom event after start recording'); + } + wrappedEmit( + wrapEvent({ + type: EventType.Custom, + data: { + tag, + payload, + }, + }), + ); +}; + export default record; diff --git a/typings/index.d.ts b/typings/index.d.ts index a378a656..2a3d0900 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1,5 +1,6 @@ -import record, { addCustomEvent } from './record'; +import record from './record'; import { Replayer } from './replay'; import { mirror } from './utils'; export { EventType, IncrementalSource, MouseInteractions, ReplayerEvents, } from './types'; +declare const addCustomEvent: (tag: string, payload: T) => void; export { record, addCustomEvent, Replayer, mirror }; diff --git a/typings/record/index.d.ts b/typings/record/index.d.ts index acf2d9f4..c5c7b4a8 100644 --- a/typings/record/index.d.ts +++ b/typings/record/index.d.ts @@ -1,4 +1,6 @@ import { recordOptions, listenerHandler } from '../types'; -export declare function addCustomEvent(tag: string, payload: T): void; declare function record(options?: recordOptions): listenerHandler | undefined; +declare namespace record { + var addCustomEvent: (tag: string, payload: T) => void; +} export default record;