Fork me on GitHub
#fulcro
<
2021-12-10
>
Declan15:12:46

Hi - I'm seeing something that I don't fully understand and wondered if anyone can provide some clarity The context of this is that I'm playing around in a freshly cloned copy of fulcro-template. I'm calling transact! to communicate with a REST api and I'm getting a JSON response from the server I added a very simple response middleware to console log some details and can see the JSON string in the :body of the response My intention is to manipulate this JSON in the ok-action of the defmutation However, when I look at the :result key in the env in ok-action I can see the all the details of the response but the :body key is an empty map I tried removing my response middleware and even tried added some logging in the result-action of the defmutation and saw the same so.. would you expect the server response body to be empty in ok-action? maybe I'm looking for the server JSON in the wrong place? ..(I removed my result-action to restore the default behaviour).. as a temp workaround I find that if I duplicate the server JSON into a different key in the response middleware it is present in the ok-action but maybe I shouldn't need to do this.... .. thoughts welcome, happy to provide further clarification

Jakub Holý (HolyJak)17:12:35

I think you need a custom remote to use a REST api. Do you do that? There is surely an examine in the book...

Declan13:12:58

I've done a bit more digging My question relates to what is happening between response middleware and ok-action Because Fulcro, by default, is expecting to be talking to something like Pathom remotely, it's trying to merge the response, the JSON doesn't "match" and so the body of the response becomes an empty map (^^^ this is a summary of my understanding, not a description of what the code is actually doing...) I've gone back to the book and tried a few options but I haven't changed the behaviour Any tips then on how I might tell Fulcro not to try merging the response so that the :body key remains intact?

Declan14:12:08

have added a new reply to try to clarify my earlier question - thanks

dvingo16:12:25

Jakub provided the answer, remotes handle communication in fulcro apps - the remote in the template does not handle JSON over https - here is a sample pathom parser setup to do that: https://github.com/dvingo/my-clj-utils/blob/master/src/main/dv/fulcro_util.cljs#L578 - then you make http calls in your resolvers which return core.async channels

❤️ 1
Declan18:12:55

Thank you @U051V5LLP and @U0522TWDA for this and for sharing your repo - looks really useful I think I will need to come back to this - it does seem that using Pathom is the "correct" way It may not have been explicit but I had already created a new remote in my template code to handle the JSON (not sure about https yet..) and this is the context within which I was asking I'm doing some POC stuff around an existing backend and hoping that Fulcro (without GraphQL) will still be a good choice for a new frontend. I think I've got enough of this working for now to make progress and will climb the Pathom resolvers hill another day...

Jakub Holý (HolyJak)19:12:01

