[Fwd: Re: [Bese-devel] isolated actions]

Drew Crampsie drewc at tech.coop
Wed Apr 5 07:02:24 UTC 2006


Just confirming my mailing list disability, forgot to cc the list on my 
last response. Sorry to all those who learned how to use email, i was 
sick that day.

drewc
-------- Original Message --------
Subject: Re: [Bese-devel] isolated actions
Date: Wed, 05 Apr 2006 03:00:51 -0400
From: Drew Crampsie <drewc at tech.coop>
To: Evrim ULU <evrim at core.gen.tr>
References: <4432CD47.5010304 at core.gen.tr> <4433535A.1030304 at tech.coop> 
<4432DC63.6090800 at core.gen.tr> <44336116.9050107 at tech.coop> 
<4432E45C.1090600 at core.gen.tr>

Evrim ULU wrote:
> Drew Crampsie wrote:
> 
> 
>>What problem are you trying to solve that requires the separation of
>>the  two defining macros in a way the current code does not?
>>
> 
> I'm considering to do a similar hook to defaction for ajax, it seems,
> this strategy will bloat the defaction macro. I may define (defaction
> sample-action :ajax) but maintainability will decrease. This is why i
> offered the defisolated-action macro.


I see. In that case, why not refactor DEFACTION to grab it's definer
from a hash table keyed on the 'combination' keyword.

Something like (completely untested and unfinished):

(defvar *action-definers* (make-hash-table))

(defmacro define-action-definer (type &body body)
  "basically just wrap a lambda around the macro form which accepts the
name and the body of the action"
  (setf (gethash type *action-definers*)
   `(lambda (name rest)
      , at body))

(define-action-definer (:isolate)
  (with-unique-names (memo-id memo memo-present-p)
         `(defaction ,name ,(second rest)
           (let ((,memo-id
                  (strcat (mapcar (rcurry #'funcall *context*)
                                  (list #'find-session-id
                                        #'find-frame-id
                                        #'find-action-id)))))
           (multiple-value-bind (,memo ,memo-present-p)
               (gethash ,memo-id (component.isolate-hash ,(caar (second
rest))))
             (if  ,memo-present-p
                  ,memo
                  (setf (gethash ,memo-id (component.isolate-hash ,(caar
(second rest))))
                        (progn ,@ (cddr rest)))))))))


(defmacro defaction (name &rest rest)
   (if (keywordp (car rest))
       ,(funcall (gethash (car rest) *action-definers*) name rest)
       `(%defaction ,name , at rest)))

Cleans things up a bit IMO.

Then again, why do you need a new definer for 'ajax' actions? A normal
action can be used with ajax just fine, like :

`(dojo.io.bind
   (create :url ,(lol::make-action-url
	         component
	         (my-action component datum))
           :load (do-some-js-with-results)))

where lol::make-action-url is defined as:

(defmacro make-action-url (component action)
   "
There has got to be something like this buried in UCW somewhere,
but here's what i use."
   `(ucw::print-uri-to-string
     (compute-url ,component
      :action-id (ucw::make-new-action (ucw::context.current-frame
*context*)
		 (lambda ()
		   (arnesi:with-call/cc
		     ,action))))))

Of course i've got layers of macros over all this to make it easier to
use, but that's the underlying machinery. Very simple, easy to use, and
no need for a new type of action (in fact, i have code that makes a
'normal' component into an 'ajax' component with a one-line change).

I think this is a better approach, although i may not understand what
you are trying to achieve.

drewc





> 
> king regards,
> evrim.
> _______________________________________________
> bese-devel mailing list
> bese-devel at common-lisp.net
> http://common-lisp.net/cgi-bin/mailman/listinfo/bese-devel





More information about the bese-devel mailing list