Fork me on GitHub
#fulcro
<
2022-04-16
>
chrisbroome13:04:53

Following the instructions of the fulcro rad template at https://github.com/fulcrologic/fulcro-rad-template I ran the rename-project.sh script but it leaves behind a ton of files that end in -e (for example application.cljs-e. Is this expected?

chrisbroome13:04:33

ah looking at the script, sed’s -e option is specified after -i and (on a Mac at least) this makes it use -e as the backup file extension

chrisbroome13:04:08

looking at the man page, I think we want to change it to sed -i '' -e "s/com.example/$1/g" $f instead. Guess I can open a PR for that 🙂

❤️ 1
Jakub Holý (HolyJak)17:04:31

Yes, the differences between mac and Linux versions of common programs have bitten me multiple times 😔

👍 1
roklenarcic20:04:34

I’ve got a problem with tempids that I don’t know how to solve. The issue basically is that I cannot map tempids in mutation parameters to their new values. The default-result-action! will run after each mutation in transaction and it will call rewrite-tempids! which will take mutation’s tempid->real-id map and change tempids to resolved IDs in TX queue (changing mutations that haven’t been sent to remotes yet) and changing state. That’s all well and good, but there’s one place this is missing. The mutation’s parameters. You can see example here in this patch: https://github.com/fulcrologic/fulcro-rad/commit/0584baee90cb3d593bbf3e3d108fa3eac296e2d6 This is the save-as-form mutation, and I had to apply this fix, because ok-action closes over root-ident which might contain tempid. It will get mapped to real ID server-side, but I had to manually fix the closed over values, so they contain new ID instead of tempid. Now I have a more complex example, a transaction with 2 mutations:

