Login  Register

Re: ListModel observer on its listitems?

Posted by Chris Uppal-3 on Jan 18, 2005; 1:21pm
URL: https://forum.world.st/ListModel-observer-on-its-listitems-tp3372732p3372756.html

Günther Schmidt wrote:

> Like when an item is added send
>
> ListModel add: anItem
> anItem when:#someEvent send:#updateItem: to: self "ListModel" with: anItem

You can do that, but I wouldn't want to change the system to do it by default.

The reason is that setting up an observer is not free (by default every
observable/observer pair ends up with an entry in the _EventsRegister) and so
using a ListModel on a list of, say, ten thousand entries would be quite
expensive.  It also isn't often needed since there is usually only a small
number of ways that the items can be modified, and it is relatively easy for
the modifying code to trigger the necessary change notifications.

That isn't always the case, though -- it can sometimes make the application
logic quite awkward (and this is especially true of trees, where I have yet to
find a satisfactory general solution).  In such cases, it seems like a
reasonable idea to consider using your own subclass of ListModel that does
Observe its elements.  If you do that (and your lists are fairly large) then
you may want to consider making your items be a subclass of Model, since that
has an optimised form of the event triggering mechanism, or of copying the
Model #getEvent (etc) code into your item class(es).

    -- chris