Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CORS support and multiple expressions (file-level compile) #30

Open
emnh opened this issue Jan 25, 2015 · 1 comment
Open

CORS support and multiple expressions (file-level compile) #30

emnh opened this issue Jan 25, 2015 · 1 comment

Comments

@emnh
Copy link

emnh commented Jan 25, 2015

CORS support

I implemented CORS support in a fork so that the compiler can be used from AJAX clients on other hosts (see this example). If you want you can just diff my fork and pick up the CORS stuff, but I also did some other small stuff so I would need to clean it up if you want me to send a proper pull request. My fork is running here.

File compile as a service

What is the best way to add a http://host/compile-file API to compile a whole file of s-expressions instead of just one expression? I'm currently trying to integrate with JSBin. I have a working demo in a JSBin fork, but it just takes one expression in the file like the REPL.

What is the best workaround given the current compilation scheme, that is, compile a file, which is basically just a list of expressions, as one expression? I figured it works fine wrapped in a let expression. For example the following runs in my JSBin fork:

(let []

(ns cljs.user)

(def paper (js/Raphael. 10, 50, 320, 200))

(defn makeCircle
   [x]
   (let 
     [circle (.circle paper x x 10)]
      (.attr circle "fill" "#0000ff")
      (.attr circle "stroke" "#ffffff")
      circle))

(def circles (map makeCircle (range 10 100 10)))
(doall circles)
(js/console.log (str circles))

)

Error handling

How can I get better error messages from the compiler to report to JSBin? How can I catch exceptions that occur with the reader in clj-params? I suppose I should disable it and explicitly call read-string on expr.

@jaredly
Copy link

jaredly commented Apr 21, 2015

great work on the CORS stuff! Exactly what I needed.

Also, for multiple expressions wrapping everything is just what you want. A (do ...) expression will also do the trick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants