[cells-devel] Connecting two models

Ken Tilton kentilton at gmail.com
Wed Oct 10 13:24:34 UTC 2012


On Tue, Oct 2, 2012 at 9:47 PM, Mark Cox <markcox80 at gmail.com> wrote:
> G'day,
>
> I think my mental model of Cells is wrong. Perhaps someone can help.
>
> I have two model classes:
>
> (defmodel model ()
>   ((item-index
>     :initarg :item-index
>     :accessor item-index))
>   (:default-initargs
>    :item-index (c-in 0)))
>
> (defmodel view ()
>   ((item-index
>     :initarg :item-index
>     :accessor item-index))
>   (:default-initargs
>    :item-index (c-in 0)))
>
> What I would like to do is to connect the item-index slot of an
> instance of MODEL to the item-index in an instance of VIEW. i.e.
>
> (defun connect-model-and-view (model view)
>   (setf (item-index view) (c? (item-index model))))
>
> which does not appear to be possible.

Correct, that is not how Cells works (though it could be made to work
if necessary).

Instead, the view would be instantiated after the model -- or with the
model in one "datapulse" -- with model either supplied as an initarg
or located by the view rule during model initialization:

Either:

    (make-instance 'view
          :model <some-model-instance already extant>
          :item-index (c? (item-index (model self)))

Or (the way my models work)

    (make-instance 'view
          :item-index (c? (item-index
<navigate-app-model-finding-desired-specific-model>)))

The key then is having model objects organized in a way that one can
find other entities dynamically as the larger model formed by all the
model objects comes to life.

The family class and its supporting utilities are how I generally
manage the Cells modelspace of an application.

hth, kt

>
> I have navigated around the issue by introducing a third model class,
> CONTROLLER, that has an item-index slot initialised with (c?
> (item-index (^model))) and an observer that updates the view. However, I
> am wondering if this is the correct way as I seem to require inserting
> WITH-INTEGRITY in the observer.
>
> Thanks
> Mark
>
> _______________________________________________
> cells-devel site list
> cells-devel at common-lisp.net
> http://common-lisp.net/mailman/listinfo/cells-devel




More information about the cells-devel mailing list