Hi! So, I'm trying to add a class that depends on a predicate (`(kid :class (cell= {:active state}))`) but, no matter what I do, the markup ends up <a class="{:active true}" href="/">Home</a>
.
Not sure what I'm doing wrong here...
Answering my own question: after digging through the code, it seems that I have to either require hoplon.jquery
or hoplon.goog
so that the multimethod can be loaded.
@rlander glad you found it, you're not the first to run into this
i added a note to https://github.com/hoplon/hoplon/wiki/HTML-Attributes-and-JS-Events#default-on-methods, feel free to edit anywhere on the wiki you would have expected to find it
@alandipert thanks for the link! I totally missed that page. I guess it wouldn't hurt to add a link here: https://github.com/hoplon/hoplon/wiki/Cookbook, under Attribute Inheritance.
I'll update that page with the link if that's all right.
please do, thanks
btw, I'm experimenting with Hoplon + shadow-cljs and I'm really enjoying the experience.
great! i have yet to use shadow myself
I might create a starter-template if anyone else is interested
@alandipert I'll leave the link here when I'm done for you to poke around then.
Assuming I have an element called article-preview
, why does this work:
(for-tpl [article global-feed]
(div (cell= (article-preview article)))))
But this doesn't:
(for-tpl [article global-feed]
(cell= (article-preview article)))))
Also, why do I have to deref within article-preview
when I try this:
(for-tpl [article global-feed]
(article-preview article)))))
....
(defn article-preview [article]
(h2 (:title @article))
Isn't for-tpl
supposed to auto deref?
I guess I'm very confused about the nuances of cell deref.
I want to help with the documentation, but I guess I need a firmer grasp of how deref'ing cells work.
@rlander these are excellent observations, in the first case you mention i would say for-tpl
stands for "for template" and the body of the for-tpl must evaluate to a non-cell, concrete piece of markup
internally for-tpl is instantiating as many instances of the template it needs to have one for each element of global-feed
at any time
so as global-feed grows and shrinks it recycles existing ones if it can
i think it might be possible for you to conditionalize the "top-level" of the template by using if-tpl
but i haven't used hoplon myself in awhile and i forget
for your 2nd question, for-tpl doesn't auto-deref i don't think. the binding name is a cell. so it will only auto-deref if you refer to it in a cell=
i.e. article
as received by article-preview
is a Cell