restart listener
This commit is contained in:
parent
fea36ec2a5
commit
9b063504e8
1 changed files with 19 additions and 0 deletions
|
|
@ -301,6 +301,25 @@
|
||||||
(var-to-str to) :state))
|
(var-to-str to) :state))
|
||||||
states))
|
states))
|
||||||
|
|
||||||
|
;; restart on events
|
||||||
|
|
||||||
|
(defprotocol ChangeListener
|
||||||
|
(add-watcher [this ks watcher])
|
||||||
|
(on-change [this k]))
|
||||||
|
|
||||||
|
(deftype RestartListener [watchers]
|
||||||
|
ChangeListener
|
||||||
|
|
||||||
|
(add-watcher [_ ks state]
|
||||||
|
(doseq [k ks]
|
||||||
|
(swap! watchers update k #(conj % state))))
|
||||||
|
|
||||||
|
(on-change [_ k]
|
||||||
|
(let [states (@watchers k)]
|
||||||
|
(apply stop states)
|
||||||
|
(apply start states))))
|
||||||
|
|
||||||
|
|
||||||
;; explicit, not composable (subject to depreciate?)
|
;; explicit, not composable (subject to depreciate?)
|
||||||
|
|
||||||
(defn stop-except [& states]
|
(defn stop-except [& states]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue