Skip to content
Browse files

Working version of a sample app using an external Js lib. Refs. CLJS-54

  • Loading branch information...
1 parent da8e7fa commit efe496ecca62fca39958c22f72144f79863a499e @fogus fogus committed Aug 5, 2011
View
2 samples/hello-js/.gitignore
@@ -1,2 +1,2 @@
out/
-hello.js
+hello*.js
View
11 samples/hello-js/README.md
@@ -1,4 +1,4 @@
-Simple ClojureScript Project Example.
+Simple ClojureScript Project Example Using an External JavaScript Library
One-time Setup
==============
@@ -18,17 +18,16 @@ Run in Development Mode
Development mode allows for each file to be loaded in a separate script tag so
that errors can be easily tracked to the offending file.
- cljsc src > hello.js
+ cljsc src > hello-js.js
-After running the above command, open hello-dev.html. Notice that each required
+After running the above command, open hello-js-dev.html. Notice that each required
JavaScript file has been loaded in its most readable form.
Run Optimized JavaScript
========================
Once an application is ready for production, a single optimized file can be produced.
- cljsc src {:optimizations :advanced} > hello.js
-
-After running the above command, open hello.html to view the result.
+ cljsc src {:optimizations :advanced} > hello-js.js
+After running the above command, open hello-js.html to view the result.
View
13 samples/hello-js/hello-js-dev.html
@@ -1,19 +1,18 @@
<html>
<head>
- <title>Hello ClojureScript</title>
+ <title>Hello External JavaScript Library</title>
</head>
<body>
- <h1>Hello ClojureScript!</h1>
+ <h1>Hello External JavaScript Library!</h1>
<!-- In unoptimized mode, additional script tags are required -->
<script type="text/javascript" src="out/goog/base.js"></script>
- <script type="text/javascript" src="hello.js"></script>
- <script type="text/javascript" src="foo.js"></script>
+ <script type="text/javascript" src="my-external-lib.js"></script>
+ <script type="text/javascript" src="hello-js.js"></script>
<script>
- goog.require('hello.core');
+ goog.require('hello_js.core');
</script>
<script>
- alert(greet("ClojureScript"));
- alert("The sum of [1,2,3,4,5,6,7,8,9] is: " + hello.core.sum([1,2,3,4,5,6,7,8,9]));
+ hello_js.core.popup_msg('JavaScript calling a ClojureScript function');
</script>
</body>
</html>
View
11 samples/hello-js/hello-js.html
@@ -1,10 +1,13 @@
<html>
<head>
- <title>Hello ClojureScript</title>
+ <title>Hello External JavaScript Library</title>
</head>
<body>
- <h1>Hello ClojureScript!</h1>
- <script type="text/javascript" src="foo.js"></script>
- <script type="text/javascript" src="hello.js"></script>
+ <h1>Hello External JavaScript Library!</h1>
+ <script type="text/javascript" src="my-external-lib.js"></script>
+ <script type="text/javascript" src="hello-js.js"></script>
+ <script>
+ hello_js.core.popup_msg('JavaScript calling a ClojureScript function');
+ </script>
</body>
</html>
View
4 samples/hello-js/my-external-lib.js
@@ -1,3 +1,3 @@
-function foo() {
- alert('you called foo!');
+function send_alert(msg) {
+ alert("Sending Alert via " + msg + "!");
};
View
10 samples/hello-js/src/hello/core.cljs
@@ -1,3 +1,9 @@
-(ns hello.core)
+(ns hello-js.core)
-(js/foo)
+(defn ^:export popup-msg
+ [msg]
+ (js/send_alert msg))
+
+(popup-msg "ClojureScript calling a global function defined in an external JavaScript library")
+
+(popup-msg (str "ClojureScript: the time is now " (js/Date.)))
View
4 samples/hello-js/src/hello/foo/bar.cljs
@@ -1,4 +0,0 @@
-(ns hello.foo.bar)
-
-(defn sum [xs]
- (reduce + 0 xs))

0 comments on commit efe496e

Please sign in to comment.
Something went wrong with that request. Please try again.