reitit

https://cljdoc.org/d/metosin/reitit/ https://github.com/metosin/reitit/
believelody 2020-05-31T11:46:02.026500Z

Hello guys, ok I have a very weird error message when I run my with reitit. This happened when I import reitit.ring or reitit.core. The message is: "Exception in thread "main" java.lang.RuntimeException: Unable to resolve symbol: qualified-keyword? in this context, compiling:(reitit/trie.cljc:317:14)" So, I'm just trying to run a basic ring app with jetty using reitit. This is my core:

(ns comment.core
  (:require [reitit.core :as r]
            [reitit.ring :as ring]
            [ring.adapter.jetty :as jetty]))

(def routes
  [["/ping" {:get (fn [_] {:status 200, :body "ok"})}]])

(def router
  (ring/router routes))

(def app
  (ring/ring-handler router))

(defn start []
  (jetty/run-jetty #'app {:port 3000 :join? false}))
My app crashes because of one reitit dependecies. I cannot figure out what's the problem.

ikitommi 2020-05-31T12:02:53.028600Z

@believelody my guess is that you are using Clojure 1.8 or earlier. qualified-keyword? was introduced in Clojure 1.9.0

believelody 2020-05-31T12:07:26.029500Z

@ikitommi oh my god you right! Thanks a lot, now everything is okay!

kitallis 2020-05-31T18:48:44.032300Z

I have a route like this: https://github.com/nilenso/pencil.space/blob/alpha/client/cljs/src/routes.cljs#L43 (it currently doesn’t do anything). But the idea is: • If someone lands on this page directly, I’d want to run some function to determine some boolean, if it’s false, render some other view which is not the :view • If I manually dispatch to this route, it can still run that function, but it must render the default :view

kitallis 2020-05-31T18:50:27.034300Z

What is the correct way to achieve this? Since in reitit, the route is always tied to a particular view, I can’t decide one way or another. Is it alright to check the app-db here and dispatch (redirect) to another route in :start?

just.sultanov 2020-06-01T09:16:34.034500Z

I think you can rewrite your event ::navigated and add some business logic something like this:

(rf/reg-fx
  ::redirect
  (fn [name params query]
    (rfe/push-state name params query)))


(rf/reg-event-fx
  ::navigated
  (fn [{db :db} [_ new-match]]
    (if-not (get db :some-flag) ;; e.g. check user authenticated/authorized or another your business logic
      {::redirect ::to-your-default-view}
      (let [current-route (:current-route db)
            controllers   (rfc/apply-controllers (:controllers current-route) new-match)
            new-route     (assoc new-match :controllers controllers)]
        {:db (assoc db :current-route new-route)}))))

just.sultanov 2020-06-01T10:32:13.034900Z

Or you can just create a subscription for your business logic flag and use it in a wrapper component to render the required component

kitallis 2020-06-01T15:35:15.035200Z

yeah, the second is what I was thinking

kitallis 2020-06-01T15:35:34.035400Z

I didn’t consider the first one, that might actually be cleaner since there’s really only 1 default fallback state and not many

kitallis 2020-06-01T15:35:41.035600Z

thanks @just.sultanov