Hey guys, I couldn't find a way to programmatically change the url of the page from an effect handler, I'm sure there might be an easy way... anyone knows?
(I'm using pushy
and bidi
for routing)
[answer in thread please]
It's right there in the pushy
documentation: https://github.com/kibu-australia/pushy#routing-libraries
The "Bidi" section has a set-page!
function - just call it within an effect.
Thank you @p-himik I am using the db to store the current route. When I try to change the route, it correctly displays the corresponding panel, but it won't change the url.
I believe I have to use set-token!
to change the url (see https://github.com/kibu-australia/pushy#googhistoryhtml5history-methods) but I can't add an event to control it since it would create a circular reference.
No idea, sorry. FWIW I'm using kee-frame myself that ties it all together itself.
I've seen this implementation (https://github.com/MattiNieminen/re-fill/blob/master/src/re_fill/routing.cljs) that saves the pushy instance into the db itself making it accessible from any event, eliminating the circular reference. I have to try it.
Thanks @p-himik, I'll check kee-frame.
Actually, thank you so much @p-himik, looking at kee-frame's code I found how they did it! (and it's pretty simple actually)
/src/kee_frame/router.cljc:88
(rf/reg-fx :navigate-to goto)
And
/src/kee_frame/router.cljc:28
(defn goto [data]
(navigate! @state/navigator (url data)))
tl;dr; With such an unqualified event ID we don't have to worry about the circular reference issue anymore.You don't have to worry about circular dependencies with fully qualified keywords as well - you can just avoid using an alias and instead spell out the whole keyword with its namespace.
A fully qualified keyword gives me a compilation error:
68 | [:dispatch [::spui.routes/navigate-to route]]]}))
------------------------------------------------------^-------------------------
spui/events.cljs [line 68, col 48] Invalid keyword: ::spui.routes/navigate-to.
Did I write it wrong?
spui.routes
:
(re-frame/reg-event-fx ::navigate-to navigate-to)
Try :spui.routes/navigate-to
instead of ::spui.routes/navigate-to
(single colon).
Double colon expects a namespace alias.
Excellent! Thank you!!
does re-frame-10x work with reagent 1.0.0? I'm not sure whether there's something wrong with my config or whether it's a versioning problem - it seems like when i recompile, the page occasionally fails to load
I have an action I’d like to take when two different things (an API access token and a GPS location) become available in my app db. This would be easy enough if it was a component—I would simply have the component subscribe to both app db keys and everything would be good. But in this case, the action has no user-visible effects (it simply adds more information to the app db by talking to the API). So I’m looking for something like “fire an event when these two events have fired”. Suggestions gratefully received!
If it's indeed "if seen eventA and eventB, fire eventC", then you can use https://github.com/day8/re-frame-async-flow-fx If it's "when valueA and valueB are set, fire eventC", then you can use a global interceptor.
Thanks! My situation is more like: • If eventA is fired, and valueB is already in the app db, go ahead (using valueB in the handling of eventA). • If eventA is fired, but valueB isn’t (yet) in the app db, wait until it is and then handle eventA. (if that makes sense?)
I imagine that I can transform it into one of the two cases you mention above 👍