fulcro

Book: http://book.fulcrologic.com, Community Resources: https://fulcro-community.github.io/, RAD book at http://book.fulcrologic.com/RAD.html
zilti 2020-10-09T13:01:48.213600Z

Is there a relatively straightforward way for :will-enter to pass data to the component?

fjolne 2020-10-11T09:02:11.244700Z

@zilti sorry for late response; :initial-state applies only once, on the app startup, to form the initial state, so it won’t affect any changes done in :will-enter; i assumed you asked whether there’s something easier than making a custom mutation and transacting it from dr/route-deferred, which is always an option; swap! should also be done in dr/route-deferred callback fn

zilti 2020-10-11T09:23:57.248400Z

Oh, I see! Yes, that makes sense, I think I will use swap! inside route-deferred then in that case. Thanks!

1👍
zilti 2020-10-12T09:53:08.263700Z

Well, that did not work... I tried it like this:

:will-enter          (fn [app params]
                          (dr/route-deferred [:component/id ::CompanyRegistrationForm]
                                             (fn []
                                               (swap! (::app/state-atom app)
                                                      assoc-in [:component/id ::CompanyRegistrationForm]
                                                      (company-registration-form-prefill params))
                                               (comp/transact!
                                                app
                                                [(dr/target-ready {:target [:component/id ::CompanyRegistrationForm]})]))))
And all I get is an empty form together with an ERROR [com.fulcrologic.fulcro.algorithms.form-state:?] - FORM NOT NORMALIZED

tony.kay 2020-10-12T12:06:43.264200Z

@zilti you still have to make a normalized db. I would never swap! on state atom in UI code. ever. It’s just bad practice, and is what mutations are for. Write a mutation that sets the thing up correctly and use that instead. The error is because you’re trying to swap a tree into place where you should have normalized stuff. You could use merge-component! instead of a transaction (which will also normalize the data properly), but beware that will overwrite the entire form with the new data (which may be ok)

zilti 2020-10-12T12:34:46.264400Z

Okay. But where do I get the component from? Since I'm in :will-enter there's no component yet, right?

zilti 2020-10-12T12:50:42.264600Z

I replaced the swap! statement with

(fa.merge/merge-component!
                                                app CompanyRegistrationForm
                                                (company-registration-form-prefill params))
But that still gives me the "FORM NOT NORMALIZED" error

zilti 2020-10-09T13:12:28.214Z

In this specific case, I want to pass URL parameters to the component

Otis van Duijnen Montijn 2020-10-09T14:02:01.216700Z

Does anyone know if it's possible to somehow print the inactive states of a UI state machine that's in a running application? Only the active state gets stored in the database...

exit2 2020-10-09T15:36:17.217400Z

This approach used to work with FC2 (I think). But I can’t seem to get it working w/ FC3 and the new router. Any ideas? https://gist.github.com/njj/8aab3a5208d8a9bb7ebaec388ea6803d

exit2 2020-10-09T15:36:29.217700Z

core.cljs:159 ERROR [com.fulcrologic.fulcro.routing.dynamic-routing:185] - com.fulcrologic.fulcro.routing.dynamic-routing/target-ready should route to [:component/id :listing] but there is no data in the DB for the ident. Perhaps you supplied a wrong ident?

tony.kay 2020-10-09T16:48:50.218900Z

@njj you did not compose the route in question to root with respect to initial state (or didn’t place the target in state if this was a later stage route). It’s telling you exactly what is wrong: That component has no data in the database.

Jakub Holý 2020-10-10T10:16:05.229Z

no, I do not think it is "reserved" in any way

Jakub Holý 2020-10-10T10:17:09.229200Z

Good, yes, I suspected that a proper :target was missing from the load. I would call the attribute perhaps :listing/current or active or st. along the lines...

1👍
exit2 2020-10-10T13:25:02.231300Z

@holyjak thats my thoughts as well, basically there are many listings but the user can select which one they are working on - I was thinking of making the component :component/id :listing-details then doing just :listing for the active one, and then :siblings for the others. Naming is hard 😄

Jakub Holý 2020-10-10T14:46:21.231500Z

It is :)

exit2 2020-10-09T17:09:09.219Z

I see… I’ve made it one step further where I can now see the data loading into listing/id by changing the component in the df/load to be ListingForm and adding {:root/listing {}} to the initial-state but now I’m getting the classic ident ([:listing/id nil]) has a nil second element warning - should my query be something different for Listing? (also I’ve updated my gist for reference)

tony.kay 2020-10-09T17:54:16.219400Z

your ident on a component like that should likely be (fn [_] [:component/id :listing]), not a shorthand

Jakub Holý 2020-10-09T17:57:56.219600Z

Look at the data in the DB, is anything missing? E.g. :component/id :listing :root/listing? It looks wrong but I cannot point at where exactly :) Where/when do you get the error? Is it because props passed to Listing Form are nil or...?

tony.kay 2020-10-09T17:58:54.219900Z

@holyjak the indicator here is that he’s getting nil for the id, indicating he’s using :ident [:component/id :listing] instead of what I said…there is no :component/id prop in his initial state

tony.kay 2020-10-09T17:59:33.220100Z

but he’s got a singleton from the naming, which does not need to have an id in props…that’s just pointless overhead. But you have to use a lambda to get a constant for an ident

tony.kay 2020-10-09T17:59:40.220300Z

the other two notations are shorthand that always try to get ID using something from state

Jakub Holý 2020-10-09T19:24:03.220700Z

I got confused b/c the Listing component already has :ident (fn [_] [:component/id :listing]). But you were perhaps speaking about the child component Listing Form, that currently has the shorthand :listing/id, right?

fjolne 2020-10-09T19:30:13.225500Z

(swap! (::app/state-atom app) assoc-in [:comp/id :smth :ui.route/data] data) as long as you don’t need re-render or transaction semantics i believe it’s safe to do whatever you need with the state

Jakub Holý 2020-10-09T19:32:11.225700Z

@njustice It's weird to me to have the singleton component Listing with a non-static route and loading a single non-static child. I'd merge the 2 components into one with the shorthand :listing/id ident and the :will-enter loading its Id-dependent data

zilti 2020-10-09T19:33:22.225900Z

Hmm, I guess that'd get overwritten by :initial-state?

exit2 2020-10-09T19:34:30.226800Z

there will be many listings at some point, just working out the basics right now

exit2 2020-10-09T19:34:42.227400Z

I got it working... I can share it when I get back to my computer

1🎉
tony.kay 2020-10-09T19:47:49.227700Z

route parameters sent to change-route will show up in will-enter

tony.kay 2020-10-09T19:48:33.227900Z

from there you could do a deferred route and transact it in

exit2 2020-10-09T20:11:54.228100Z

@holyjak heres the updated the gist https://gist.github.com/njj/8aab3a5208d8a9bb7ebaec388ea6803d

1🎉
exit2 2020-10-09T20:21:46.228300Z

although… now I see that making it root/ is kind of weird so I’ll mostly like they change it to to something like active-listing

exit2 2020-10-09T20:22:15.228500Z

I assuming root/something query is reserved for queries w/in the Root component