[Bese-devel] Re: Question regarding container and widget-component

Mac Chan emailmac at gmail.com
Sat Oct 1 20:57:39 UTC 2005


OK. So I came up with this. Apparently *context* is not available when
during object initialization.

So this won't work:

(defmethod shared-initialize :after ((obj level4-container) slot-names
&rest initargs)
  (declare (ignore slot-names initargs))
  (setf (root obj)
        (level1-container (context.window-component *context*))))

Now I patch the reference before the component is rendered.

(defmethod render-on :before ((res response) (obj level4-container))
  (setf (root obj)
        (level1-container (context.window-component *context*))))

I'm not sure if this is the proper way to structure my app.

Basically I have some global state to keep in the top level object,
and I don't want to replicate the states to the sub components (the
blogline rss-reader ucw example posted on c.l.l sometime ago uses this
approach).

So each subcomponent will have a reference to the top level object so
it will render the state properly.

Maybe this is not the standard way to do things, but I find that the
other way (the blogline example) resulted in a lot of state
replication code.

Anyone want to chime in and share your thoughts?

On 10/1/05, Mac Chan <emailmac at gmail.com> wrote:
> Is there a simple way to carry a reference to the top level component
> for each subcomponent?
>
> (defcomponent level1-container (widget-component)
>   (
>    (level2-container :component level2-container
>                      :accessor level2-container)
>   ))
>
> (defcomponent level2-container (widget-component)
>   (
>    (root :initarg :root :accessor root) ;; point to level1-container obj
>    (level3-container :component level3-container
>                      :accessor level3-container)
>   ))
>
> (defcomponent level3-container (widget-component)
>   (
>    (root :initarg :root :accessor root) ;; point to level1-container obj
>    (level4-container :component level4-container
>                      :accessor level4-container)
>   ))
>
> (defcomponent level4-container (widget-component)
>   (
>    (root :initarg :root :accessor root) ;; point to level1-container obj
>   ))
>
> ;; ----------------------------------------------------------------
> ;; Approach 1 - use after method of the top level container to assign
> ;; the referece.  Ugly and cumbersome. Is there a better way?
> ;; ----------------------------------------------------------------
>
> (defmethod shared-initialize :after ((obj level1-container) slot-names
> &rest initargs)
>   (declare (ignore slot-names initargs))
>   (setf (root (level2-container obj)) obj)
>   (setf (root (level3-container (level2-container obj))) obj)
>   (setf (root (level4-container (level3-container (level2-container obj)))) obj)
> )
>
> ;; ----------------------------------------------------------------
> ;; Approach 2 - pass SELF object to initarg, but how to refer to SELF???
> ;; ----------------------------------------------------------------
> (defcomponent level1-container (widget-component)
>   (
>    (level2-container :component (level2-container :root SELF) ;; SELF
> = level1-container ???
>                      :accessor level2-container)
>   ))
>
> ;; ----------------------------------------------------------------
> ;; Approach 3 - use after method of each component to find its
> ;; containing component or root component
> ;; ----------------------------------------------------------------
>
> (defmethod shared-initialize :after ((obj level4-container) slot-names
> &rest initargs)
>   (declare (ignore slot-names initargs))
>   (setf (root obj) (FIND-CONTAINING-COMPONENT obj))) ;; is there a way
> to do this?
>
> Maybe there's a reference to the top level window-component and we can
> work our way from there?
>
> Thanks.
>



More information about the bese-devel mailing list