This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-01-18
Channels
- # bangalore-clj (1)
- # beginners (60)
- # boot (98)
- # cider (8)
- # clojure (158)
- # clojure-dusseldorf (16)
- # clojure-france (3)
- # clojure-hamburg (2)
- # clojure-mke (2)
- # clojure-russia (11)
- # clojure-serbia (1)
- # clojure-spec (123)
- # clojure-uk (59)
- # clojurescript (44)
- # code-reviews (16)
- # community-development (51)
- # core-async (46)
- # cryogen (1)
- # cursive (9)
- # datascript (5)
- # datomic (36)
- # emacs (3)
- # events (12)
- # hoplon (57)
- # jobs (1)
- # juxt (3)
- # klipse (55)
- # lein-figwheel (3)
- # leiningen (5)
- # luminus (3)
- # off-topic (8)
- # om (75)
- # om-next (9)
- # onyx (17)
- # pedestal (7)
- # portland-or (3)
- # proton (36)
- # protorepl (6)
- # re-frame (3)
- # reagent (33)
- # remote-jobs (1)
- # ring (23)
- # ring-swagger (2)
- # rum (1)
- # specter (1)
- # untangled (36)
- # yada (11)
@mccraigmccraig Thank you so much for that component, it worked excactly as indended once I figured out what the arguments were. Do you want to answer that SO post and let me give you some magical internet points or would you allow me to publish a simplified version of your code as the answer?
@rovanion: publish at will :)
@mccraigmccraig You're very kind!
np @rovanion - all my projects are built on the open-source efforts of many others, which i am very grateful for - helping out a little is the least i can do in return
Hi hoping someone can help, I'm attempting to do something a little out of the ordinary. I want to create a component that renders a "hidden" anchor element. When the component loads I want to automatically trigger a click event on the components root DOM node. This is what I have so far:
(defn my-btn []
(reagent/create-class
{:component-did-mount
#(js/click (reagent/dom-node %))
:reagent-render
(fn []
[:a {:style {:display "none"}}])}))
Now this won't work because js/click
is not a function. Can someone advise on how I can achieve this?that's really a javascript question though, isn't it? How to programmatically generate click events?
oh. do you mean just .click
instead of js/click?
@pesterhazy yes looks likes that's what I need
Do you know how I could get reference to child elements within the component? Assuming the anchor was a nested element?
have a look at this technique: https://presumably.de/reagent-mysteries-part-3-manipulating-the-dom.html
reagent/dom-node is semi-depricated
@pesterhazy ok will take a look, thanks
you can attach refs to subnodes in your tree
@pesterhazy yeah was wondering about how to do React refs
@pesterhazy this is what I went with that is alot nicer than having to use the React lifecycle stuff:
(defn my-btn []
(fn []
[:a {:style {:display "none"}
:ref (fn [el] (when-not (nil? el)
(.click el)))}]))
Yup that works too
@pesterhazy thanks for pointing me in the right direction 🙂
:ref
is like a mini did-mount method 🙂
just have to remember that it's called when the component is destroyed too, except in this case the el
passed to the function is nil
.
Right
I usually use some->
Hi hoping someone can help. I have a higher order function that may accept either a Reagent component or a standard function as an argument. I want to invoke the supplied function with []
if it's a component and ()
if it's a standard function.
;; higher order function
(defn hof [f]
;; need to determine if f is a component
[f])
(defn my-component []
[:div "I'm a compnent"])
(defn not-a-component []
"I'm NOT a component")
;; I want `not-my-component to be invoked with ()'
(hof not-a-component)
;; I want `my-component to be invoked with []'
(hof my-component)
Is there any way I can determine if the supplied function is a component?