Skip to content

Commit

Permalink
GtPhlowUpdateOnAnnouncement can have condition [feenkcom/gtoolkit#2257
Browse files Browse the repository at this point in the history
]
  • Loading branch information
JurajKubelka committed Nov 1, 2024
1 parent a7c3ad1 commit 7bd0c49
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 20 deletions.
7 changes: 7 additions & 0 deletions src/GToolkit-Phlow/GtPhlowAsyncUpdateDefinition.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ Class {
#category : #'GToolkit-Phlow-Updating'
}

{ #category : #testing }
GtPhlowAsyncUpdateDefinition class >> isDeprecated [
"Replaced by GtPhlowUpdateOnAnnouncement"

^ true
]

{ #category : #subscriptions }
GtPhlowAsyncUpdateDefinition >> subscribeOn: aGtPhlowElementContext [
self announcerDo: [ :anAnnouncer |
Expand Down
23 changes: 14 additions & 9 deletions src/GToolkit-Phlow/GtPhlowChangeAnnouncerListener.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ GtPhlowChangeAnnouncerListener class >> installOn: anElement announcer: anAnnoun
^ aListener
]

{ #category : #private }
GtPhlowChangeAnnouncerListener >> addSubscription: aSubscription [
"We do not need to collect subscriptions.
We do it just for an explainability purpose."

subscriptions := WeakArray
new: subscriptions size + 1
streamContents: [ :aStream |
aStream
nextPutAll: subscriptions;
nextPut: aSubscription ]
]

{ #category : #accessing }
GtPhlowChangeAnnouncerListener >> configuration: aFutureExecutionConfiguration [
elementFuture executionConfiguration: aFutureExecutionConfiguration
Expand Down Expand Up @@ -79,15 +92,7 @@ GtPhlowChangeAnnouncerListener >> installAnnouncer: anAnnouncer announcement: an
when: anAnnouncement
send: #onAnnouncement:
to: self.

"We do not need to collect subscriptions.
We do it just for an explainability purpose."
subscriptions := WeakArray
new: subscriptions size + 1
streamContents: [ :aStream |
aStream
nextPutAll: subscriptions;
nextPut: aSubscription ]
self addSubscription: aSubscription
]

{ #category : #'event handling' }
Expand Down
14 changes: 5 additions & 9 deletions src/GToolkit-Phlow/GtPhlowUpdateDefinitions.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,18 @@ GtPhlowUpdateDefinitions >> add: aDefinition [

{ #category : #'api - adding' }
GtPhlowUpdateDefinitions >> asyncWhen: anAnnouncement if: anIfCondition in: anAnnouncer [
self add: (GtPhlowAsyncUpdateWithConditionDefinition new
announcement: anAnnouncement;
condition: anIfCondition;
announcer: anAnnouncer)
self
add: (GtPhlowUpdateOnAnnouncement new
announcement: anAnnouncement;
condition: anIfCondition;
announcer: anAnnouncer)
]

{ #category : #'api - adding' }
GtPhlowUpdateDefinitions >> asyncWhen: anAnnouncement in: anAnnouncer [
self add: (GtPhlowUpdateOnAnnouncement new
announcement: anAnnouncement;
announcer: anAnnouncer).
true ifTrue: [ ^ self ].

self add: (GtPhlowAsyncUpdateDefinition new
announcement: anAnnouncement;
announcer: anAnnouncer)
]

{ #category : #copying }
Expand Down
23 changes: 21 additions & 2 deletions src/GToolkit-Phlow/GtPhlowUpdateOnAnnouncement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ Class {
#superclass : #GtPhlowUpdateDefinition,
#instVars : [
'announcerValuable',
'announcementValuable'
'announcementValuable',
'condition'
],
#category : #'GToolkit-Phlow-Updating'
}
Expand All @@ -20,7 +21,11 @@ GtPhlowUpdateOnAnnouncement >> announcement: aValuable [

{ #category : #accessing }
GtPhlowUpdateOnAnnouncement >> announcementDo: aBlock [
self announcement ifNotNil: aBlock
self announcement ifNotNil: [ :anAnnouncementClass |
self condition
ifNotNil: [ :aCondition |
aBlock cull: (anAnnouncementClass where: aCondition) ]
ifNil: [ aBlock cull: anAnnouncementClass ] ]
]

{ #category : #accessing }
Expand All @@ -38,6 +43,20 @@ GtPhlowUpdateOnAnnouncement >> announcerDo: aBlock [
self announcer ifNotNil: aBlock
]

{ #category : #accessing }
GtPhlowUpdateOnAnnouncement >> condition [
^ condition
]

{ #category : #accessing }
GtPhlowUpdateOnAnnouncement >> condition: aOneArgBlock [
"Condition is a block which receives an announcement and returns boolean value.
[ :anAnnouncement | true ].
See `Announcement where: [ :anAnnouncement | true ]`"

condition := aOneArgBlock
]

{ #category : #accessing }
GtPhlowUpdateOnAnnouncement >> inputDo: aBlock [
self announcer ifNotNil: [ :anAnnouncer |
Expand Down

0 comments on commit 7bd0c49

Please sign in to comment.