21 |
22 |
23 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/samples/repl/src/repl/test.cljs:
--------------------------------------------------------------------------------
1 | ;; Copyright (c) Rich Hickey. All rights reserved.
2 | ;; The use and distribution terms for this software are covered by the
3 | ;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
4 | ;; which can be found in the file epl-v10.html at the root of this distribution.
5 | ;; By using this software in any fashion, you are agreeing to be bound by
6 | ;; the terms of this license.
7 | ;; You must not remove this notice, or any other, from this software.
8 |
9 | (ns repl.test
10 | (:require [clojure.browser.repl :as repl]
11 | [clojure.reflect :as reflect]))
12 |
13 | (repl/connect "http://localhost:9000/repl")
14 |
15 | (comment
16 |
17 | ;; Note: If you would like for the compiler to be aware of
18 | ;; everything in a project then delete the 'out' directory before
19 | ;; calling build. This will force the compiler to compile the whole
20 | ;; project.
21 |
22 | ;; Compile this project to JavaScript
23 | (use 'cljs.closure)
24 | (def opts {:output-to "samples/repl/main.js"
25 | :output-dir "samples/repl/out"})
26 | (build "samples/repl/src" opts)
27 |
28 | ;; Start REPL
29 | (do (require '[cljs.repl :as repl])
30 | (require '[cljs.repl.browser :as browser])
31 | (def env (browser/repl-env))
32 | (repl/repl env))
33 |
34 | ;; Open http://localhost:9000/ in a browser. When this page is loaded
35 | ;; it will connect to the REPL. Alternatively you can serve index.html
36 | ;; from your own local webserver.
37 |
38 | ;; Evaluate some basic forms
39 | (+ 1 1)
40 | (string-print "hello")
41 | (prn "foo")
42 | (prn {:a :b})
43 | (println "hello")
44 | (doseq [next (range 20)] (println next))
45 | {:a :b}
46 | "hello"
47 | (reduce + [1 2 3 4 5])
48 | (time (reduce + (range 10000)))
49 | (js/alert "Hello World!")
50 |
51 | (load-file "clojure/string.cljs")
52 | (clojure.string/reverse "Hello")
53 |
54 | (defn sum [coll] (reduce + coll))
55 | (sum [2 2 2 2])
56 |
57 | ;; Create dom elements.
58 | (ns dom.testing (:require [clojure.browser.dom :as dom]))
59 | (dom/append (dom/get-element "content")
60 | (dom/element "Hello World!"))
61 |
62 | ;; Load something we haven't used yet
63 | (ns test.crypt
64 | (:require [goog.crypt :as c]))
65 | (c/stringToByteArray "ClojureScript")
66 |
67 | (load-namespace 'goog.date.Date)
68 | (goog.date.Date.)
69 |
70 | (ns test.color (:require [goog.color :as c]))
71 | (js->clj (c/parse "#000000"))
72 |
73 | )
74 |
--------------------------------------------------------------------------------
/samples/twitterbuzz/.gitignore:
--------------------------------------------------------------------------------
1 | out/
2 | twitterbuzz.js
3 |
--------------------------------------------------------------------------------
/samples/twitterbuzz/README.md:
--------------------------------------------------------------------------------
1 | # ClojureScript "TwitterBuzz" Demo
2 |
3 | ## One-time Setup
4 |
5 | See https://github.com/clojure/clojurescript/wiki/Quick-Start
6 |
7 | ## Run in Development Mode
8 |
9 | Compile the demo:
10 |
11 | cljsc src > twitterbuzz.js
12 |
13 | After running the above command, open index.html.
14 |
15 | ## Compile in Development Mode with the REPL (Faster)
16 |
17 | * Run `script/repl`
18 | * To run it from Emacs, `C-x d` and nav to the `clojurescript` directory
19 | * `M-x set-variable inferior-lisp-program`
20 | * Set to `"script/repl"`
21 | * `M-x run-lisp`
22 |
23 | * Once the REPL is running, evaluate:
24 |
25 | (use 'cljs.closure)
26 | (def opts {:output-to "samples/twitterbuzz/twitterbuzz.js" :output-dir "samples/twitterbuzz/out"})
27 |
28 | (build "samples/twitterbuzz/src" opts)
29 |
30 | The reason we set the `:output-dir` is because the `index.html` script tag is specifically pointing to that directory.
31 |
32 | * See `cljs.closure` source for more compilation examples.
33 |
34 | ## Compile in Advanced Mode
35 |
36 | `cljsc` can be run with a Clojure map of compiler options. To compile using `cljsc` and Closure Compiler's "advanced" optimization setting:
37 |
38 | cljsc src '{:optimizations :advanced}' > twitterbuzz.js
39 |
40 | Because advanced mode results in only one `.js` file, `twitterbuzz.js`, only one `
23 |
24 |
25 |
26 |
27 |
39 |
40 |
47 |
48 |
49 |
50 |
51 |
53 |
54 |
55 | Leaderboard
56 |
57 |
58 |
59 |
60 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
75 |
76 |
77 |
78 |
79 |