This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-04-22
Channels
- # announcements (1)
- # beginners (179)
- # boot (8)
- # calva (3)
- # cider (4)
- # clara (3)
- # cljdoc (31)
- # clojure (9)
- # clojure-austin (1)
- # clojure-chicago (5)
- # clojure-dev (19)
- # clojure-nl (2)
- # clojure-uk (1)
- # clojurescript (13)
- # core-matrix (1)
- # cursive (86)
- # datascript (2)
- # datomic (13)
- # emacs (3)
- # figwheel-main (1)
- # fulcro (66)
- # off-topic (250)
- # pathom (7)
- # re-frame (19)
- # reitit (5)
- # sql (37)
- # uncomplicate (5)
is there a way to change the url (pushState) based on a subscription?
@ackerleytng In general subscriptions should not cause side-effects. Try thinking it this way: what is the event that should cause the url to change? That event should probably have an effect that calls pushState.
hmm but the subscription is kind of a derived result
i have two events, one that adds to a map and one that removes
the subscription returns (keys (:results db))
I now have a component that subscribes to the subscription in question and updates the url as a side effect, then returns an empty [:div]
That sounds a bit hacky. 🙂 Sometimes it’s possible to make the calculation of derived results already at the event handler(s) and store the results into the db and/or dispatch other side-effects.
1. you can subscribe outside of a component, which would probably be incrementally better. 2. I think one would prefer to have the pushState as an effect and a co-effect. treating it as derived from the app-db is frought with problems
how do you subscribe outside a component?
the biggest problem is that the URL can be changed by a whole host of things. the user can use the forward/back button. they might manually type in the URL. they may have bookmarked a specific thing or clicked a link to navigate to a place
if you're relying on state in the URL bar, you should ensure that you are covering these cases appropriately so that you don't break the user experience for your app
@ackerleytng I’m not at all sure this is the best way to deal with pushState, but here’s my best take so far: https://github.com/rgm/bidi-pushy-example/blob/master/src/cljs/sample/core.cljs
as @lilactown suggested, it ended up working OK when treating it as a coeffect/effect pairing.
Personally I’m using reitit
for routing (both backend and frontend) and to me it feels simpler than bidi & pushy. I implemented a small example how to use it with re-frame. https://github.com/vharmain/reitit/tree/frontend-examples/examples/frontend-re-frame
oh, nice. Yeah, I’ve been meaning to switch to reitit but, y’know … other things and all that.
notice I had to retrofit back in the query-params as a consequence of bidi’s philosophy on query params https://github.com/juxt/bidi/issues/51
Thanks! I'll try that