I’m working through the fulcro tutorial and a bit confused by the code below
(defn person-path [& ks] (into [:person/id] ks))
What does the ‘&’ mean in this context? If I call this function with something like
(swap! state assoc-in (picker-path :person-picker/selected-person) [:person/id id]))
what exactly is the picker-path function doing?I recommend clojure for the brave and true's chapter on macros for grokking syntax quote and friends: https://www.braveclojure.com/writing-macros/
The &
is a rest parameter in Clojure, which just means that ks
can be any number of parameters.
specifically ks
is a sequence, the same as a backtick quoted list, and in that code it's being concated into a vec that already has one item in it
Thank you for clarifying. I did look-up “&” in the clojure cheatsheet but didn’t find mention of it. Appreciate your help. Do you mind to explain significance of backtick quoted list? is it different than single quote? In the tutorial, for example, I’ve seen things like (or load-mutation
internal-load!)` which is is invoked like (comp/transact! app
[(load-sym mutation-args)])` Is the ~ used for named parameters like in ReasonML?
sure, it's kind of a funky clojurism. It's technically called syntax quoting: https://clojure.org/reference/reader#syntax-quote
fulcro often uses it for automatically namespace-qualifying symbols
is for escaping a form within a syntax quoted list. recall that parens are "overloaded" in lisp to mean both a list and a function call: when you want a list rather than a function call you have to quote the list, and if you want some things in that list to be evaluated instead of literally returned, you use
you don't usually want lists in clojure, we use vecs instead. but lists are used sometimes in EQL syntax (refer the fulcro book, it really is more of a book that you read sequentially, than a reference)
That was a helpful link and your comments above also helpful. Thank you.
user=> (*def*
*x* 5)
user=> (`def` *lst* '(a b c))
user=> `(fred x x lst @lst 7 8 :nine)
(user/fred user/x 5 user/lst a b c 7 8 :nine)
While going through the fulcro-rad-tutorial using Cursive, the "find usages" action sometimes does not work (not showing usages when there are indeed usages). Have anyone experienced the same issue? Wonder if this is a fulcro issue or a cursive issue...
Must be a cursive issue, I have to re-index certain macros every 2 hours or so. Couldn't figure out what the problem is yet
Thanks for letting me know. Yes, I guess this is a cursive issue, so I also asked in the cursive channel. FYI: I found that the issue I encounter only exists in CLJC files and only pertains to the find usages and navigation actions of the namespaces inside (:require ...). A temporary solution I found: for CLJC files, put all required namespaces inside of reader conditionals (#? or #?@) and the actions should work properly.
Well that explains a lot! I mainly use CLJC files. Thanks a lot, I'll give it a try!
I'm modifying the properties of a component via the global state atom in the ok-action of a transaction, and everything works until I modify a property that is prefixed with :ui/
, like :ui/selected?
. I can see in the inspector that the value I set is in the database, but nothing is re-rendered. If I change something like :team/name
then the component is re-rendered, and the change to the :ui/
property is ignored. I've been able to change the values of :ui/
properties before similar ways. Any clue why it's not working this time? The value I'm writing is a map, if that's relevant. I would use computed properties but I don't know if these can be changed after they've been set
I figured it out. I had another component that was also changing this property. If I remove that, things work as expected. Sorry to have distracted you with this @lgessler. Thank you for your help
np! glad you figured it out
some "is your computer plugged in" questions first since that's all I can think of... are you sure that everything in the relevant component(s) has the :ui/
prefix? I think I've made similar mistakes in the past where I updated it in the props but not in the query, etc
a diagnostic would be to force a re-render, maybe by remounting your entire app (app/mount! app Root "app")
if you get the new value after a forced re-render then that'd be indicative of a rendering issue and probably? rule out a problem with your component
Yup. When I mount the component, e.g. (u-team-name props)
, props contains :ui/
and renders correctly. What's not happening is the re-rendering when this changes
a cheap way of forcing a re-render, assuming a std configuration: you can just make an inconsequential code change after your mutation is run and i think you ought to have your re-render
> after a forced re-render
How do I do this? Adding :refresh
to the transaction won't work because at the time the transaction is called I don't know the ident of the component that will need to change
> you can just make an inconsequential code change Oh, right. I was about to try this. Good idea
I mean instead of changing just one prop, I can reset all of them
I think even just adding a newline and saving ought to do it
Oh, no that has no effect
Neither does resetting all properties to the same value
what's your refresh function look like? it ought to look something like this
(defn ^:export refresh []
(log/info "Hot code Remount")
(log/merge-config! log-config)
(comp/refresh-dynamic-queries! SPA)
(app/mount! SPA root/Root "app"))
or wait am i misunderstanding...
one last thing that comes to mind for this: you could try different render middlewares to see whether it's a rendering issue https://book.fulcrologic.com/#_render_middleware
Hmm. I hadn't looked at that. I'll take a look. Thanks
Everything appears as though it should work. I can see the changes I make to the components props in the inspector. Yet things don't re-render. But they do when I change a non :ui/
prop
this is probably not what's going on, but in case the inspector's display is inaccurate you could also put some printlns in the body of the render method to check out your props (and also know when a re-render is happening)
Did that 🙂 The print statements aren't called
ah so it is a render scheduling issue
setting :shouldComponentUpdate
to (constantly true)
might help figure some things out