I think Fulcro filters out all that you do not query for => 1) make the json into Clojure data, 2) query for everything - add to you mutation st. like (remote [env] (m/returning env (rc/nc '[*]))) What does your remote look like? Do you use the mock-http-remote or the http-remote? Have you looked at https://github.com/fulcrologic/fulcro/blob/develop/src/main/com/fulcrologic/fulcro/networking/http_remote.cljs#L155 ?

Declan13:12:52

really grateful for your continued support I'm using fulcro-http-remote and wrap-fulcro-response as part of the response middleware I tried adding your "returning everything" query and also tried completely removing wrap-fulcro-response from the response middleware .. same result something happening in fulcro-http-remote, in the ok-routine*, probably the ok-handler At the risk of parading my ignorance, is there a mechanism for either adding logging to the fulcro library code or better still getting a old fashioned debugger with breakpoints? ... I should stress that this isn't a blocker for me - I'm just trying to better understand and follow how this code and library are working

Jakub Holý (HolyJak)14:12:08

I have this in my deps.edn :

:dev/fulcro     {:override-deps {com.fulcrologic/fulcro     {:local/root "/Users/me/fulcro-all/fulcro"}}}
(where I checked out Fulcro to /Users/me/fulcro-all/fulcro ) and if I run my repl with this alias then I can change Fulcro's code, e.g. to add println or log/info calls there or do any of the repl-driven-dev tricks

Declan14:12:59

fantastic - that's going to be enormously useful!!

dvingo14:12:37

You can also https://ptaoussanis.github.io/timbre/taoensso.timbre.html#var-set-level.21`(set-level! :debug)` to see the logging statements fulcro has in place already

Brandon Olivier15:12:15

What’s the right way to introduce a new component layer at the root of your UI tree? I’m doing todomvc, and I can’t figure out how to create a good query. My todos list is loaded at :todo-list but because there’s a new component, I can’t get todo-list from the root query, it needs to be in TodoList but then there’s no root node for Root to grab. What am I missing?

Brandon Olivier15:12:05

I can make the rendering work by passing the whole props map down to a layer in the UI tree, but it doesn’t that make my UI tree and query tree divergent? It feels wrong to me, but I don’t know enough to know if that’s bad for any reason

simonkatz15:12:11

Hi. I’m just getting started learning Fulcro. After I refresh my app web page, the DB in Fulcro Inspect is always empty. I have to close Chrome Dev Tools and re-open it, and then I can see my data in the DB. Is this normal?

simonkatz16:12:35

It turns out that if I update the database after a browser refresh, Fulcro Inspect updates and shows the DB contents.

dvingo17:12:45

the message sent to inspect happens when the app is mounted the first time, but not on code reload: https://github.com/fulcrologic/fulcro/blob/develop/src/main/com/fulcrologic/fulcro/application.cljc#L327

dvingo17:12:27

but having the devtools open and refreshing the page should work

simonkatz18:12:05

Hmmm. A refresh definitely causes an empty DB to be shown. Here’s a video: https://drive.google.com/file/d/11_JbWqwgkKm-EATQ1WGQNKZh1aWq9ug6/view?usp=sharing

dvingo22:12:06

if you right click on the inspector itself and Inspect that there may be an error there

simonkatz13:12:05

Indeed there is! Thanks.

simonkatz13:12:13

Here are the details: main.js:37898 DevTools tooltip root node not found; context menus will be disabled. (anonymous) @ main.js:37898 Qj @ main.js:17369 Gk @ main.js:18941 Dk @ main.js:18393 kg @ main.js:14190 Wk @ main.js:18802 Ok @ main.js:18743 Fk @ main.js:18320 J @ main.js:20007 R @ main.js:20044 main.js:4076 ERROR [fulcro.inspect.chrome.devtool.main:176] - Something was nil (anonymous) @ main.js:4076 (anonymous) @ main.js:4088 h.hc @ main.js:1837 Gd @ main.js:1526 ug @ main.js:1631 j5 @ main.js:4086 (anonymous) @ main.js:5543 (anonymous) @ main.js:1490 setTimeout (async) (anonymous) @ main.js:1490 Twb @ main.js:5538 axb @ main.js:5551 (anonymous) @ main.js:5556 n @ main.js:5554 yU @ main.js:2896 (anonymous) @ main.js:2896 (anonymous) @ main.js:2881 r8a @ main.js:2877 b.port1.onmessage @ main.js:2876

simonkatz13:12:36

This is with code created by following section 4.4 of the Fulcro Developers’ Guide (at https://book.fulcrologic.com/#_create_your_project)

Jakub Holý (HolyJak)17:12:42

Do you have the problem with https://github.com/holyjak/minimalist-fulcro-template-backendless? I don't => explore differences. If you do, try different browser

simonkatz11:12:31

@U0522TWDA Thank you. No problem with that repo. The difference is calls to app/set-root and dr/initialize in the client/init function.

Jakub Holý (HolyJak)14:12:50

This change should not matter. You don't need dr of you don't use it and mount does the same thing as set-root+ mount, just in 1 step

simonkatz16:12:19

@U0522TWDA It definitely makes a difference for me. 🙂 If anyone wants to try it: 1. Clone https://github.com/simon-katz/fulcro-app-from-ch4-of-the-book 2. Checkout the branch fix-fulcro-inspect-error (not necessary right now, because that’s the same as the main branch. 3. Compare the behaviour with and without the most recent commit. I get the same behaviour with both Chrome and Vivaldi.

simonkatz12:12:28

An update: I had the same problem with the early parts of the Fulcro 3 video series, but when I moved from Part 5 to Part 6 (using a server and removing :dev-http from shadow-cljs.edn ), the problem went away.

👍 2
roklenarcic16:12:01

do fulcro apps work with :advanced optimization enabled?

Björn Ebbinghaus17:12:42

Yes. Of course. 🙂