Fork me on GitHub
#fulcro
<
2021-10-04
>
rafaeldelboni13:10:08

Hi folks, does anybody have experience or idea of how I can implement something like react's hashHistory/HashRouter in fulcro? I want to create a frontend-only page and use it in gh-pages.

Hukka15:10:20

You mean react-router's HashRouter?

Hukka15:10:02

Have a look at https://github.com/fulcro-community/guides/blob/tutorial/advanced-min-fulcro/modules/tutorial-advanced-minimalist-fulcro/pages/index.adoc#binding-the-route-to-the-url. So you need the fulcro routers (section 20, or was it 21 in the book), and then make a helper that does a route change and url change, and put listeners. Fulcro RAD has some examples based on the path of the URL, but there's nothing special. You could use the hash very similarly

Hukka15:10:34

I haven't actually used react-router v4–v6, only v3. But my impression is that the fulcro's implementation is much in the same spirit as v5. That is, the router (or Route in react-router) components are intermixed in the ui component tree

Hukka15:10:36

Just getting my head around this too, though I don't need it quite yet (all our PoC UIs are still separate projects)

rafaeldelboni15:10:52

thanks I will check it out, I was looking at rad and maybe if was possible to set the route prefix as # it should work, I think.

Hukka15:10:31

And tweak the listener too, as the RAD version only looks at the path and params, skiping the hash

Hukka15:10:55

Err, I mean path and search

Hukka15:10:14

Hm, does that have any listeners for URL changes?

Hukka16:10:02

Ah, it checks it at https://github.com/fulcrologic/video-series/blob/817969602a31aee5fbf546b35893d73f93f1d78c/src/app/client.cljs#L125. The state machinery is still unknown to me. I can't read it that happens only at init, or does it check it later too

rafaeldelboni16:10:14

I was searching

rafaeldelboni22:10:34

Hey I managed to draft something here https://github.com/rafaeldelboni/stasis/blob/main/src/stasis/routing.cljs I had to "fork" pushy to use path-prefix

dehli22:10:46

👋 not sure if this is the right spot, but I have a question about fulcro’s guardrails. Is it possible to get runtime access to whether or not guardrails is enabled? I’d like to do some extra “type” checking at runtime that is more complex than a spec could capture (but only when guardrails is enabled).

👋 1
lgessler23:10:58

I think you can just (System/getProperty "guardrails.enabled") , right?

dehli00:10:03

Thanks! I should have stated that I’m in ClojureScript but that gives me something to search the repo for! I’ll update if I figure it out.

tony.kay00:10:45

so, most of the decision logic on putting GR into your runtime happens at macroexpansion…I don’t know if there is a trivial way to detect it at runtime, though you could make a macro that emits the system property to source as a constant.

tony.kay00:10:40

(defmacro gr-enabled? [] ~(System/getProperty "guardrails.enabled"))

tony.kay00:10:45

might do it

tony.kay00:10:10

the problem then is compiler caching at dev time…the result of the macro on a file that doesn’t get recompiled

dehli00:10:16

Appreciate it! With your last comment are you saying that if you changed the system property it could still be cached to its previous value in the compiled code?

tony.kay00:10:16

or, if an incremental compile was done (say you stopped the compiler and restated it w/diff gr enabled state)…the files that don’t get recompiled would have the stale value

dehli00:10:39

thanks for the clarification! that would be fine for my use-case so i’ll go down this path 👍

tony.kay00:10:14

GR proper has the same concern…you could technically get a mix of instrumented/non-instrumented code in such a transition

tony.kay00:10:51

but the alternative is to add overhead at runtime to even non-instrumented code…whihc is unacceptable

👍 1
dehli00:10:47

that makes sense. since GR proper has the same concern do you think it makes sense to add the enabled macro to core? I could submit a PR if you’d like.

tony.kay01:10:00

try it for yourself first, and yeah, if it works ok, I’m fine throwing it into core

👍 1