reblocks-parenscript - An utility to define JavaScript dependencies for Weblocks widgets using Parenscript.



You can install this library from Quicklisp, but you want to receive updates quickly, then install it from

(ql-dist:install-dist ""
                      :prompt nil)
(ql:quickload :reblocks-parenscript)


This library should be used to define JavaScript dependencies for Reblocks widgets.





Keeps JavaScript code, created using make-dependency macro or make-dependency* function.



This function works similarly like make-dependency macro but accepts Parenscript code as a list. They are related to each other like parenscript:ps macro and parenscript:ps* function.

Use a function version when you want to build a JavaScript code from parts and embed some value into it.

Usually it looks like this:

CL-USER> (let ((widget-id "foo-bar"))
            `(defun show-alert ()
               (alert (+ "Hello from widget with id = " ,widget-id)))))

This will generate following JavaScript code:

CL-USER> (format t "~A~%"
                 (reblocks-parenscript:js-code *))
function showAlert() {
    __PS_MV_REG = [];
    return alert('Hello from widget with id = ' + 'foo-bar');


This macro creates an object of class parenscript-dependency transformin the BODY into JavaScript Code. It interpreters whole body as a Parenscript code.

Here is a usage example.

CL-USER> (reblocks-parenscript:make-dependency
           (defun show-alert ()
             (ps:chain console (log "Showing alert"))
             (alert "Hello from Lisp!"))

           (set-interval show-alert 3000))

This dependency will have this JavaScript code:

CL-USER> (format t "~A~%"
                 (reblocks-parenscript:js-code *))
function showAlert() {
    console.log('Showing alert');
    __PS_MV_REG = [];
    return alert('Hello from Lisp!');
setInterval(showAlert, 3000);

You can use this dependency in a method of reblocks/dependencies:get-dependencies generic-function like this:

(defmethod reblocks/dependencies:get-dependencies ((widget example))
     (defun show-alert ()
       (ps:chain console (log "Showing alert"))
       (alert "Hello from Lisp!"))

     (set-interval show-alert 3000))

Creates a Reblocks action and returns JavaScript code, which can be used as onChange, onClick, etc. handler.

  • Argument LISP-CODE should be a list of conses:

    First list item should be action's lambda list. Other list items are wrapped into implicit progn.

  • Argument JS-CODE also should be a list of conses:

    Parenscript code, returning an object. This object will be passed to the Lisp part of the handler as keyword arguments.

This macro creates a code which will return a string. The result is suitable to be used inline as value for HTML attributes like onChange, onClick, etc.

Handler must be build from two parts JS and Lisp.

JavaScript part should be written in Parenscript and return an objects. This object will be passed to the backend as keyword arguments for the action, defined by Lisp part of the handler.

The code from JS-CODE argument will be wrapped into a function which is called immediately with implicit arguments.

Here is a real world example. This code processes updates of a text in the HTML input. This way you can make a suggest or on fly value validation:

(:input :value url
        :name "url"
        :type "text"
         :lisp-code ((&key url)
                     (update-url (branches widget)
         :js-code ((event)
                   ;; This will pass new URL value
                   ;; to the backend:
                    :url (@ event target value)))))