Skip to content
Clint Moore edited this page Oct 2, 2015 · 5 revisions

I'll use this to list some of the stuff I've done with pikey.

First off, a couple of simple macros.

Some of the most useful so far that I've written.

(defmacro+ps -> (name function &rest args)
  `((@ ,name ,function) ,@args))

(defpsmacro with-document-ready (&rest body)
  `(progn
     ((@ ($ document) ready) (lambda ()
                               ,@body))))

(defpsmacro ajax (&key url (data nil) (on-success nil) (on-error nil))
  `(-> $ ajax (create url ,url
                      method "POST"
                      data-type "json"
                      ,@(when data  `(data ,data))
                      ,@(when on-success  `(success ,on-success))
                      ,@(when on-error `(error ,on-error)))))

(defpsmacro and-property (element prop action)
  `(when ((@ ,element has-own-property) ,prop)
     ,action))

;; And my personal favorite...
(defpsmacro map (func list)
  `(do ((i 0 (incf i)))
       ((>= i (@ ,list length)))
     (funcall ,func (aref ,list i))))
(-> console log "Honk") ;; console.log("Honk");
(-> console die) ;; console.die();
(defmacro+ps bind-event (name event &rest body)
  `((@ (@ (sel ,name)) bind) ,event ,@body))
(defmacro+ps sel (name)
  `($ ,name))

(defmacro+ps $. (name)
  `(@ (sel ,name)))

(defmacro+ps on (what event &rest body)
  `((@ ,what on) ,event ,@body))

(defmacro+ps bind-event (name event &rest body)
  `((@ (@ (sel ,name)) bind) ,event ,@body))

(defmacro+ps selector-ready (selector &rest body)
  `((@ (@ ($ ,selector)) ready) ,@body))
Clone this wiki locally