Fork me on GitHub

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...


Summing up: :label prints sub correctly, but :select in the form doesn't


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


hmmm I don't know much about reagent-forms, let me check it out...


“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: I'm lost there, sorry I can't help


@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


I just don’t know enough react/reagent to figure this out


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 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:


It is a small bit of work to setup, but then you can just watch the 4 domino pattern happening in the js/console