Routing for a non-web-app

92 views
Skip to first unread message

Blake Watson

unread,
Apr 18, 2021, 7:58:53 PM4/18/21
to clo...@googlegroups.com
Howdy,

Writing a desktop app and thinking describing routes is the way to go, as far as setting up the flow through the program. There are quite a few Clojure routing libraries but most seem to assume it's a web backend (naturally), and the ones that don't seem to be ClojureScript (which I can't use here).

I could just use a multi-method and roll my own, of course, but I thought it might be useful to try out an existing library.

===Blake===

Orestis Markou

unread,
Apr 19, 2021, 3:46:45 AM4/19/21
to clo...@googlegroups.com
As far as I know, reitit could probably do what you want. It works on ClojureScript too.

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/clojure/CAJAnwPnBTuHsbDA_OgGSAt1j_B_tL%2B%3DnCVsigwZrAzD_g9%3D%2BsA%40mail.gmail.com.

Chris Nuernberger

unread,
Apr 19, 2021, 2:07:22 PM4/19/21
to clo...@googlegroups.com
For 'routing' specifically, if you want a more formal system we used state machines in the past and recently Clojure has a really nice additional possibility there - https://github.com/lucywang000/clj-statecharts.

For general UI programming if you are using javafx then I really like cljfx - https://github.com/cljfx/cljfx

Blake Watson

unread,
Apr 19, 2021, 5:18:50 PM4/19/21
to clo...@googlegroups.com
For 'routing' specifically, if you want a more formal system we used state machines in the past and recently Clojure has a really nice additional possibility there - https://github.com/lucywang000/clj-statecharts.

I really like the idea of the app being as stateless as possible, to where you could have a history stack which was basically an address like "\user\update\123" so people could move back and forth between spots that aren''t otherwise easy to jump around in.
 
For general UI programming if you are using javafx then I really like cljfx - https://github.com/cljfx/cljfx

I keep looking at cljfx thinking, "Well, this is probably the way to go" but I could not get the examples to work, despite trying different Java/JavaFX combos.

But it's a horse pill. Besides JavaFX, you've got component lifecycles (which I've never grasped), renderers (which I haven't touched in years, since I used reagent), and after about 3.5K of words and code you get, "Now that every piece is laid out, it's time to combine them into application." That kind of approach has not been successful for me, so I've been interacting with JavaFX directly to get going. This, at least, means that when I start thinking, "Well, it would make a whole lot of sense to be able to describe this interface as a data structure," I can go back to cljfx and go, "Ah, that's why he did that."

Harold

unread,
Apr 20, 2021, 10:42:27 AM4/20/21
to Clojure
I think bidi fits the bill: https://github.com/juxt/bidi

It's not tied too tightly to any specific (or even the idea of a) web backend and it does not require cljs.

Hope that helps,
-Harold

Blake Watson

unread,
Apr 20, 2021, 10:35:11 PM4/20/21
to clo...@googlegroups.com
Cool. I thought about bidi but this:

...is intended for use with Ring middleware, HTTP servers...

 sorta made me think it wouldn't work in a non-web app.

Harold

unread,
Apr 21, 2021, 7:54:17 PM4/21/21
to Clojure
>> ...is intended for use with Ring middleware, HTTP servers...
>
> sorta made me think it wouldn't work in a non-web app.
>

Understood.

One of the coolest things about bidi is that it's just functions that operate on data.

Nothing ring, web, or http specific going on here:

> (require 'bidi.bidi)
nil
> (bidi.bidi/match-route ["/foo" :bar] "/foo")
{:handler :bar}
> (bidi.bidi/match-route [["/foo/" :id] :bar] "/foo/17")
{:route-params {:id "17"}, :handler :bar}
> (bidi.bidi/path-for [["/foo/" :id] :bar] :bar :id 17)
"/foo/17"

---

Hope that helps,
-Harold

Brandon R

unread,
Apr 21, 2021, 9:46:17 PM4/21/21
to clo...@googlegroups.com
Bidi probably would work fine for what you want, but I'll also second the reitit suggestion.

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.

Blake Watson

unread,
Apr 22, 2021, 4:02:48 PM4/22/21
to clo...@googlegroups.com
I tried Reitit a couple of months ago so maybe I'll look at it again.

|| > (bidi.bidi/match-route ["/foo" :bar] "/foo")
|| {:handler :bar}

Yeah, the simplicity of bidi is nice. I couldn't figure out if it would also parse out query params. Like:

"/foo?a=123"
{:handler :bar :query-params {:a "123"}}


Reply all
Reply to author
Forward
0 new messages