Skip to content

Commit

Permalink
Refactor the emitting of the lifecycle event
Browse files Browse the repository at this point in the history
We're only ever going to fire the newly received CDP lifecycle event
so there's no need for the for loop to go over all the events that
have already fired and ignore the ones that have already been emitted
to internal handlers.

This should lead us to refactoring out the subtreeLifecycleEvents
as there's no need for it now, it's just a duplicate of
lifecycleEvents.
  • Loading branch information
ankur22 committed Nov 8, 2022
1 parent b50622b commit 8f2b360
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
12 changes: 3 additions & 9 deletions common/frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,11 @@ func (f *Frame) clearLifecycle() {
f.inflightRequestsMu.Unlock()
}

func (f *Frame) recalculateLifecycle() {
func (f *Frame) recalculateLifecycle(event LifecycleEvent) {
f.log.Debugf("Frame:recalculateLifecycle", "fid:%s furl:%q", f.ID(), f.URL())

f.emit(EventFrameAddLifecycle, event)

// Start with triggered events.
events := make(map[LifecycleEvent]bool)
f.lifecycleEventsMu.RLock()
Expand All @@ -199,14 +201,6 @@ func (f *Frame) recalculateLifecycle() {
}
f.lifecycleEventsMu.RUnlock()

// Check if any of the fired events should be considered fired when looking at the entire subtree.
for k := range events {
if f.hasSubtreeLifecycleEventFired(k) {
continue
}
f.emit(EventFrameAddLifecycle, k)
}

f.lifecycleEventsMu.Lock()
{
f.subtreeLifecycleEvents = make(map[LifecycleEvent]bool)
Expand Down
2 changes: 1 addition & 1 deletion common/frame_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func (m *FrameManager) frameLifecycleEvent(frameID cdp.FrameID, event LifecycleE
frame := m.getFrameByID(frameID)
if frame != nil {
frame.onLifecycleEvent(event)
frame.recalculateLifecycle() // Recalculate life cycle state from the top
frame.recalculateLifecycle(event)
}
}

Expand Down

0 comments on commit 8f2b360

Please sign in to comment.