[Cuis-dev] updating a TextModelMorph
Juan Vuletich
juan at cuis.st
Sun Aug 25 05:56:09 PDT 2024
On 8/24/2024 5:40 PM, Mark Volkmann via Cuis-dev wrote:
> I have a class whose initialize method creates a TextModelMorph like
> this:
>
> textModelMorph := TextModelMorph
> textProvider: self
> textGetter: #text
> textSetter: #text:.
>
> It has the following additional instance methods:
>
> text
> ^ text
>
> text: aString
> text := aString.
>
> In addition to displaying the TextModelMorph, it displays a button.
> When the button is clicked, it does this:
>
> self text: 'test'.
>
> But the TextModelMorph does not update to show the new value.
> I thought since I changed the "model", it would update.
> I tried lots of methods in TextModelMorph, such as
> updateActualContents, but nothing is working.
> What do I need to do to cause it to update when the value of the text
> instance variable changes?
>
> --
> R. Mark Volkmann
> Object Computing, Inc.
Hi Mark,
I don't have access to your full example, so I can not try what I'll
say. So take it just as a suggestion for further exploration.
You need to do `self changed: #text.`. For an example, see senders of
#classCommentText, especially in #newClassComment:. This is the changed:
/update: dependency mechanism in action. According to MVC and the
Observer pattern, models don't know about views, so they can't
communicate directly. It is views, when created, that say 'I want to be
notified when...'.
Hope this helps,
--
Juan Vuletich
cuis.st
github.com/jvuletich
researchgate.net/profile/Juan-Vuletich
independent.academia.edu/JuanVuletich
patents.justia.com/inventor/juan-manuel-vuletich
linkedin.com/in/juan-vuletich-75611b3
twitter.com/JuanVuletich
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20240825/a282a360/attachment.htm>
More information about the Cuis-dev
mailing list