Fork me on GitHub
#fulcro
<
2018-01-07
>
rastandy15:01:02

hello everyone

rastandy15:01:59

I’m using Fulcro 1.2.0. I’m puzzled about how to trigger a load action inside a post-mutation. It seems like the load-action is queued but not performed until the next transaction.

rastandy15:01:40

It seems like the remote part of a post mutation is not called, so the “(df/remote-load env)” is never setup for remote calling

tony.kay19:01:01

@rastandy post mutations are for transforms only

rastandy08:01:28

Thanks for the very complete clarification. The need for a post-mutation arises for me because I’m using a custom client-side network component to manage requests to server rest api, but I think I’ll be able to do what you suggest in the response adapters I wrote. Thank you very much!

tony.kay19:01:33

the remote side is not checked…you’re post-merge, so they are not transactions, they’re just data transforms.

tony.kay19:01:36

You could use pessimistic transactions, in 2.x, but read on

tony.kay19:01:34

The Om Next model used in 1.x makes running transactions from the merge phase (which is where post mutations happen) not a good idea

tony.kay19:01:00

or consider this: why do you need one read to follow after another has finished??? If you can figure it out locally, then the server must also be able to do so if supplied the correct parameters

tony.kay19:01:29

so, you can make a singe round-trip by issuing both loads “at once”, but with parameters so the server can figure out how to constrain the “second” one

tony.kay19:01:31

You probably have logic like this: “Load X, then when I get that, look to see if I need Y…if so, load Y”…why not “Load X AND Y (with info about X, like the id of it)“…server uses parameters on load of Y to limit what gets returned.

tony.kay19:01:46

The abstraction is still spelled out on the client, but the filtering work is just done on the server. Also has the advantage of being easier to reason about. The client logic is synchronous, local, and linear (not chained through mutations), and the server logic is the same (local to Y, based on local parameters).

tony.kay19:01:17

Another approach is to define a query (via a query-only component that combines the final concern into the form you’d like) and parse that on the server to get back what you expect.

tony.kay19:01:43

lots of ways to do it without introducing async behaviors that are hard to track down and debug

tony.kay20:01:16

For anyone interested in true isomorphic apps with SSR using Nashorn (so js libs work): I’m working on a project and refined the development mode a lot more. I’m still refining it, but I’m ending up with something that works pretty well. The basics are: 1. Make the production build output to a .min.js file, and dev to just .js. 2. Run both a lein cljsbuild auto on production, and the figwheel on dev 3. Have the server use the .min build for SSR (required…nashorn can’t use the figwheel build) 4. Have the server modify the script tag so that in dev mode it sends a script tag for the figwheel code in index.html This lets the server-side render work during development, but still gives you figwheel hot code reload. I still need to make the server watch for timestamp changes on the .min file (to reset the Nashorn cached instance), but it’s working really well, and I’m using semantic UI React (js-only) lib with good results.

thosmos23:01:22

@tony.kay I'm interested in your SSR work. The following line https://github.com/fulcrologic/fulcro/blame/develop/DevelopersGuide.adoc#L9582 should be (map->ChannelListener {}) fulcro.websockets.components.channel_server.ChannelServer has a component dependency on :handler but no mention is made in the DevGuide about this. It'd be great if you could talk a bit about component dep keys and possibly the differences in ring handler needs between websockets and regular requests. I would do it, but I got a bit too confused between the different approaches in the full template and the websockets demo.

rastandy08:01:28

Thanks for the very complete clarification. The need for a post-mutation arises for me because I’m using a custom client-side network component to manage requests to server rest api, but I think I’ll be able to do what you suggest in the response adapters I wrote. Thank you very much!