This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-08-09
Channels
- # announcements (3)
- # babashka (120)
- # beginners (87)
- # calva (7)
- # clj-kondo (35)
- # cljsrn (25)
- # clojure (94)
- # clojure-austin (4)
- # clojure-europe (53)
- # clojure-nl (2)
- # clojure-norway (6)
- # clojurescript (16)
- # conjure (8)
- # cursive (6)
- # data-oriented-programming (2)
- # data-science (19)
- # datahike (1)
- # datalevin (29)
- # datomic (13)
- # fulcro (50)
- # gratitude (1)
- # honeysql (9)
- # jackdaw (2)
- # kaocha (7)
- # leiningen (3)
- # malli (4)
- # off-topic (4)
- # polylith (3)
- # re-frame (5)
- # reagent (1)
- # releases (1)
- # reveal (4)
- # shadow-cljs (17)
- # tools-deps (10)
- # vim (17)
- # vscode (4)
- # xtdb (3)
sure, its all just cljs. just the way you use the tools and the configs are different. the code is just cljs
Hey guys, just a quick check:
;; If `product` doesn't exist, fetch it, then update parent state with the newly fetched `product`
(defn fetcher [& {:keys [product on-fetch]}]
[:Fetcher
(when (nil? product)
{:update :parent :on-resolve (fetch-json ""
#(on-fetch (-> % :title (or "Failed to fetch"))))})
(if product
[:div "Fetched successfully!"]
[:div "Loading..."])])
(defn app [& {:keys [product]}]
[:App
[:div "Product is: " product]
(fetcher
:product product
:on-fetch #(app :product %))])
Do you find this code intelligible at all? Are you able to figure out what's going on?LGTM, although I'd use just {:keys [...]}
instead of & {:keys [...]}
- easier to compose and format such functions.
Also, depending on what you're doing and assuming you're using Reagent, that (fetcher ...)
should probably be [fetcher ...]
.
Thanks! It's not Reagent, it's a similar framework (but with no dependencies on anything else) I'm working on, where the selling point is purely functional components, no atoms
Another example:
(defn up-down
[x]
[:Up-down
[:div {:class "flex items-center self-start space-x-3"}
[:button {:class "px-3 py-1", :on-click #(up-down (inc x))}
"+"]
[:span "Current value: " x]
[:button {:class "px-3 py-1", :on-click #(up-down (dec x))}
"-"]]])
(See how "updating state" is just instead a recursive call to the component, which returns the next version of itself)
@U2FRKM4TW / @U03EC9KU17H What is :Fetcher
here, till now I am using :div
as first element while defining hiccup syntax
As zakkor mentioned, it's not from Reagent but rather from an unrelated framework.
In Reagent, that would probably result in a warning and <Fetcher>
directly in the DOM, but I'd have to check.
ohh... Thanks for the message @U2FRKM4TW
I’m trying to add figwheel-main to an existing leiningen project, and am trying to now build for the first time (`lein trampoline run -m figwheel.main -- -b dev -r`) Any thoughts as to how I can solve this error message? It does manage to open a new tab at 9500, but it’s just the default dev page, and the repl prompt never appears because it doesn’t successfully connect
[Figwheel] Compiling build admin to "target/public/cljs-out/admin-main.js"
[Figwheel] Failed to compile build admin in 4.881 seconds.
[Figwheel:WARNING] Compile Exception: 'com.cognitect.transit.Writer com.cognitect.transit.TransitFactory.writer(com.cognitect.transit.TransitFactory$Format, java.io.OutputStream, java.util.Map, com.cognitect.transit.WriteHandler, java.util.function.Function)'
[Figwheel:SEVERE] 'com.cognitect.transit.Writer com.cognitect.transit.TransitFactory.writer(com.cognitect.transit.TransitFactory$Format, java.io.OutputStream, java.util.Map, com.cognitect.transit.WriteHandler, java.util.function.Function)'
[Figwheel] Starting Server at
[Figwheel] Starting REPL
Prompt will show when REPL connects to evaluation environment (i.e. a REPL hosting webpage)