Skip to content

Commit

Permalink
👌 stop throttle instead of using a boolean
Browse files Browse the repository at this point in the history
  • Loading branch information
bcaudan committed Apr 23, 2020
1 parent 39b8cb3 commit 4b0f454
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions packages/rum/src/viewCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,12 @@ function newView(
userActionCount: 0,
}
let documentVersion = 0
let shouldIgnoreScheduledViewUpdate = false

viewContext = { id, location, sessionId: session.getId() }

// Update the view every time the measures are changing
const { throttled: scheduleViewUpdate } = throttle(
monitor(() => {
if (shouldIgnoreScheduledViewUpdate) {
// The view update may come after the view has ended when the throttled scheduleViewUpdate
// function is called right before ending the view. In this case, we should not send the
// updated view event.
return
}
updateView()
}),
const { throttled: scheduleViewUpdate, stop: stopScheduleViewUpdate } = throttle(
monitor(updateView),
THROTTLE_VIEW_UPDATE_PERIOD,
{
leading: false,
Expand Down Expand Up @@ -121,9 +112,10 @@ function newView(

return {
end() {
shouldIgnoreScheduledViewUpdate = true
stopTimingsTracking()
stopEventCountsTracking()
// prevent pending view updates execution
stopScheduleViewUpdate()
// Make a final view update
updateView()
},
Expand Down

0 comments on commit 4b0f454

Please sign in to comment.