[Cuis-dev] How to use Events?
Casey Ransberger
bahweep at icloud.com
Mon Sep 9 18:43:54 PDT 2019
Hey Juan, is the backticks thing specific to Cuis, or is this yet another magic feature of Smalltalk that I didn’t know about?
—Casey
> On Sep 9, 2019, at 6:04 AM, Juan Vuletich via Cuis-dev <cuis-dev at lists.cuis.st> wrote:
>
>> On 9/9/2019 3:17 AM, Philip Bernhart via Cuis-dev wrote:
>> Hello,
>>
>> I noticed that when I register events with when:send:to:with: with collections
>> as the with: paramater the contents of the collection the collection
>> becomes nil on the actually triggered event. Maybe that has something
>> todo with WeakMessageSend. Anyway an example tells better what I mean:
>>
>>
>> browserMorph
>> setProperty: #editItemAction
>> toValue: [:repository :record|
>> | flashcardMorph card mapping |
>> flashcardMorph _ FlashcardMorph new.
>> card _ Flashcard new.
>> card question: (record at: #question ifAbsent: '').
>> card answer: (record at: #answer ifAbsent: '').
>>
>> card when: #changed
>> send: #saveRecordMappingWith:
>> to: browser
>> with: {card. record}.
>>
>> flashcardMorph model: card.
>> flashcardMorph showAnswer.
>> flashcardMorph enableEditing.
>> flashcardMorph openInWorld ].
>>
>> Then in Flashcard there is a foo method which does:
>> self triggerEvent: #changed.
>>
>> Here the {card. record} becomes for some reason (weak reference?) nil
>> and causes that the event isn't triggered. So #saveRecordMappingWith:
>> isn't called.
>>
>> With simple datatypes like Integers this works, with static arrays this
>> seems to work too.
>>
>> Maybe this style of doing that isn't the right one, maybe I'm using the
>> event system for things which it wasn't supposed to do.
>>
>> Suggestions?
>>
>>
>> Thanks for your time,
>> Philip
>
> Hi Philip,
>
> I believe the event system uses WeakMessageSend in all Smalltalk dialects. Folks, please correct me if I'm wrong.
>
> An easy way to fix the problem is to turn your collection into a literal, using backticks:
>
> card when: #changed
> send: #saveRecordMappingWith:
> to: browser
> with: `{card. record}`.
>
>
> Cheers,
>
> --
> Juan Vuletich
> www.cuis-smalltalk.org
> https://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Dev
> https://github.com/jvuletich
> https://www.linkedin.com/in/juan-vuletich-75611b3
> @JuanVuletich
>
> --
> Cuis-dev mailing list
> Cuis-dev at lists.cuis.st
> https://lists.cuis.st/mailman/listinfo/cuis-dev
More information about the Cuis-dev
mailing list