Skip to content

Instantly share code, notes, and snippets.

@verma
Created July 14, 2014 21:15
Show Gist options
  • Save verma/a8560f22cdae3e7709fb to your computer and use it in GitHub Desktop.
Save verma/a8560f22cdae3e7709fb to your computer and use it in GitHub Desktop.
(defmacro bind-handlers [type node cb & specs]
(let [attacher (if (= type :value)
'addValueEventListener
'addChildEventListener)]
`(cond
~@(for [[matchtype iface handler] specs]
(list
`(= ~type ~matchtype )
`(. ~node ~attacher (reify ~iface
(~handler [this v]
(~cb (.getValue v))))))))))
(bind-handlers a b c [:value com.firebase.Test onDataChange])
;; What I am getting right now:
(clojure.core/cond ((clojure.core/= a :value) (. b addChildEventListener (clojure.core/reify com.firebase.Test (onD
ataChange [pani.core/this pani.core/v] (c (.getValue pani.core/v)))))))
;; What I want
(clojure.core/cond (clojure.core/= a :value) (. b addChildEventListener (clojure.core/reify com.firebase.Test (onD
ataChange [pani.core/this pani.core/v] (c (.getValue pani.core/v))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment