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
|
||||
/.lein-repl-history
|
||||
/.nrepl-history
|
||||
.cljs_rhino_repl/
|
||||
out/
|
||||
|
|
|
|||
13
build.boot
13
build.boot
|
|
@ -88,6 +88,19 @@
|
|||
(comp
|
||||
(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
|
||||
"mount cljs example"
|
||||
[]
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
(mount/start)
|
||||
|
||||
;; 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
|
||||
(js/setTimeout #(show-log) 1000)
|
||||
|
|
|
|||
|
|
@ -53,8 +53,7 @@
|
|||
(when stop
|
||||
(prn (str "<< stopping.. " state " (namespace was recompiled)"))
|
||||
(stop))
|
||||
(swap! running dissoc state)
|
||||
{:restart? true}))
|
||||
(swap! running dissoc state)))
|
||||
|
||||
#?(:clj
|
||||
(defn current-state [state]
|
||||
|
|
@ -130,6 +129,9 @@
|
|||
(up name state (atom #{})))
|
||||
@inst)))
|
||||
|
||||
;; #?(:clj
|
||||
;; (println (str "[mount]: here is what I see running: " @@#'mount.core/running
|
||||
;; " is " state " running? [" @@#'mount.core/running state)))
|
||||
#?(:clj
|
||||
(defmacro defstate [state & body]
|
||||
(let [[state params] (macro/name-with-attributes state body)
|
||||
|
|
@ -138,22 +140,22 @@
|
|||
order (make-state-seq state-name)
|
||||
sym (str state)]
|
||||
(validate lifecycle)
|
||||
(let [{:keys [restart?]} (cleanup-if-dirty state-name)
|
||||
s-meta (cond-> {:order order
|
||||
(let [s-meta (cond-> {:order order
|
||||
:start `(fn [] ~start)
|
||||
:status #{:stopped}}
|
||||
stop (assoc :stop `(fn [] ~stop))
|
||||
suspend (assoc :suspend `(fn [] ~suspend))
|
||||
resume (assoc :resume `(fn [] ~resume)))]
|
||||
`(do
|
||||
(defonce ~state (DerefableState. ~state-name))
|
||||
(let [meta# (assoc ~s-meta :inst (atom (NotStartedState. ~state-name))
|
||||
:var (var ~state))]
|
||||
((var mount.core/update-meta!) [~state-name] meta#)
|
||||
(when ~restart?
|
||||
(prn (str ">> starting.. " ~state-name " (namespace was recompiled)"))
|
||||
((var mount.core/up) ~state-name meta# (atom #{})))
|
||||
(var ~state)))))))
|
||||
(~'defonce ~state (DerefableState. ~state-name))
|
||||
(let [meta# (~'assoc ~s-meta :inst (~'atom (NotStartedState. ~state-name))
|
||||
:var (~'var ~state))
|
||||
restart?# ((~'var mount.core/cleanup-if-dirty) ~state-name)]
|
||||
((~'var mount.core/update-meta!) [~state-name] meta#)
|
||||
(~'when restart?#
|
||||
(~'prn (str ">> starting.. " ~state-name " (namespace was recompiled)"))
|
||||
((~'var mount.core/up) ~state-name meta# (~'atom #{})))
|
||||
(~'var ~state)))))))
|
||||
|
||||
#?(:clj
|
||||
(defmacro defstate! [state & {:keys [start! stop!]}]
|
||||
|
|
|
|||
Loading…
Reference in a new issue