(let [id (tempid/tempid)
        invoice (merge {::m.invoice/id id} some-val]
    (comp/transact! component [(form/save-as-form {:root-ident (comp/get-ident InvoiceForm invoice) :entity invoice})
                               (add-invoice-to-list {:id id})]))
Both mutations take an ident with tempid with it and both close over it. save-as-form saves it and maps tempid to a new ID. But the second mutation, which adds the ident to a list of invoices somewhere will always insert the old value, ident with tempid. That transaction also has no access to tempid->real-id mapping that happened in save-as-form so I have no way of fixing that temp ID. So I am at a loss of how to carry temp-id->real-id information from the first (inserting) mutation to other mutations in tx that also operate with same temporary ident.

tony.kay21:04:00

OK, I have an open issue on this as an unverified bug. I have not had time to make a minimal repro case and look into it. https://github.com/fulcrologic/fulcro/issues/509 . Are you plugging any custom stuff into the internals of Fulcro? Tx processing? Changing default mutation handler? Changing load mutation?

tony.kay21:04:32

In the case above, is add-invoice-to-list a local-only mutation? If so, it should have applied before the return value (because optimistic stuff runs immediately). If it is remote, then the values in the params on the remote should have been rewritten for you. Did you look at the network logs in this case?

tony.kay21:04:43

Oh…ok…I think I see what you’re saying. BOTH mutations are remote, but the remapping happened for the first one, the network request for the second one was fine, but no remapping map was available in the remote result handler of the second? I kind of need clarification there: as in, the code definition in Fulcro for the second mutation.

tony.kay21:04:03

I found a typo that might be the culprit. Try 3.5.19-SNAPSHOT (commit 16f1ad6f63864454f0cb43702fc4cbcdb7e04fbb)

tony.kay21:04:19

You should not have to be doing any manual remappings on these.

roklenarcic18:04:34

Hm, so I see what you mean, if the mutation 2 in transaction is local only then the temp ID will get replaced in app state since it runs before the remote action of mutation 1. But what if transaction is pessimistic? And if mutation 2 is remote then it will get replaced in the remote queue? That logic still misses the ok-action, it’s why save-as-form needed that patch, it used the old ident values.

roklenarcic19:04:00

And I tested it just now… the second mutation remote part doesn’t get its parameter tempid updated

roklenarcic19:04:17

So this is quite broken

roklenarcic19:04:01

Fulcro inspect shows that both mutations are sent to remote at the same time, so of course the resolver for the second one still gets tempid in parameter

tony.kay23:04:54

Right, actually that can't be any other way. If you send one transaction then you are responsible on the server to make it make sense. If you send 2 transactions then it will work fine

tony.kay23:04:38

Fulcro does no server side logic because it has no idea what you back end actually is

tony.kay23:04:26

It doesn't even know if you're using pathom or some hand written thing

roklenarcic10:04:24

Ok so the solution is to use a single mutation then or multiple transactions. But how do I reuse/extend existing mutations? Basically I have save-as-form mutation that does most of what I want, but I also want to add the item to some list of entities. I’ve added a mutation to tx for this purpose but as seen, the tempid logic doesn’t link up. What's the expected solution for this user story?

tony.kay13:04:06

Save as form has a server side helper that you can compose there.

roklenarcic07:04:06

But it also has client side logic in remote section, so I have to copy paste that. Seems to be a gap there in capability, on the client side it’s not possible to augment ok-action of a mutation to queue another tx without changing the code of the mutation itself. I cannot specify “if this mutation finishes successfully, do this other mutation” at the transact call site. ok-action is hardcoded in the first mutation. This very much limits composability of simple mutations. Back to replacing tempids in queues. I’ve tried to use pessimistic tx and it sent each of these 2 mutations to backend separately, but the second one still didn’t have tempid replaced with the result of the first one. So that tempid replacement in tx queues doesn’t seem to be working.

tony.kay19:04:30

Did you use the SNAPSHOT version of Fulcro I mentioned? They should get rewritten if you’ve used two transactions. I don’t think 2 transacts get auto-combined in the current logic…did that turn into 2 network requests?

tony.kay19:04:53

The two separate requests is the ONLY way that Fulcro can solve this for you

chrisbroome22:04:56

Might be better to ask this in the #cursive channel, but I have warnings all over my IDE for defstate and things that involve it. I’ve seen in the fulcro videos where Tony Kay says to map it to a previous version of fulcro to get it to work, but I don’t have anything like that in my options for the “Specify…” context menu. So then I tried vscode and calva, but it only lets you run 1 REPL by default unless you set up multiple workspaces which I don’t really want to do. So, my question is, going from a fresh IntelliJ Ultimate and a paid version of Cursive, how do I get all the Fulcro macros to resolve correctly?

tony.kay00:04:09

CLick on the macro name (e.g. defstate) and press CMD-SHIFT-A and type “resolve as”. Pick def. For defsc pick defn, etc.

tony.kay00:04:39

Some things have built-in support in Cursive, and everything else you have to tell it what the macro in question is “acting like”

markaddleman00:04:14

There is a problem with recent versions of cursive where it will forget the "resolve as" settings. The work around us to resolve as None and then resolve as to the appropriate definition

👍 2
tony.kay00:04:03

Try the latest EAP. There was a problem with new ns parser. Seems fixed there

👍 2
chrisbroome00:04:47

awesome. thanks for the help

chrisbroome00:04:51

i have the latest EAP 🙂

chrisbroome01:04:08

After going through each file, here’s what I came up with for the “resolve as” settings (had to export to XML to get it in a text-based format):

<ClojureResolveScheme>
  <item key="com.fulcrologic.fulcro.routing.dynamic-routing/defrouter" resolves-as="clojure.core/defn" />
  <item key="com.fulcrologic.guardrails.core/>defn" resolves-as="clojure.core/defn" />
  <item key="com.fulcrologic.rad.attributes/defattr" resolves-as="clojure.core/def" />
  <item key="com.fulcrologic.rad.blob/defblobattr" resolves-as="clojure.core/def" />
  <item key="com.fulcrologic.rad.form/defsc-form" resolves-as="clojure.core/defn" />
  <item key="com.fulcrologic.rad.report/defsc-report" resolves-as="clojure.core/defn" />
  <item key="com.wsscode.pathom.connect/defresolver" resolves-as="clojure.core/defn" />
  <item key="mount.core/defstate" resolves-as="clojure.core/def" />
  <item key="mount.tools.macrovich/deftime" resolves-as="clojure.core/do" />
  <item key="taoensso.encore/if-let" resolves-as="clojure.core/if-let" />
  <currentScheme>IDE</currentScheme>
</ClojureResolveScheme>
The mount.tools.macrovich/deftime definition was a tip from a cursive github issue.

👍 2
pserrano19:09:05

Thanks, this thread was very useful.

👍 1
chrisbroome22:04:07

If it helps, I’m starting from a cloned https://github.com/fulcrologic/fulcro-rad-template repo (hence my comments earlier today about sed )