Skip to content

Commit

Permalink
@Juice10: Add a flag for rrweb generated events
Browse files Browse the repository at this point in the history
Port of @Juice10/record-once-rrweb/commit/0aef9569a7c5eabe167a9abc8aecf8fd5987bf0a
  • Loading branch information
joris committed Oct 2, 2020
1 parent 0333f38 commit 425a040
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/record/observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ function initInputObserver(
): listenerHandler {
function eventHandler(event: KeyboardEvent) { // was Event
const { target } = event;
const rrwebGenerated = !event.isTrusted;

if (
!target ||
!(target as Element).tagName ||
Expand All @@ -233,7 +235,7 @@ function initInputObserver(
}

if (event.type === 'keyup' && event.key === 'Enter') {
return cbWithDedup(target, { key: 'Enter' });
return cbWithDedup(target, { key: 'Enter', rrwebGenerated });
}

const type: string | undefined = (target as HTMLInputElement).type;
Expand All @@ -255,7 +257,7 @@ function initInputObserver(
) {
text = '*'.repeat(text.length);
}
cbWithDedup(target, { text, isChecked });
cbWithDedup(target, { text, isChecked, rrwebGenerated });
// if a radio was checked
// the other radios with the same name attribute will be unchecked.
const name: string | undefined = (target as HTMLInputElement).name;
Expand All @@ -267,6 +269,7 @@ function initInputObserver(
cbWithDedup(el, {
text: (el as HTMLInputElement).value,
isChecked: !isChecked,
rrwebGenerated: true,
});
}
});
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ export type inputValue = {
text?: string;
isChecked?: boolean;
key?: string;
rrwebGenerated: boolean;
};

export type inputCallback = (v: inputValue & { id: number }) => void;
Expand Down

0 comments on commit 425a040

Please sign in to comment.