[parenscript-devel] jQuery chain commands?
rklinda at gmail.com
Sun May 17 11:46:11 UTC 2009
>>>>> Regarding 'Re: [parenscript-devel] jQuery chain commands?'; Vladimir Sedach adds:
> Here's one way to do it: (defpsmacro chain (&rest method-calls)
> (labels ((do-chain (method-calls)
> (if (cdr method-calls)
> `((@ ,(do-chain (cdr method-calls)) ,(caar
> method-calls)) ,@(cdar method-calls))
> (car method-calls))))
> (do-chain (reverse method-calls))))
> Then you can say:
> (ps (chain ($ "foo") (bar x z) (baz 5)))
> => "$('foo').bar(x, z).baz(5);
and I absolutely love it, so much cleaner and maintainable. Thank you
for this chain macro and the whole project, superb.
> As an aside, be careful that none of the chained functions cause
> reflows, and cache the intermediate results when possible. The
> jQuery style of programming is pretty much stream processing, but
> done in a terribly slow way (mostly because current JS
> implementations are not very good, but also because of the way
> jQuery is implemented). It would be interesting to do something like
> Rich Waters' SERIES for Parenscript since (like SERIES itself) you
> can do some really mean optimizations with macros.
I'll keep that in mind, thanks.
More information about the parenscript-devel