diff --git a/.gitignore b/.gitignore index 35a2e79..5c17b56 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ pom.xml pom.xml.asc .repl* /dev-resources -/resources/public +/test/resources/public/js figwheel_server.log *.jar *.class diff --git a/project.clj b/project.clj index 6f646e7..41163a2 100644 --- a/project.clj +++ b/project.clj @@ -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}}]}}}) diff --git a/test/mount/example/app_config.cljs b/test/mount/example/app_config.cljs new file mode 100644 index 0000000..4952209 --- /dev/null +++ b/test/mount/example/app_config.cljs @@ -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")) diff --git a/test/mount/example/cljs.cljs b/test/mount/example/cljs.cljs index 25361ea..a7d800f 100644 --- a/test/mount/example/cljs.cljs +++ b/test/mount/example/cljs.cljs @@ -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) diff --git a/test/mount/example/websockets.cljs b/test/mount/example/websockets.cljs new file mode 100644 index 0000000..068a492 --- /dev/null +++ b/test/mount/example/websockets.cljs @@ -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))