This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-09-09
Channels
- # beginners (376)
- # cider (7)
- # cljs-dev (4)
- # clojure (96)
- # clojure-dev (7)
- # clojure-finland (2)
- # clojure-spec (1)
- # clojure-uk (15)
- # clojurescript (54)
- # cryogen (1)
- # defnpodcast (2)
- # docs (4)
- # emacs (1)
- # fulcro (2)
- # hoplon (15)
- # lumo (19)
- # off-topic (28)
- # om (3)
- # pedestal (2)
- # portkey (6)
- # proton (2)
- # re-frame (34)
- # reagent (4)
- # ring (3)
- # spacemacs (5)
- # unrepl (3)
@dm3 for stuff like this i'd usually wire up a function that takes a cell and returns a new one that behaves the way i want (probably with do-watch)
(defn passive-cell
[active v]
(j/with-let [c (j/cell @v)]
(h/do-watch
active
(fn [_ n] (reset! c @v)))))
like this?
it seems strange though
seems like the main reason you want this is because you have the function that has side effects inside the cell= but you want to decide whether the side effects happen at all outside the cell. personally i would just build the contents of the possible alert unconditionally without side effects, then decide whether to actually trigger the alert based on that as step 2.
(defc= alert-string (when bad? (str "BAD: " (muted indicator))))
then either
(do-watch alert-string (fn [_ n] (when n (println n))))
(cell= (when alert-string (println alert-string)))
the latter can be bundled up into a fn pretty easy if you end up with a lot of boilerplate
(defn alert-cell
[c]
(j/cell= (when c (println c))))
(alert-cell (cell= (when bad? (str "BAD: " (muted indicator)))))
you could probably even go a step further with macros to get
(alert-cell= (when bad? (str "BAD: " (muted indicator))))