[Pharo-project] Issue 4036 in pharo: Please update Help> Announcements tutorial

Henrik Sperre Johansen henrik.s.johansen at veloxit.no
Mon Apr 18 11:22:41 CEST 2011


This section should probably also explain the concept of the subscriber, 
ie. the thing you need to unregister for the announcement to stop being 
sent.

For message sends (on:send:to:) it is the receiver (to: argument), for 
blocks (on: do:) it's the object where block is defined.
#on:do:for:/#when:do:for, which lets you specify another object as 
subscriber for block actions, is currently not implemented.
It's also a difference from the VW implementation, where when:do: uses 
the action block itself as subscriber, so you're much more likely to 
need on:do:for:.

Cheers,
Henry


On 18.04.2011 11:13, Henrik Sperre Johansen wrote:
> On 18.04.2011 10:47, Fernando Olivero wrote:
>> To remove the subscription you can evaluate: World announcer initialize.
>>
>> Maybe the tutorial should add (pesudo code):
>>
>> MyStuff>>initialize
>>          World announcer
>>                  on: WindowOpened
>>                  send: #showOnTranscript
>>                  to: self
>>          SystemAnnouncer on:#classremove send:#release: to: self.
>>
>> MyStuff>>release: anAnn
>>          World announcer unsuscribe: self.
>>
>> MyStuff>>showOnTranscript
>>       Transcript show: 'A new window was opened';cr
>>
>> I can update the tutorial if people agrees on the pseudo code.
>>
>>
>> To open a transcript evaluate: TranscriptMorph openWindow
>> (decoupled Transcript from Morphic, so directly ask the view to open 
>> itself)
>>
>> Fernando
>
> The old tutorial was weak mainly because it didn't tell you how to 
> unsubscribe.
>
>
> Here's a few examples of that:
>
> "Unsubscribe automatically with weak announcements."
> World announcer weak
>     on: WindowOpened
>     send: #shownOnTranscript
>     to: self.
>
> Then example in Workspace
> obj := self new.
> "Open a window, and see Transcript printing"
> obj := nil.
>  "Open a window, you may see Transcript printing (depending on 
> finalization)"
> "Now force finalization"
> Smalltalk garbageCollect.
> "Open a window, now see no transcript prints."
>
>
> "Automatically unregister after handling one announcement"
> initialize
> World announcer
>     on: WindowOpened
>     do: [:ann: announcer | self shownOnTranscript.
>     announcer unsubscribe: self.]
>
> "Unregister specifically after some time"
> initialize
>     World announcer
>         on: WindowOpened
>         send: #shownOnTranscript
>         to: self.
>
> release
>     World announcer unsubscribe: self.
>
> "Using same action block registered for multiple announcers, 
> unregister specifially at a specific time"
> initialize
>     handlesAnnoucements := true.
>     actionBlock:= [:ann :announcer |
>         handlesAnnouncement
>              ifTrue: [self shownOnTranscript]
>             ifFalse: [announcer unsubscribe: self]].
>      World announcer on: WindowOpened do: actionBlock.
>      AnnouncerTest announcer on: TestCaseEnded do: actionBlock.
>
> release
>     handlesAnnouncements := false.
>
>
>
>
>
>




More information about the Pharo-project mailing list