Revisions
-
bodil revised this gist
Jul 31, 2013 . 1 changed file with 10 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ core.async example thing ======================== To run: * checkout https://github.com/clojure/core.async and install it using `lein install` * make a project directory for this code * put `omgcoreasync.cljs` in a `src` subdirectory, `project.clj` and `index.html` in the root * go `lein cljsbuild once` to build * load `index.html` in a browser and watch it go -
bodil created this gist
Jul 31, 2013 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <title>core.async demo</title> <meta name="viewport" content="width=device-width"> <script src="js/main.js"></script> </head> <body> <h1>horse_ebooks knows what you did</h1> </body> </html> This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ (ns omgcoreasync (:require-macros [cljs.core.async.macros :refer [go alt!]]) (:require [cljs.core.async :as async])) (def counter (atom 0)) (defn parse-data [data] (let [data (js->clj data) children ((data "data") "children")] (map (fn [child] ((child "data") "title")) children))) (defn jsonp-get [url] (let [callback-name (str "mycallback" (swap! counter inc)) channel (async/chan)] (aset js/window callback-name (fn [data] (async/put! channel data))) (let [script (.createElement js/document "script")] (aset script "src" (str url "?jsonp=" callback-name)) (.appendChild document/head script)) channel)) (go (let [c (jsonp-get "http://www.reddit.com/r/clojure.json") d (jsonp-get "http://www.reddit.com/r/dogfort.json") h (jsonp-get "http://www.reddit.com/r/haskell.json")] (while true (alt! [c d h] ([val ch] (.write js/document (str (parse-data val)) ch)))))) This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ (defproject omgcoreasync "0.1.0-SNAPSHOT" :dependencies [[core.async "0.1.0-SNAPSHOT"]] :plugins [[lein-cljsbuild "0.3.2"]] :cljsbuild {:builds [{:source-paths ["src"], :compiler {:output-to "js/main.js", :output-dir "js", :optimizations :simple, :jar true}}]})