pharo icon indicating copy to clipboard operation
pharo copied to clipboard

Model unsubscribe support

Open JanBliznicenko opened this issue 2 years ago • 0 comments

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

JanBliznicenko avatar Jun 26 '22 08:06 JanBliznicenko