fulcro

Book: http://book.fulcrologic.com, Community Resources: https://fulcro-community.github.io/, RAD book at http://book.fulcrologic.com/RAD.html
Jason Jones 2020-11-19T02:02:47.221900Z

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?

lgessler 2020-11-19T19:45:19.235500Z

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

2020-11-19T02:08:04.222Z

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

nivekuil 2020-11-19T02:10:49.222200Z

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 Jones 2020-11-19T02:38:44.222400Z

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?

nivekuil 2020-11-19T02:39:54.222600Z

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

nivekuil 2020-11-19T02:40:17.222800Z

fulcro often uses it for automatically namespace-qualifying symbols

nivekuil 2020-11-19T02:43:39.223100Z

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

nivekuil 2020-11-19T02:45:16.223300Z

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 Jones 2020-11-19T02:47:20.223500Z

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

👍 1
Jason Jones 2020-11-19T02:47:50.223700Z

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)

Henry 2020-11-19T11:24:04.228500Z

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

xceno 2020-11-19T13:10:53.228600Z

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

Henry 2020-11-19T14:53:45.229200Z

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.

xceno 2020-11-19T15:36:12.229400Z

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

👍 1
tvaughan 2020-11-19T19:34:47.235400Z

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

✅ 1
tvaughan 2020-11-20T11:18:15.240700Z

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

lgessler 2020-11-20T16:07:22.241Z

np! glad you figured it out

👍 1
lgessler 2020-11-19T19:48:35.235700Z

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

lgessler 2020-11-19T19:51:50.236100Z

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

lgessler 2020-11-19T19:52:19.236300Z

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

tvaughan 2020-11-19T19:53:05.236500Z

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

lgessler 2020-11-19T19:53:56.236700Z

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

tvaughan 2020-11-19T19:54:11.237Z

> 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

tvaughan 2020-11-19T19:54:51.237200Z

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

tvaughan 2020-11-19T19:55:28.237400Z

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

lgessler 2020-11-19T19:57:44.237600Z

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

tvaughan 2020-11-19T19:59:07.237800Z

Oh, no that has no effect

tvaughan 2020-11-19T19:59:27.238Z

Neither does resetting all properties to the same value

lgessler 2020-11-19T20:00:24.238200Z

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

lgessler 2020-11-19T20:00:44.238400Z

or wait am i misunderstanding...

lgessler 2020-11-19T20:04:13.238600Z

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

tvaughan 2020-11-19T20:05:21.238800Z

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

tvaughan 2020-11-19T20:06:06.239Z

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

lgessler 2020-11-19T20:07:29.239300Z

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)

tvaughan 2020-11-19T20:23:49.239500Z

Did that 🙂 The print statements aren't called

lgessler 2020-11-19T21:23:32.239800Z

ah so it is a render scheduling issue

lgessler 2020-11-19T21:23:53.240Z

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