Closed mikavilpas closed 8 years ago
Something like this?
;; helper
(defn channel->atom [ch atom]
(go (reset! state (<! ch)))
(defonce view-atom (atom :empty))
(defcard view-channel view-atom)
(channel->atom (config/read-config-from-url config-file-url) view-atom)
Yes, that works nicely. This is what I came up with, for reference:
(defn channel->atom
"Allows showing the first channel result in a devcard:
(defcard foo
(channel->atom (go :hello)))"
[channel]
(let [atom (reagent/atom :empty)]
(go (reset! atom (<! channel)))
atom))
Hi, I'm using devcards to create a build monitor app and lovin' it!
I have core.async channels in many places, and like to create proof of concept devcards to see what they return. Here's a minimal example of the code I use for this:
I need the deref as the render function so a re-render will take place once the async
go
block completes (I think this is why at least). Do you know of a more idiomatic way to achieve this?