This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-01-30
Channels
- # bangalore-clj (1)
- # beginners (104)
- # boot (207)
- # cider (173)
- # cljs-dev (157)
- # cljsjs (1)
- # cljsrn (51)
- # clojure (196)
- # clojure-berlin (1)
- # clojure-chicago (1)
- # clojure-italy (4)
- # clojure-new-zealand (1)
- # clojure-nl (1)
- # clojure-russia (28)
- # clojure-spec (17)
- # clojure-uk (73)
- # clojured (13)
- # clojurescript (110)
- # core-async (4)
- # datascript (25)
- # datomic (92)
- # editors (1)
- # emacs (157)
- # events (4)
- # hoplon (16)
- # klipse (74)
- # lein-figwheel (10)
- # leiningen (2)
- # lumo (13)
- # off-topic (78)
- # om (3)
- # om-next (3)
- # onyx (14)
- # protorepl (1)
- # re-frame (17)
- # reagent (23)
- # remote-jobs (1)
- # ring-swagger (33)
- # schema (2)
- # slack-help (3)
- # spacemacs (7)
- # testing (1)
- # yada (7)
again fighting with form-3
components, if I have:
(defn graph [clicked hovered attrs graph-data]
(log/debug "Init: clicked" clicked)
(log/debug "Init: hovered" hovered)
(log/debug "Init: attrs" attrs)
(log/debug "Init: graph-data" graph-data)
(r/create-class
{:display-name "graph-container"
:reagent-render graph-render
:component-did-update (fn [this] .....how do I get the individual props here? ...)
:component-did-mount (fn [this] .....or here? ...))
I tried:
(let [state (r/props this)]
(log/debug "graph-did-mount" state)
(graph! state))
and it indeed worked when I had one propbut now I have many (same passed to the rendered btw)
@richiardiandrea one of the ways to do it is the following
(defn component-form-3 [arg1 arg2 arg3]
(reagent/create-class
{:component-function
(fn [arg1 arg2 arg3] [:div])
:component-did-update
(fn [this]
(let [[_ new-arg1 new-arg2 new-arg3] (reagent/argv this)]
; do something
))}))
uhm interesting
let me try
(reagent/argv this)
inside :component-did-update
can be destructured into the same args as passed to the component + 1st argument will be something else
I am interesting in did-mount
as well, I am trying, a big thanks!
@kishanov works in did-mount
as well yes!
this definitely needs a blog post 😉
@richiardiandrea I started recalcictrant with this kind of difficulty in mind
oh cool interesting
if you use the "new-props" mixin, the function will simply get the (new) props as arguments, just like the render fn
reagent's handling of lifecycle methods is opaque, the goal is to make it a bit more transparent
the pattern you were looking for (do something both on mount and on update) is pretty common in my experience
yeah, I see that now with d3
re-com
components are smooth to use, this stuff is hard-core and not as simple as it should be
yeah you need form-3 components in a couple of scenarios
- XHR requests or other network activity like websockets (if you choose to tie them to the component) - timers - direct dom manipulation - resource cleanup - multimedia (canvas, webgl) - imperative web APIs (video)
luckily you can often stash away the side-effecting complexity in a wrapper Higher Order Component
yes the thing is that I need to re-render my d3 graph (direct DOM) on every mouse event