[Cuis-dev] dependency mechanism for TextModelMorph
Mark Volkmann
r.mark.volkmann at gmail.com
Sun Mar 23 14:31:15 PDT 2025
I must be doing a poor job of describing what I want to achieve.
I've boiled it down to the minimum code needed to demonstrate.
Here are the steps:
- create a subclass of Object
- add the following instance methods
initialize
| tmm |
tmm := TextModelMorph withText: '' :: acceptOnAny: true.
SystemWindow new addMorph: tmm; openInWorld.
update: arg
'update was called' print
What can I do in the initialize method so update: is called after every
keystroke in the TextModelMorph?
Here are two things I tried that do not work:
tmm model addDependent: self.
tmm model when: #actualContents send: #update: to: self.
On Sun, Mar 23, 2025 at 11:45 AM Weslleymberg Lisboa via Cuis-dev <
cuis-dev at lists.cuis.st> wrote:
> TextModel generates some events. Browse senders of #changed: to see it.
> Maybe the event that #addDepedent: listens to is not the one you need.
>
> Cuis use the Observer Pattern as a dependency mechanism (see [1]) so
> #addDependent: and #changed: are "simplifications" of #when:send:to: and
> #triggerEvent:with:
>
> IMHO if what you need is to be notified of changes in the model, I'd use
> it directly instead of making TextModelMorph notify me.
>
> 1 - <
> https://github.com/nmingotti/The-Cuis-CookBook/wiki/The-Dependency-Mechanism--3
> >
>
>
> Em 23 de março de 2025 11:53:10 BRT, Mark Volkmann via Cuis-dev <
> cuis-dev at lists.cuis.st> escreveu:
>
>> As far as I can tell, TextModel morph does not send #changed: every time
>> its value changes, so that prevents me from listening for updates. I see
>> that the TextModel method actualContents: does send #changed:, but that
>> is not invoked on every change to a TextModelMorph even when it is
>> configured with acceptOnAny: true.
>>
>> On Sun, Mar 23, 2025 at 9:38 AM <ken.dickey at whidbey.com> wrote:
>>
>>> On 2025-03-23 06:35, Mark Volkmann via Cuis-dev wrote:
>>>
>>> > ...
>>> > myTextModelMorph addDependent: self.
>>> ..
>>> >
>>> > I have a few questions.
>>> > - Are there reasons why I should not want this ability?
>>>
>>> Generally, Morphs are Views and update to reflect changes in an
>>> underlying Model.
>>>
>>> A Morph can be a Model if sensible.
>>>
>>> > - Would it be better to listen for changes on the underlying TextModel?
>>>
>>> IMHO, yes.
>>>
>>> $0.02,
>>> -KenD
>>>
>>
>>
>>
> --
> Att.
> Wéslleymberg Lisboa
> Graduado em Sistemas de Informação
> Docente no IFFluminense - Campus Itaboraí
> Ex-Bolsista de IC do Núcleo de Computação Científica (NC2-IFF) - Projeto
> IFF Aerospace
> Github: https://github.com/weslleymberg
> Tel.: +55 22 99931-2376
> --
> Cuis-dev mailing list
> Cuis-dev at lists.cuis.st
> https://lists.cuis.st/mailman/listinfo/cuis-dev
>
--
R. Mark Volkmann
Object Computing, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20250323/486dd728/attachment.htm>
More information about the Cuis-dev
mailing list