Skip to content

Commit 4c5f3b3

Browse files
committed
ref: Keep flat list of pending events
1 parent 23828b2 commit 4c5f3b3

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

packages/replay/src/eventBuffer/EventBufferArray.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ interface EventsGroup {
1313
*/
1414
export class EventBufferArray implements EventBuffer {
1515
private _events: EventsGroup[];
16+
private _eventsFlat: RecordingEvent[];
1617

1718
public constructor() {
1819
this._events = [];
20+
this._eventsFlat = [];
1921
}
2022

2123
/** @inheritdoc */
@@ -25,7 +27,8 @@ export class EventBufferArray implements EventBuffer {
2527

2628
/** @inheritdoc */
2729
public get pendingEvents(): RecordingEvent[] {
28-
return this._events.reduce((acc, { events }) => [...events, ...acc], [] as RecordingEvent[]);
30+
return this._eventsFlat;
31+
// return this._events.reduce((acc, { events }) => [...events, ...acc], [] as RecordingEvent[]);
2932
}
3033

3134
/** @inheritdoc */
@@ -49,14 +52,25 @@ export class EventBufferArray implements EventBuffer {
4952
} else {
5053
this._events[0].events.push(event);
5154
}
55+
56+
this._eventsFlat.push(event);
5257
}
5358

5459
/** @inheritdoc */
5560
public clear(keepLastCheckout?: boolean): void {
5661
if (keepLastCheckout) {
5762
this._events.splice(1);
63+
64+
if (this._events.length === 0) {
65+
this._eventsFlat = [];
66+
} else {
67+
// Remove all events from the flat array that are not in the first group
68+
const firstGroup = this._events[0];
69+
this._eventsFlat = this._eventsFlat.filter(event => firstGroup.events.includes(event));
70+
}
5871
} else {
5972
this._events = [];
73+
this._eventsFlat = [];
6074
}
6175
}
6276

0 commit comments

Comments
 (0)