[squeak-dev] Morphs and Data Question

tim Rowledge tim at rowledge.org
Sun Oct 25 17:39:49 UTC 2020



> On 2020-10-25, at 7:44 AM, Eric Gade <eric.gade at gmail.com> wrote:

> What is the best way to design my Morph subclasses so that they "react" to changes on their models? For example, if I have some data related model with text that updates and I want the "view" (the Morph) to update whenever this occurs? In my own quick code I've always just implemented a `step` method that checks for data on the model updates, but is that too brutal and inefficient?
> 

A simple step method is certainly possible and certainly effective - but if you set the step time too short it will also eat your cpu alive.

The basic strategy is to use some mechanism to signal to your morph that something has changed and thereby set a flag that the morph needs redraw/updating. One of the nice things about morphs (and I've certainly fulminated about a lot of the not-so-nice things over time) is that the system can work better than the old MVC approach to the #changed:/#update: protocol. The old approach often lead to massive storms (or worse, recursions) of a change leading to an update that lead to a number of changes that each lead to ... etc. Morphic quite neatly broke that (when used properly) by allowing for an update to flag that a redraw is needed. Multiple changes simply keep setting that flag and eventually the morphic cycle reaches the "everybody what wants to, update!" phase.

I know there are plenty of people that know the details better than me, so I'll let them explain more...

tim
--
tim Rowledge; tim at rowledge.org; http://www.rowledge.org/tim
The downside of being better than everyone else is that people tend to assume you're pretentious




More information about the Squeak-dev mailing list