Fork me on GitHub
#fulcro
<
2020-02-15
>
cjsauer13:02:29

Hello 👋 I’m getting a bit confused reading through the mutation section in the developer’s guide regarding the difference between server-side use of pc/defmutation and fulcro’s defmutation; when should I reach for one over the other? Related, I believe there may be a typo in the “Demo mutation joins” section’s code example, which appears to use both forms simultaneously:

(pc/defmutation trigger-error [_ _]
  (action [env]
    {:error "something bad"}))

tony.kay16:02:00

Use Pathom when you’re using a pathom parser, which can be used on the client (i.e. wrapped in a virtual remote) or server. Fulcro no longer has a server-side defmutation. It is a macro for adding a multimethod dispatch on a symbol for client-side use…it is basically defmethod with some syntax checking and boilerplate reduction that also give code nav convenience.

cjmurphy17:02:06

Having an action inside a pc/defmutation is confusing and almost certainly a typo.

👆 4
cjsauer17:02:31

Cool, makes sense, ty

tony.kay16:02:24

So, I had an idea this morning that I just tried out that will be interesting to many people I think. I was inspired to think about the “floating root” idea that comes up at times when @mdhaney mentioned that he was using a js react lib that wanted you to pass in a class…obviously something that is going to be hard to adapt in Fulcro without the ability to “disconnect” the reified UI graph. It occurred to me this morning that it might be possible to do this without any internal changes to Fulcro at all, and in fact in less than an hour this morning I have a working demo. It is not fully optimized, and probably has a bug or two, but shows how simple it is to expand abilities. It is currently on a work-in-progres branch (in two files) here: https://github.com/fulcrologic/fulcro/blob/feature/multiroot/src/todomvc/roots/multiple_roots_renderer.cljc https://github.com/fulcrologic/fulcro/blob/feature/multiroot/src/todomvc/roots/sample.cljs Basically the idea is to plug in a custom renderer, which itself tracks and manages the extra roots (I used keyframe render 2 as a base, so you could have :only-refresh optimizations). Composing root queries and initial state is just data manipulation (the root query combination is necessary to get initial state to normalize…a complete implementation to do this would do alt root initialization on mount and eliminate that need in the custom renderer by detecting if the state was already there).

metal 20
tony.kay16:02:42

One hour. No customizations to Fulcro’s code. Floating roots.

Aleed18:02:40

for a local database (i.e. sqlite), do we need to create our own remote implementation, or does fulcro's mock-server-remote * serve this purpose?

currentoor22:02:18

no, that is for demoing things

currentoor22:02:32

a remote is super simple, just a map with a :transmit! key

currentoor22:02:06

but you can use that com.fulcrologic.fulcro.networking.mock-server-remote as an example of how to do a remote, given a parser

currentoor22:02:37

then with a pathom parser you would implement resolvers that perform operations on your DB

currentoor22:02:48

does that make sense?

Aleed22:02:31

yes it does, ty