Fork me on GitHub
#fulcro
<
2020-10-06
>
zilti01:10:53

I am trying to implement a settings page with a separate router. Are there any examples in the wild? I noticed I can't just use a router, because when I do, the query won't be merged and thus the sub-routed component won't have any of its queried (and loaded) data available in props.

tony.kay01:10:49

nesting routers is supported...not sure what you’re doing that is confusing you. You have to compose queries and initial state (though defrouter does that for you for a router itself). I think the book itself shows such a nesting, doesn’t it?

zilti02:10:20

It does indeed, and the helpful code is confusingly under "http://book.fulcrologic.com/#_setting_the_route_early" but yes, it works now 🙂

zilti01:10:31

There is a http://book.fulcrologic.com/#_code_splitting but I have no idea how one'd combine that with a router

njj01:10:16

How does Fulcro support a basic index route? I tried :route-segment [""] but that doesn’t seem to work with the back button

zilti01:10:16

You can't give it an empty route segment. You have to put something there. You can then give app/fulcro-app the key :client-did-mount which takes a function. I have (fn [app] (hist5/restore-route! app ui/LandingPage {}))

tony.kay01:10:03

if you want a “/” route you do that in your own function to translate between what you think of as a URL and the actual target…just like you would in a normal web serving env…`/` never names a resource. It’s a directory. So, if you were translating from a URL of “/” you’d have a fn in between URL and dr that would “alias” / to mean something like ["index"]

👍 3
njj01:10:37

core.cljs:159 ERROR [com.fulcrologic.fulcro.routing.dynamic-routing:636] - Could not find route targets for new-route []

AJ Snow05:10:44

I've been able to get mutations to alter behavior within a single component, but now I need set up an :onClick mutation in some component X that changes some part of the state in another component Y. Anyone know where I can get more info on that? I'm probably going to start by rereading section 9 in the book.

cjmurphy06:10:25

From a client mutation you have the whole of app state. Start off with swap!->

[com.fulcrologic.fulcro.algorithms.normalized-state :refer [swap!->]]
, and do assoc-in or call st->st* functions.

AJ Snow03:10:19

That's what I suspected, but initial attempts weren't working. I will look into this, thank you!

tvaughan13:10:28

Per http://book.fulcrologic.com/#_defining_remote_errors, I'm trying to handle server error responses, e.g. 401 responses. I have a fallback mutation on my transactions (e.g load!) which I do see is being called, however the params :status-code passed to this fallback mutation is 500, not 401 (which is the HTTP response code returned by the server). This is v3.4.2-1. What am I doing wrong? What do I need to do so that :status-code matches the HTTP response code?

tony.kay13:10:12

@tvaughan you might not be doing anything wrong…it could just be a mistake in the middleware copying the status code. I would not, in general, use status codes for error handling in Fulcro. Period. Assume a non-200 is a bug or network failure. Error handling makes a lot more sense to do as proper mutation return values.

tony.kay13:10:35

this is different than what you might be used to from the REST world, but this is a different beast. It’s more like remote method invocation…an error means something went horribly wrong with the comm-layer (or a bug happened) such that the mutation was simply not able to even respond properly.

tony.kay13:10:18

however, I do think the “raw” response is still in env, so look deeper into what you got

tvaughan13:10:17

> I do think the “raw” response is still in `env` A quick scan and I don't see it. Will continue to look. I don't follow that HTTP responses shouldn't be used to detect "errors." There could be a lot of things in front of a remote resolver or mutation that could intercept a request and send a response. Even in the RPC over HTTP world response codes aren't ignored. I'll see what sort of work arounds I can come up with. Thanks for the quick response!

tvaughan14:10:41

:status-text is Unauthorized. Using this seems to work

njj19:10:42

Any advice on getting rid of this warning?

njj19:10:43

core.cljs:159 WARN [com.fulcrologic.fulcro.ui-state-machines:215] - Attempt to get an ASM path [:com.fulcrologic.fulcro.ui-state-machines/local-storage :path-segment] for a state machine that is not in Fulcro state. ASM ID:  :app.client/Router
#error {:message "", :data {}}

njj19:10:22

I found some related questions here, https://clojurians-log.clojureverse.org/fulcro/2020-02-14 - but I have dr/change-route! in client-will-mount and dr/initialize! in my app start.