#10: first pass on cljs support is in
This commit is contained in:
parent
362036a3b9
commit
87e59dedcc
5 changed files with 35 additions and 8 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -5,7 +5,7 @@ pom.xml
|
||||||
pom.xml.asc
|
pom.xml.asc
|
||||||
.repl*
|
.repl*
|
||||||
/dev-resources
|
/dev-resources
|
||||||
/resources/public
|
/test/resources/public/js
|
||||||
figwheel_server.log
|
figwheel_server.log
|
||||||
*.jar
|
*.jar
|
||||||
*.class
|
*.class
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
:cljsbuild {
|
:cljsbuild {
|
||||||
:builds [{:id "dev"
|
:builds [{:id "dev"
|
||||||
:source-paths ["src" "test"]
|
:source-paths ["src" "test"]
|
||||||
:figwheel {:on-jsload "mount.example.cljs/on-js-reload" }
|
;; :figwheel {:on-jsload "mount.example.cljs/on-js-reload"}
|
||||||
|
|
||||||
:compiler {:main mount.example.cljs
|
:compiler {:main mount.example.cljs
|
||||||
:asset-path "js/compiled/out"
|
:asset-path "js/compiled/out"
|
||||||
|
|
@ -36,6 +36,5 @@
|
||||||
{:id "prod"
|
{:id "prod"
|
||||||
:source-paths ["src" "test"]
|
:source-paths ["src" "test"]
|
||||||
:compiler {:output-to "test/resources/public/js/compiled/mount.js"
|
:compiler {:output-to "test/resources/public/js/compiled/mount.js"
|
||||||
:main mount.example.cljs
|
|
||||||
:optimizations :advanced
|
:optimizations :advanced
|
||||||
:pretty-print false}}]}}})
|
:pretty-print false}}]}}})
|
||||||
|
|
|
||||||
8
test/mount/example/app_config.cljs
Normal file
8
test/mount/example/app_config.cljs
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
(ns mount.example.app-config
|
||||||
|
(:require-macros [mount.core :refer [defstate]]))
|
||||||
|
|
||||||
|
(defn load-config [path]
|
||||||
|
(println "loading config from " path " (at least pretending)")
|
||||||
|
{:system-a {:uri "ws://echo.websocket.org/"}})
|
||||||
|
|
||||||
|
(defstate config :start (load-config "resources/config.end"))
|
||||||
|
|
@ -1,10 +1,13 @@
|
||||||
(ns mount.example.cljs
|
(ns mount.example.cljs
|
||||||
(:require [mount.core :as mount])
|
(:require [mount.core :as mount]
|
||||||
(:require-macros [mount.core :refer [defstate]]))
|
[mount.example.websockets :refer [system-a]]))
|
||||||
|
|
||||||
(enable-console-print!)
|
(enable-console-print!)
|
||||||
|
|
||||||
(println "hi from mount!")
|
(println "(mount/start)" (mount/start))
|
||||||
|
|
||||||
(defn on-js-reload []
|
(println "system-a: " @system-a)
|
||||||
"reloading js..")
|
|
||||||
|
;; time for websocket to connect
|
||||||
|
(js/setTimeout #(println "(mount/stop)" (mount/stop))
|
||||||
|
500)
|
||||||
|
|
|
||||||
17
test/mount/example/websockets.cljs
Normal file
17
test/mount/example/websockets.cljs
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
(ns mount.example.websockets
|
||||||
|
(:require [mount.example.app-config :refer [config]])
|
||||||
|
(:require-macros [mount.core :refer [defstate]]))
|
||||||
|
|
||||||
|
(defn connect [uri]
|
||||||
|
(println "connecting to " uri)
|
||||||
|
(let [ws (js/WebSocket. uri)]
|
||||||
|
(set! (.-onopen ws) #(println "opening ws @" uri))
|
||||||
|
(set! (.-onclose ws) #(println "closing ws @" uri))
|
||||||
|
ws))
|
||||||
|
|
||||||
|
(defn disconnect [ws]
|
||||||
|
(println "disconnecting " @ws)
|
||||||
|
(.close @ws))
|
||||||
|
|
||||||
|
(defstate system-a :start (connect (get-in @config [:system-a :uri]))
|
||||||
|
:stop (disconnect system-a))
|
||||||
Loading…
Reference in a new issue