This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-02-17
Channels
- # announcements (12)
- # babashka (27)
- # beginners (65)
- # biff (8)
- # calva (22)
- # clj-kondo (1)
- # clj-otel (5)
- # clojure (65)
- # clojure-europe (127)
- # clojure-nl (1)
- # clojure-norway (11)
- # clojure-portugal (2)
- # clojure-uk (2)
- # clojurescript (18)
- # cursive (5)
- # data-science (3)
- # datahike (14)
- # datascript (3)
- # datomic (7)
- # deps-new (11)
- # emacs (31)
- # exercism (1)
- # fulcro (1)
- # honeysql (3)
- # hyperfiddle (38)
- # introduce-yourself (4)
- # leiningen (2)
- # malli (20)
- # meander (2)
- # missionary (3)
- # off-topic (4)
- # pathom (3)
- # practicalli (2)
- # reagent (5)
- # releases (1)
- # sci (1)
- # shadow-cljs (9)
- # xtdb (8)
I tried to make a hiccup like macro, but that interferes with the electric macro (would need to make a macro that wraps the e/defn
and processes things before that I guess), and a function that does dom/element
calls doesn’t seem to work properly in a dynamic case (says hyperfiddle.electric-dom2/node not declared ^:dynamic
)
yeah there are good reasons that we haven't provided hiccup
though im not sure what error you're seeing
i can probably help you resolve any issues with dynamics, the boundary between photon dynamics and clojure dynamics has to be explicitly managed currently
yes please show snippet
that's really cute, we have not considered that style
i like it a lot
I mostly just want the :div.some-class
to make classes, if that was provided builtin, that would be enough
yeah the current dom syntax has been a frequently reported issue
we agree with you btw
just tricky to do right
the compiler is giving me warnings for each of the content count cases like
90 | 0 (dom/element e (when attrs (dom/props attrs)) (doseq [[h b] handlers] (dom/on h b)))
------------------^-------------------------------------------------------------
hyperfiddle.electric-dom2/node not declared ^:dynamic
--------------------------------------------------------------------------------
turn <% into defmacro not defn
e/def is not visible in ordinary clojure, only from e/defn and e/def etc
(defmacro <% [elt & attrs-and-content]
(let [[attrs content] (if (map? (first attrs-and-content))
[(first attrs-and-content) (rest attrs-and-content)]
[nil attrs-and-content])
handlers (keep (fn [[key val]]
(when (str/starts-with? (str key) ":on-")
[(subs (str key) 4) val]))
(seq attrs))
classes (element-class-names elt)
attrs (cond-> (apply dissoc attrs (map first handlers))
(seq classes)
(update :class (fn [class]
(let [class-names (str/join " " classes)]
(if class
(str class-names " " ~class)
class-names)))))
e (element-name elt)]
`(dom/element
~e
~(when attrs
`(dom/props ~attrs))
~@(for [[h b] handlers]
`(dom/on ~h ~b))
~@(for [c content]
(if (string? c)
`(dom/text ~c)
c)))))
here’s the macro version, I must have made some mistake 1st time… now it workedthere are also small syntax gaps that photon compiler doesn't understand yet, not all interop forms are handled correctly for example
i will play with it! thank you for sharing
there seems to be a contrib namespace, I can make a properly documented version of that macro as a PR if you think it will be helpful for others
what’s the reason for extensive use of binding forms? Prolly a doc somewhere I missed I guess
i don’t think we’ve explained that yet
main e.g. I'm looking at:
(e/defn Main []
(binding [router/encode contrib.ednish/encode-uri
router/decode #(or (contrib.ednish/decode-path % hf/read-edn-str)
[`user.demo-index/Demos]
#_[[`user.demo-index/Demos . . .]]
#_{`user.demo-index/Demos {0 . 1 . 2 .}})]
(router/router (html5/HTML5-History.)
(set-page-title! router/route)
(binding [dom/node js/document.body]
(dom/pre (dom/text (contrib.str/pprint-str router/route)))
(let [[page & args] router/route]
(e/server (new (Pages. page #_args))))))))
reactive dynamic scope is really cool, it is sufficient for dependency injection of the kind that DI libs like Component etc do
so instead of libraries like component or mount, you would bind a db connection pool at your app root?
Yes, these DI libs: 1. track dependencies to start/stop elements in the right order 2. Inject references in dependent components Electric clojure does 1 out of the box.