This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-03-03
Channels
- # admin-announcements (2)
- # beginners (18)
- # boot (118)
- # cider (12)
- # cljs-dev (12)
- # cljsrn (24)
- # clojure (142)
- # clojure-art (4)
- # clojure-bangladesh (3)
- # clojure-ireland (1)
- # clojure-italy (7)
- # clojure-norway (4)
- # clojure-poland (207)
- # clojure-russia (101)
- # clojurescript (108)
- # clojurewerkz (2)
- # core-async (6)
- # css (8)
- # data-science (23)
- # datomic (31)
- # devcards (2)
- # emacs (8)
- # funcool (25)
- # hoplon (34)
- # immutant (78)
- # ldnclj (7)
- # lein-figwheel (4)
- # leiningen (6)
- # luminus (35)
- # off-topic (1)
- # om (119)
- # onyx (43)
- # parinfer (29)
- # proton (11)
- # re-frame (25)
- # remote-jobs (1)
- # slack-help (1)
- # spacemacs (3)
- # yada (10)
When I pass the subscription ratom to reagent-forms bind-fields, it seems to be empty. If I conj something to it as shown, only the bit conjed in shows. If instead I pass the commented ratom, I get the original content plus the conjed bit.
I know the subs ratom is not empty because the :label before bind-fields always prints what I would expect...
Furthermore, if I log the reaction inside new-collection-form template, I can see it initially being nil (there’s an ajax call that populates it), and then filling up (presumably when the ajax call completes). So, now I’m even more baffled: if it logs correctly, why isn’t the for loop seeing it?
@hjrnunes try with [bind-fields [new-collection-form-template (conj @apps {:name "TEST APP"})] form]
(you want a vector instead of applying the component fn)
@nberger: thanks. Same result though. Anyway, my understanding from reagent-forms is that bind-fields doesn’t actually expect a component but a data structure that it will walk and wire-up to the form
the 'new-collection-form-template’ function isn’t supposed to be a component but only a template for the form
“The templates are eagerly evaluated, and you should always call the helper functions as in the example above instead of putting them in a vector. These will be replaced by Reagent components when the bind-field is called to compile the template."
“The bind-fields function expects a data structure as its input and walks it to find any elements with a :field attribute."
@hjrnunes how are you using reagent-forms with re-frame ? if you are using the app-db as the source of data for a view, that's not compatible with reagent-forms binding form fields into an atom - you would have to have separate atoms for the data backing the form fields ?
@mccraigmccraig: yep, I’m using a separate atom as per the reagent-form docs. I pass it’s content to a re-frame event handler via dispatch when its submit time
in snippet you can see it - it’s the “form” ratom. But I need to build that :select list with app-db data, which I’m getting via subscribe. But I can’t seem to be able to get to the subs data inside the form template, even though it still logs fine… 😩
I wonder if it has to do with rendering, because I can see the reaction updating via js/log
OTH, if the form isn’t re-rendering when the reaction updates, how come I see that js/log result in the console two times? One prints nil, the other actually prints the data I need. So it would seem to me that the component is actually being re-rendered, otherwise that log statement wouldn’t execute twice, right?
I'm trying to wrap my head around when re-frame will rerender components and when it wont (trying to internalize the lesson of https://github.com/Day8/re-frame#a-more-efficient-signal-graph).
I notice that, if one of my subscriptions is very simple: (re-frame/register-sub :name (fn [db] (reaction (:name @db))))
, if another part of the database changes, a component subscribed to :name will rerender (though (:name db)
didn't change). I can tweak that subscription reaction to this:
(re-frame/register-sub :name (fn [db] (let [name (reaction (:name @db))] (reaction @name))))
and indeed this prevents components subscribed to :name from rendering! But I wonder if this is the kind of optimization that the Reagent readme warns is not necessary?
(because, presumably, even though re-frame might re-render a component subscribed to :name, react won't write it to the DOM since it's not changed)
@fasiha: The render function itself is wrapped in a reaction, so if name doesn't change, the render function won't get called
@hjrnunes: @fasiha the best way to get a sense of what is happening (the flow), is to use clairvoyant in this manner: https://github.com/Day8/re-frame/wiki/Debugging
It is a small bit of work to setup, but then you can just watch the 4 domino pattern happening in the js/console