Skip to content

Commit

Permalink
Collapse any duplicated events when flusing the event queue.
Browse files Browse the repository at this point in the history
  • Loading branch information
joao-pedro-braz committed Mar 10, 2024
1 parent 5068242 commit f8e1207
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/Bloc/BlEvent.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ BlEvent >> bubblingTarget: aTBlEventTarget [
currentTarget := aTBlEventTarget
]

{ #category : #accessing }
BlEvent >> canBeCollapsed [
"Whether I can be skipped in case there's too many of myself queued."

^ false
]

{ #category : #testing }
BlEvent >> canBePropagated [
<return: #Boolean>
Expand Down
16 changes: 12 additions & 4 deletions src/Bloc/BlHostEventFetcher.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Class {
'eventQueue',
'hostSpace'
],
#category : 'Bloc-Universe - Host'
#category : #'Bloc-Universe - Host'
}

{ #category : #accessing }
Expand All @@ -35,11 +35,19 @@ BlHostEventFetcher >> enqueueEvent: aBlEvent [

{ #category : #'event processing' }
BlHostEventFetcher >> fetchedEventsDo: aBlock [
"Flush event queue and evaluate a given block with every queued event as argument"
| theEvents |
"Flush event queue and evaluate a given block with every queued event as argument, also
collapses any events that can be replaced by newer ones."

| theEvents |
theEvents := LinkedList new.
eventQueue flush: [ :anEvent | theEvents add: anEvent ].
eventQueue
flush: [ :anEvent |
| theLastEvent |
(anEvent canBeCollapsed
and: [ theEvents isNotEmpty
and: [ (theLastEvent := theEvents last) class = anEvent class ] ])
ifTrue: [ theEvents at: theEvents size put: anEvent ]
ifFalse: [ theEvents add: anEvent ] ].
theEvents do: aBlock
]

Expand Down
5 changes: 5 additions & 0 deletions src/Bloc/BlMouseMoveEvent.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ BlMouseMoveEvent class >> secondary [
^ self button: BlMouseButton secondary
]

{ #category : #accessing }
BlMouseMoveEvent >> canBeCollapsed [
^ true
]

{ #category : #accessing }
BlMouseMoveEvent >> delta [
^ delta
Expand Down

0 comments on commit f8e1207

Please sign in to comment.