parent
0622b64941
commit
8cedfaa60a
4 changed files with 30 additions and 13 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -16,3 +16,5 @@ doo-index.html
|
||||||
/.idea
|
/.idea
|
||||||
/.lein-repl-history
|
/.lein-repl-history
|
||||||
/.nrepl-history
|
/.nrepl-history
|
||||||
|
.cljs_rhino_repl/
|
||||||
|
out/
|
||||||
|
|
|
||||||
13
build.boot
13
build.boot
|
|
@ -88,6 +88,19 @@
|
||||||
(comp
|
(comp
|
||||||
(cljs :optimizations :advanced :ids #{"mount"})))
|
(cljs :optimizations :advanced :ids #{"mount"})))
|
||||||
|
|
||||||
|
(deftask cljs-dev
|
||||||
|
"mount cljs dev example"
|
||||||
|
[]
|
||||||
|
(set-env! :source-paths #(conj % "dev/clj" "dev/cljs"))
|
||||||
|
(set-env! :resource-paths #{"dev/resources"})
|
||||||
|
|
||||||
|
(comp
|
||||||
|
(serve :dir "dev/resources/public/")
|
||||||
|
(watch)
|
||||||
|
(reload)
|
||||||
|
(cljs-repl)
|
||||||
|
(cljs :optimizations :none :ids #{"mount"})))
|
||||||
|
|
||||||
(deftask cljs-example
|
(deftask cljs-example
|
||||||
"mount cljs example"
|
"mount cljs example"
|
||||||
[]
|
[]
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
(mount/start)
|
(mount/start)
|
||||||
|
|
||||||
;; time to establish a websocket connection before disconnecting
|
;; time to establish a websocket connection before disconnecting
|
||||||
(js/setTimeout #(mount/stop-except "#'app.audit-log/log") 500)
|
;; (js/setTimeout #(mount/stop-except "#'app.audit-log/log") 500)
|
||||||
|
|
||||||
;; time to close a connection to show it in audit
|
;; time to close a connection to show it in audit
|
||||||
(js/setTimeout #(show-log) 1000)
|
(js/setTimeout #(show-log) 1000)
|
||||||
|
|
|
||||||
|
|
@ -53,8 +53,7 @@
|
||||||
(when stop
|
(when stop
|
||||||
(prn (str "<< stopping.. " state " (namespace was recompiled)"))
|
(prn (str "<< stopping.. " state " (namespace was recompiled)"))
|
||||||
(stop))
|
(stop))
|
||||||
(swap! running dissoc state)
|
(swap! running dissoc state)))
|
||||||
{:restart? true}))
|
|
||||||
|
|
||||||
#?(:clj
|
#?(:clj
|
||||||
(defn current-state [state]
|
(defn current-state [state]
|
||||||
|
|
@ -130,6 +129,9 @@
|
||||||
(up name state (atom #{})))
|
(up name state (atom #{})))
|
||||||
@inst)))
|
@inst)))
|
||||||
|
|
||||||
|
;; #?(:clj
|
||||||
|
;; (println (str "[mount]: here is what I see running: " @@#'mount.core/running
|
||||||
|
;; " is " state " running? [" @@#'mount.core/running state)))
|
||||||
#?(:clj
|
#?(:clj
|
||||||
(defmacro defstate [state & body]
|
(defmacro defstate [state & body]
|
||||||
(let [[state params] (macro/name-with-attributes state body)
|
(let [[state params] (macro/name-with-attributes state body)
|
||||||
|
|
@ -138,22 +140,22 @@
|
||||||
order (make-state-seq state-name)
|
order (make-state-seq state-name)
|
||||||
sym (str state)]
|
sym (str state)]
|
||||||
(validate lifecycle)
|
(validate lifecycle)
|
||||||
(let [{:keys [restart?]} (cleanup-if-dirty state-name)
|
(let [s-meta (cond-> {:order order
|
||||||
s-meta (cond-> {:order order
|
|
||||||
:start `(fn [] ~start)
|
:start `(fn [] ~start)
|
||||||
:status #{:stopped}}
|
:status #{:stopped}}
|
||||||
stop (assoc :stop `(fn [] ~stop))
|
stop (assoc :stop `(fn [] ~stop))
|
||||||
suspend (assoc :suspend `(fn [] ~suspend))
|
suspend (assoc :suspend `(fn [] ~suspend))
|
||||||
resume (assoc :resume `(fn [] ~resume)))]
|
resume (assoc :resume `(fn [] ~resume)))]
|
||||||
`(do
|
`(do
|
||||||
(defonce ~state (DerefableState. ~state-name))
|
(~'defonce ~state (DerefableState. ~state-name))
|
||||||
(let [meta# (assoc ~s-meta :inst (atom (NotStartedState. ~state-name))
|
(let [meta# (~'assoc ~s-meta :inst (~'atom (NotStartedState. ~state-name))
|
||||||
:var (var ~state))]
|
:var (~'var ~state))
|
||||||
((var mount.core/update-meta!) [~state-name] meta#)
|
restart?# ((~'var mount.core/cleanup-if-dirty) ~state-name)]
|
||||||
(when ~restart?
|
((~'var mount.core/update-meta!) [~state-name] meta#)
|
||||||
(prn (str ">> starting.. " ~state-name " (namespace was recompiled)"))
|
(~'when restart?#
|
||||||
((var mount.core/up) ~state-name meta# (atom #{})))
|
(~'prn (str ">> starting.. " ~state-name " (namespace was recompiled)"))
|
||||||
(var ~state)))))))
|
((~'var mount.core/up) ~state-name meta# (~'atom #{})))
|
||||||
|
(~'var ~state)))))))
|
||||||
|
|
||||||
#?(:clj
|
#?(:clj
|
||||||
(defmacro defstate! [state & {:keys [start! stop!]}]
|
(defmacro defstate! [state & {:keys [start! stop!]}]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue