-
-
Save swannodette/332c574cb4d9df41aa35 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns strange.macros | |
#+cljs (:require-macros [cemerick.cljs.test :refer [is deftest]] | |
[strange.macros :refer [my-response edn]])) | |
;; I want an abstraction over a javascript library. These macros are simplified versions | |
#+clj | |
(defmacro my-response | |
[x] | |
(let [{:keys [status headers body]} (macroexpand x)] | |
`(str ~status ~body))) | |
#+clj | |
(defmacro edn | |
;; ([body] `(edn 200 ~body)) | |
([status body] | |
{:status status | |
:headers {"Content-Type" "application/edn"} | |
:body `(pr-str ~body)})) | |
#+cljs | |
(deftest dummy-macro-tests | |
;; I use (+ [] {}) just to make sure the code is evaluated in javascript | |
(is (= (my-response (edn [] {})) "[]{}"))) | |
;; This is what I do with the real my-response | |
(comment | |
;; inside a request handler | |
(my-response response-object {:status 200 :headers {"Content-type" "..."} {:hello "world"}}) | |
(my-response response-object (edn {:hello "world"})) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It turns out that cljsbuild sometimes compiles before cljx completes which result the output javascript is a mix of old and new code. This macro itself is guiltless :)