This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-02-07
Channels
- # announcements (35)
- # beginners (80)
- # boot (1)
- # calva (4)
- # cider (33)
- # cljdoc (40)
- # clojars (3)
- # clojure (95)
- # clojure-berlin (2)
- # clojure-europe (4)
- # clojure-italy (28)
- # clojure-nl (2)
- # clojure-seattle (1)
- # clojure-serbia (1)
- # clojure-spec (74)
- # clojure-uk (71)
- # clojurescript (29)
- # core-async (1)
- # cursive (80)
- # data-science (4)
- # datomic (17)
- # duct (75)
- # emacs (4)
- # figwheel-main (5)
- # fulcro (3)
- # jackdaw (1)
- # java (1)
- # jobs-discuss (20)
- # off-topic (32)
- # parinfer (2)
- # pathom (23)
- # re-frame (26)
- # reagent (25)
- # rum (6)
- # shadow-cljs (122)
- # speculative (4)
- # sql (17)
- # testing (7)
- # yada (8)
@dj942 nice article!
I’m referring to this: https://functional.works-hub.com/learn/re-framing-text-mode-apps-fd5cf
Hi, how to change the content of one element of HTMLCollection using ClojureScript?
I just want to translate something like document.getElementsByTagName('style')[0].innerHTML="xxx";
to ClojureScript.
(let [el (-> (js/document.getElementsByTagName "style")
(aget 0))]
(set! (.-innerHTML el) "xxx"))
also (aset (js/document.getElementsByTagName "style") 0 "innerHTML" "xxx")
yeah but that is abusing aset
for something it is not supposed to do since innerHTML
is not an array
looking at the call to js*
I don't think it would be a problem
(js* "(~{}[~{}][~{}] = ~{})" (js/document.getElementsByTagName "style") 0 "innerHTML" "xxx")
might not be the intended purpose but...
that is not the point. yes it generates the correct code since it happens to be the same JS code
TIL 🙂
I did this: (let [xx (some-> js/document (.getElementsByTagName "style") array-seq first .-innerHTML)] .. )
... and when xx is not empty, do (set! xx "xxx")
but that won't work? xx
will be a string so using set!
on it won't update the actual element
Thanks, changed to (let [xx (some-> js/document (.getElementsByTagName "style"))] ..)
and then (set! (-> xx array-seq first .-innerHTML) "xxx")
I am exploring extend-via-metadata
and I am getting this behavior:
(defprotocol Component
:extend-via-metadata true
(start [component]))
(def component (with-meta {:name "db"} {`start (constantly "started")
`clojure.core.protocols/datafy (fn [x] (:name x))}))
(satisfies? clojure.core.protocols.Datafiable component)
;; => true
(satisfies? Component component)
;; => false
So when extending with datafy
protocol i get true when checking if the data satisfies?
the protocol.
However with a custom protocol with :extend-via-metadata true
I am getting false
in the satisfies?
check.
Is there something I am missing in the implementation?
thanksIn Clojure, satisfies? doesn’t check metadata extensions, not sure about cljs
Just to expand on the answer as to why satisfies seems to work for Datafiable. Datafiable is implemented on Object. https://github.com/clojure/clojure/blob/28b87d53909774af28f9f9ba6dfa2d4b94194a57/src/clj/clojure/core/protocols.clj#L191-L192 This even works.
(satisfies? clojure.core.protocols/Datafiable 2)
;; => true
Is it okay to have multiple puts (`>!`) within a go block or should each put be within its own go-block? If the answer depends then what are some things I should consider before doing one over the other?
@mario.cordova.862 It's fine
@jkr.sw Thanks! I originally had each put within a go-block but I was thinking about it and reasoned that since, the way it was currently set up, everything was happening synchronously I might as well do them all within one go block. But wasn't sure if this was proper
I'm trying to write some code (to run at compilation time) that will only do a require if a library is present. I thought of trying something like this:
(defmacro include-if-present []
(when (io/resource "foo/bar.cljc")
'(require 'foo.bar)))
but it doesn't seem to work and the docs for cljs.core/require
suggest it's 'for the repl only' .. not sure what restrictions that implies exactly. https://clojurescript.org/guides/ns-forms#_the_require_and_require_macros_macros
Any ideas please let me know.