pharo
pharo copied to clipboard
Model unsubscribe support
Problem description
Class Model
uses Announcer
and has getter announcer
and whenChangedDo:
.
What I am missing is support for unsubscribe: aSubscriber
. If I directly use aModel announcer unsubscribe: aSubscriber
, it does not work, because the original block (that has info about the receiver) is replaced by different one in Model>>#whenChangedDo:
, so the model acts as the subscriber even if the real original subscriber is different.
Note that I actually noticed this issue when using NewValueHolder, not the generic Model.
Possible test
testUnsubscribe
| hasBeenAnnounced |
hasBeenAnnounced := false.
aModel whenChangedDo: [ hasBeenAnnounced := true ].
aModel unsubscribe: self.
aModel valueChanged.
self deny: hasBeenAnnounced.
Version All recent versions of Pharo (8-11), all OS