Fork me on GitHub
#fulcro
<
2021-04-19
>
Jakub Holý (HolyJak)10:04:40

Hello! I seek feedback on a new section added to my "When UI Components and Data Entities Diverge", titled "https://blog.jakubholy.net/2020/fulcro-divergent-ui-data/#_accessing_top_level_data_from_a_nested_component" 🙏

Luis Thiam-Nye19:04:37

I think it is well presented 👍. The key takeaway I got from it is that it is best practice not to be querying for ident tables directly (eg :friend/id but rather maintain a separate list :all-friends). That would solve some of my problems. But what if all friends were not needed and instead it was desired to display a filtered view? Would you still populate :all-friends with all the friends, and then do the filtering and/or sorting in the MyFriends component?

Timofey Sitnikov11:04:40

Good morning! How do I add and use a configuration in config/defaults.edn? for example, I want to add the following configuration:

:server-components/auth-email/config {:host  ""
                                       :email ""
                                       :pass "my-password"
                                       :port 587}}
Then I have a namespace server-components/auth-email and in that namespace, I would like to use the configurations in that namespace, do I need to declare a keyword config ? How do I get these configs to use them?

Jakub Holý (HolyJak)11:04:28

It is more less just data. Add whatever you want. See how eg fulcro-template reads it.

Jakub Holý (HolyJak)11:04:22

There is little magic for reading values from env vars, good for passwords

Timofey Sitnikov12:04:11

@U0522TWDA, how would I access that data? Its probably super obvious, I try to do this: (pprint (get config :host)) but I get a null. Should I read it through `(defstate config ...) ? Or is there already a variable that has already loaded configurations from the file?

Jakub Holý (HolyJak)12:04:04

What if you print the whole config?

Jakub Holý (HolyJak)12:04:45

Also config is just a nested map = the EDN. So you must ask for the key you used there, :server-components... It does not know or care which ns you call it from

Timofey Sitnikov14:04:07

How do you print the whole config?

Jakub Holý (HolyJak)14:04:08

(pprint config) Do you use REPL?

Björn Ebbinghaus15:04:57

@U012GN57FJ9 When you follow the template: config is mount/defstate It is a singleton you can just require.

(ns whatever.server-components.auth-mail
  (:require
    [whatever.server-components.config :refer [config]))

(println config)
(println (:auth-mail config))
I added a rudimentary email service to my app two weeks ago: https://github.com/hhucn/decide3/blob/master/src/main/decide/server_components/email.clj#L40 https://github.com/hhucn/decide3/blob/master/src/main/config/prod.edn#L20

☝️ 2
Jakub Holý (HolyJak)16:04:27

From the point of repl, once your app started / mounted, it is just a var containing data, isn't it? So you can just look at it in the REPL. Does it look as you expect or not?

Timofey Sitnikov22:04:46

@U0522TWDA and @U4VT24ZM3, sorry for the late response, I can only work on Clojure during certain times 😞. OK, yes to @U0522TWDA, that is exactly right.

Timofey Sitnikov22:04:54

@U4VT24ZM3, OK, I followed your example and it clarified it.

Timofey Sitnikov22:04:28

@U0522TWDA and @U4VT24ZM3, as I am going through the journey of learning Clojure and Fulcro, I keep getting tripped up by little stuff like this. This is completely unexpected to me, but the config/defaults.edn is 100% Fulcro thing and it is basically handled by the com.fulcrologic.fulcro.server.config namespace. I did not catch that and that is why I was confused, but I was not asking you the right questions because I did not know from which angle to approach it, it looked magical to me. It is now super clear, but it was super hard to find the right chain to analyze and things like these make it challenging when learning Clojure. So, thank you for helping me to get to the bottom of it.

Jakub Holý (HolyJak)09:04:09

That is a big step, learning Clojure and Fulcro both at the same time. Best of luck!

Timofey Sitnikov10:04:52

@U0522TWDA you are not kidding me, but I have a hard time learning things that I do not use. So I wake up at 4:30 every morning, have my coffee and start learning Clojure till about 7:30. Then I exercise and then I start my work little past 8. Sounds crazy, but I love it ...

Jakub Holý (HolyJak)11:04:41

Incredible! I am a little afraid that you have bitten a little too much of the cake all at once but it is not up to me to judge 🙂 I hope you will do well!

Timofey Sitnikov13:04:39

@U0522TWDA, well the key is LOVE! When you love something its easy, I look forward to waking up and working on it!!

❤️ 3
Jakub Holý (HolyJak)13:04:49

Just remember that Clojure is as much about way of thinking and way of working (REPL-driven dev), if not more, than the language (listen to my recent podcast on the topic, if you want #news-and-articles)

Timofey Sitnikov13:04:18

Definitely! I use vim-iced and it is awesome, my source files become REPL, so I can execute lines inside (comment ...) blocks. I can type multiple-lines of commands, execute them, edit them, very powerful.