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" 🙏
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 "<http://smtp.gmail.com|smtp.gmail.com>"
:email "<mailto:myemail@gmail.com|myemail@gmail.com>"
: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?@mroerni, OK, I followed your example and it clarified it.
@holyjak and @mroerni, 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.
That is a big step, learning Clojure and Fulcro both at the same time. Best of luck!
@holyjak 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 ...
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!
@holyjak, well the key is LOVE! When you love something its easy, I look forward to waking up and working on it!!
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)
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.
It is more less just data. Add whatever you want. See how eg fulcro-template reads it.
There is little magic for reading values from env vars, good for passwords
@holyjak, 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?
What if you print the whole config?
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
How do you print the whole config?
(pprint config) Do you use REPL?
@timofey.sitnikov 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#L20From 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?
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?