From 7bd0c49c90b9a02a62915a656f9a65a437f16619 Mon Sep 17 00:00:00 2001 From: Juraj Kubelka Date: Fri, 1 Nov 2024 20:36:47 -0300 Subject: [PATCH] `GtPhlowUpdateOnAnnouncement` can have condition [feenkcom/gtoolkit#2257] --- .../GtPhlowAsyncUpdateDefinition.class.st | 7 ++++++ .../GtPhlowChangeAnnouncerListener.class.st | 23 +++++++++++-------- .../GtPhlowUpdateDefinitions.class.st | 14 ++++------- .../GtPhlowUpdateOnAnnouncement.class.st | 23 +++++++++++++++++-- 4 files changed, 47 insertions(+), 20 deletions(-) diff --git a/src/GToolkit-Phlow/GtPhlowAsyncUpdateDefinition.class.st b/src/GToolkit-Phlow/GtPhlowAsyncUpdateDefinition.class.st index 4c01f319..5220bd35 100644 --- a/src/GToolkit-Phlow/GtPhlowAsyncUpdateDefinition.class.st +++ b/src/GToolkit-Phlow/GtPhlowAsyncUpdateDefinition.class.st @@ -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 | diff --git a/src/GToolkit-Phlow/GtPhlowChangeAnnouncerListener.class.st b/src/GToolkit-Phlow/GtPhlowChangeAnnouncerListener.class.st index 83babf29..dde40d90 100644 --- a/src/GToolkit-Phlow/GtPhlowChangeAnnouncerListener.class.st +++ b/src/GToolkit-Phlow/GtPhlowChangeAnnouncerListener.class.st @@ -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 @@ -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' } diff --git a/src/GToolkit-Phlow/GtPhlowUpdateDefinitions.class.st b/src/GToolkit-Phlow/GtPhlowUpdateDefinitions.class.st index f68b1304..16284c56 100644 --- a/src/GToolkit-Phlow/GtPhlowUpdateDefinitions.class.st +++ b/src/GToolkit-Phlow/GtPhlowUpdateDefinitions.class.st @@ -14,10 +14,11 @@ 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' } @@ -25,11 +26,6 @@ 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 } diff --git a/src/GToolkit-Phlow/GtPhlowUpdateOnAnnouncement.class.st b/src/GToolkit-Phlow/GtPhlowUpdateOnAnnouncement.class.st index ee4ec0b4..6f3b9e1f 100644 --- a/src/GToolkit-Phlow/GtPhlowUpdateOnAnnouncement.class.st +++ b/src/GToolkit-Phlow/GtPhlowUpdateOnAnnouncement.class.st @@ -3,7 +3,8 @@ Class { #superclass : #GtPhlowUpdateDefinition, #instVars : [ 'announcerValuable', - 'announcementValuable' + 'announcementValuable', + 'condition' ], #category : #'GToolkit-Phlow-Updating' } @@ -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 } @@ -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 |