#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
|
||||
.repl*
|
||||
/dev-resources
|
||||
/resources/public
|
||||
/test/resources/public/js
|
||||
figwheel_server.log
|
||||
*.jar
|
||||
*.class
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
:cljsbuild {
|
||||
:builds [{:id "dev"
|
||||
: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
|
||||
:asset-path "js/compiled/out"
|
||||
|
|
@ -36,6 +36,5 @@
|
|||
{:id "prod"
|
||||
:source-paths ["src" "test"]
|
||||
:compiler {:output-to "test/resources/public/js/compiled/mount.js"
|
||||
:main mount.example.cljs
|
||||
:optimizations :advanced
|
||||
: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
|
||||
(:require [mount.core :as mount])
|
||||
(:require-macros [mount.core :refer [defstate]]))
|
||||
(:require [mount.core :as mount]
|
||||
[mount.example.websockets :refer [system-a]]))
|
||||
|
||||
(enable-console-print!)
|
||||
|
||||
(println "hi from mount!")
|
||||
(println "(mount/start)" (mount/start))
|
||||
|
||||
(defn on-js-reload []
|
||||
"reloading js..")
|
||||
(println "system-a: " @system-a)
|
||||
|
||||
;; 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