Fork me on GitHub
#fulcro
<
2020-11-19
>
Jason Jones02:11:47

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?

Buidler02:11:04

The & is a rest parameter in Clojure, which just means that ks can be any number of parameters.

nivekuil02:11:49

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

Jason Jones02:11:44

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?

nivekuil02:11:54

sure, it's kind of a funky clojurism. It's technically called syntax quoting: https://clojure.org/reference/reader#syntax-quote

nivekuil02:11:17

fulcro often uses it for automatically namespace-qualifying symbols

nivekuil02:11:39

￱ 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 ￱

nivekuil02:11:16

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)

Jason Jones02:11:20

That was a helpful link and your comments above also helpful. Thank you.

👍 3
Jason Jones02:11:50

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)

lgessler19:11:19

I recommend clojure for the brave and true's chapter on macros for grokking syntax quote and friends: https://www.braveclojure.com/writing-macros/

Henry11:11:04

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...

xceno13:11:53

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

Henry14:11:45

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.

xceno15:11:12

Well that explains a lot! I mainly use CLJC files. Thanks a lot, I'll give it a try!

👍 3
tvaughan19:11:47

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

3
lgessler19:11:35

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

lgessler19:11:50

a diagnostic would be to force a re-render, maybe by remounting your entire app (app/mount! app Root "app")

lgessler19:11:19

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

tvaughan19:11:05

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

lgessler19:11:56

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

tvaughan19:11:11

> 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

tvaughan19:11:51

> you can just make an inconsequential code change Oh, right. I was about to try this. Good idea

tvaughan19:11:28

I mean instead of changing just one prop, I can reset all of them

lgessler19:11:44

I think even just adding a newline and saving ought to do it

tvaughan19:11:07

Oh, no that has no effect

tvaughan19:11:27

Neither does resetting all properties to the same value

lgessler20:11:24

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"))

lgessler20:11:44

or wait am i misunderstanding...

lgessler20:11:13

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

tvaughan20:11:21

Hmm. I hadn't looked at that. I'll take a look. Thanks

tvaughan20:11:06

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

lgessler20:11:29

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)

tvaughan20:11:49

Did that 🙂 The print statements aren't called

lgessler21:11:32

ah so it is a render scheduling issue

lgessler21:11:53

setting :shouldComponentUpdate to (constantly true) might help figure some things out

tvaughan11:11:15

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 @U49U72C4V. Thank you for your help

lgessler16:11:22

np! glad you figured it out

👍 3