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 |
14 | (repl/connect "http://localhost:9000/repl")
15 |
16 | (comment
17 |
18 | ;; Note: If you would like for the compiler to be aware of
19 | ;; everything in a project then delete the 'out' directory before
20 | ;; calling build. This will force the compiler to compile the whole
21 | ;; project.
22 |
23 | ;; Compile this project to JavaScript
24 | (use 'cljs.closure)
25 | (def opts {:output-to "samples/repl/main.js"
26 | :output-dir "samples/repl/out"})
27 | (build "samples/repl/src" opts)
28 |
29 | ;; Start REPL
30 | (do (require '[cljs.repl :as repl])
31 | (require '[cljs.repl.browser :as browser])
32 | (def env (browser/repl-env))
33 | (repl/repl env))
34 |
35 | ;; Open http://localhost:9000/ in a browser. When this page is loaded
36 | ;; it will connect to the REPL. Alternatively you can serve index.html
37 | ;; from your own local webserver.
38 |
39 | ;; Evaluate some basic forms
40 | (+ 1 1)
41 | (string-print "hello")
42 | (prn "foo")
43 | (prn {:a :b})
44 | (println "hello")
45 | (doseq [next (range 20)] (println next))
46 | {:a :b}
47 | "hello"
48 | (reduce + [1 2 3 4 5])
49 | (time (reduce + (range 10000)))
50 | (js/alert "Hello World!")
51 |
52 | (load-file "clojure/string.cljs")
53 | (clojure.string/reverse "Hello")
54 |
55 | (defn sum [coll] (reduce + coll))
56 | (sum [2 2 2 2])
57 |
58 | ;; Create dom elements.
59 | (ns dom.testing (:require [clojure.browser.dom :as dom]))
60 | (dom/append (dom/get-element "content")
61 | (dom/element "Hello World!"))
62 |
63 | ;; Load something we haven't used yet
64 | (ns test.crypt
65 | (:require [goog.crypt :as c]))
66 | (c/stringToByteArray "ClojureScript")
67 |
68 | (load-namespace 'goog.date.Date)
69 | (goog.date.Date.)
70 |
71 | (ns test.color (:require [goog.color :as c]))
72 | (js->clj (c/parse "#000000"))
73 |
74 | )
75 |
--------------------------------------------------------------------------------
/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 |