fulcro

Book: http://book.fulcrologic.com, Community Resources: https://fulcro-community.github.io/, RAD book at http://book.fulcrologic.com/RAD.html
Gleb Posobin 2021-01-10T08:22:39.273800Z

How to understand when I need to set the initial state of a component and whether to use lambda for it? Example:

(defsc HomePage [this props]
  {:query         [{[:component/id :session] (comp/get-query Session)}]
   :initial-state (fn [p] {[:component/id :session] {}})
   :ident         (fn [] [:component/id :home-page])}
  (dom/span "Hi " (get-in props [[:component/id :session] :account/username])))

(def ui-home-page (comp/factory HomePage))

(defsc Main [this {:keys [home-page] :as props}]
  {:query             [{:home-page (comp/get-query ui-home-page)}]
   :initial-state     (fn [p] {:home-page (comp/get-initial-state HomePage)})
   :ident             (fn [] [:component/id :main])
   :route-segment     ["main"]}
  (dom/div (ui-home-page home-page)))
If I remove any of the two initial-state's, or change the second one to be a template {:home-page {}}, it doesn't work: the username in the HomePage component is not loaded: why? I also don't understand why I need to assign initial value in HomePage to [:component/id :session], even though it is an empty initial value which is supposed to be replaced with the value from the app db. Why doesn't the query to the app db to get [:component/id :session] happen if there is no initial value?

✅ 1
Toni Tuominen 2021-01-10T09:41:57.275400Z

I have a report that lists products. Products can have many tags (ref attribute). What's the proper way to have the report render the tag labels instead of the idents that it lists by default?

➕ 2
Jakub Holý 2021-01-10T16:46:34.275900Z

See https://book.fulcrologic.com/#_a_warning_about_ident_and_link_queries Your Main init state is wrong, pass in the class and not ui-... Use the template form unless you need to do something it doesn't support. Simpler, better errors checking

Gleb Posobin 2021-01-10T16:50:46.276100Z

Oops, sorry, I was trying out different things, same thing if I pass in the class.

Gleb Posobin 2021-01-10T16:51:19.276300Z

Wait, I do pass in the class in the init state, and not the factory.

Jakub Holý 2021-01-10T16:52:09.276500Z

(I would have hoped that https://blog.jakubholy.net/2020/troubleshooting-fulcro/#_frontend_fulcro would have guided you to the 1st answer)

Jakub Holý 2021-01-10T16:52:43.276800Z

Sorry, it's query that's wrong

Gleb Posobin 2021-01-10T16:53:35.277Z

I have tried going with the troubleshooting guide!

Gleb Posobin 2021-01-10T16:55:04.277200Z

Yeah, I was trying out random things, when it's a class same thing happens.

Gleb Posobin 2021-01-10T16:55:32.277400Z

The section you linked to explains this, thank you!

Gleb Posobin 2021-01-10T16:56:25.277600Z

I don't know why I missed the steps in the troubleshooting guide. Probably should have unfolded all (missed that link) and done Cmd-F for initial-state.

Jakub Holý 2021-01-10T16:57:40.277900Z

Please, go to the guide, click the Expand All link, search for " 6.8. A Warning About Ident and Link Queries" and tell what I can improve so that your younger I would have found it 🙏

Gleb Posobin 2021-01-10T17:01:35.278100Z

I think I went with the data in DB missing/wrong because it mentioned initial state.

Gleb Posobin 2021-01-10T17:02:07.278300Z

And the same thing happened with me again just now when I tried to find the section I knew I needed XD

Jakub Holý 2021-01-10T17:09:07.278600Z

But your data was actually correct, wasn't it? Was is XD?

Gleb Posobin 2021-01-10T17:10:07.278800Z

XD is a laughing face.

Gleb Posobin 2021-01-10T17:10:22.279Z

Well it wasn't being populated in the component.

Gleb Posobin 2021-01-10T17:10:30.279200Z

So there was no data.

Jakub Holý 2021-01-10T17:12:15.279400Z

Well, the data of Session was in the DB, it just did not show up in the HomePage UI,no?

Gleb Posobin 2021-01-10T17:25:15.279600Z

Yes.

Jakub Holý 2021-01-10T17:25:51.279800Z

Any suggestions for how to make the distinction between the two clearer so that folk would go down the right path?

Gleb Posobin 2021-01-10T17:26:27.280Z

Make steps unfolded by default so that people could Cmd-F?

Gleb Posobin 2021-01-10T17:27:13.280200Z

As I said, I missed the unfold all link.

Jakub Holý 2021-01-10T17:50:27.280400Z

The idea is that the questions should guide you to the answer though searching is certainly also a common use case. So I wanted to ask, how an I improve the question(s) so that you would not have gone down the wrong path?

Gleb Posobin 2021-01-10T18:10:33.281100Z

Well I guess when I am searching for a solution to a problem I try to skim as much as possible, and having to unfold all the points manually prevents me from that. I missed the explanation in 2. saying to go to the next section, plus when 2. is unfolded there is the initial state section, which seemed like the right section for me so I hadn't thought to look in the others. I would suggest adding the link to this initial state problem into the section 2. too, even though it doesn't strictly fall under it.

👀 1
Gleb Posobin 2021-01-10T18:16:42.281300Z

Maybe an additional section for people like me for reverse search? Like "if you are having problems with initial state, these are the possible reasons". Btw in this case, I initially didn't know what's happening at all, just randomly tried adding the initial state to the components at some point.

Jakub Holý 2021-01-10T20:13:54.281800Z

But you did not have a problem with initial state. Your only problem was that the data in the DB were not showing up in the expected UI. At leas that is how I see it. The idea with having everything collapsed is so that you see all the questions at the same level at once and can better decide which one matches best. (the mention to look at the next point I've added after our initial discussion)

Gleb Posobin 2021-01-10T20:21:02.282Z

I mean, sure, if you had magically told me that while I was on the page, I would have looked in the correct section.

Gleb Posobin 2021-01-10T20:22:11.282200Z

But we are talking about people trying to find an answer to their question. People are skimming, making mistakes, getting distracted, getting side-tracked, misunderstanding what's written.

Gleb Posobin 2021-01-10T20:22:43.282400Z

My philosophy is that everything should be written with that in mind.

Gleb Posobin 2021-01-10T20:23:06.282600Z

When you are traversing the tree, any mistake at any point will lead you astray.

Jakub Holý 2021-01-10T20:34:07.282800Z

These are good points. I will tru to add some cross-references. And I will think about how to help people ask the right questions / discard the wrong ones. Thank you very much for your inputs!!!