Fork me on GitHub
#yada
<
2016-08-16
>
jethroksy12:08:27

Hi, does bidi only accept keywords for matches?

jethroksy12:08:49

I want the route to match to a var, which contains a function that renders the correct HTML

jethroksy12:08:00

right now I'm working around it like this:

jethroksy12:08:03

(def app-routes
  ["/" {"" :home-page
        "about" :about-page
        "dev" :dev-page
        "login" :login-page}])

(def route-match
  {:home-page  #'pages/home-page
   :about-page #'pages/about-page
   :dev-page   #'pages/dev-page
   :login-page #'login/login-page})

jethroksy12:08:16

this looks really awkward

malcolmsparks12:08:56

bidi accepts keywords, functions and (I believe) vars. I will check

jethroksy13:08:51

let me just paste the error I get for clarity

jethroksy13:08:29

bidi.cljc:183Uncaught Error: No protocol method Matched.resolve-handler defined for type cljs.core/Var: [object Object]

dominicm13:08:11

That's the problem

jethroksy13:08:09

ah, is it meant to be unsupported?

dominicm13:08:54

Probably just a case of whoever did the cljc didn't know about cljs.core/Var (or it didn't exist then? not sure!)

jethroksy13:08:05

that's good news ^^

dominicm13:08:34

@jethroksy: It's probably best if you try and make the patch yourself, and test it on your own codebase by using lein install

dominicm13:08:50

I can provide a little helping hand if you need.

jethroksy13:08:05

yeah I'll try to make a PR

dominicm13:08:12

That would be great!

dominicm13:08:27

There are some tests which do run on cljs, so maybe we need some tests which use vars there too.

jethroksy13:08:04

I'll ping you for help when I need it 🙂

jethroksy13:08:36

@dominicm: there seems to be no tests the different protocols for Matched

jethroksy13:08:45

but the fix does work

malcolmsparks13:08:29

Send the PR and I'll backfill the tests if necessary

dominicm13:08:01

Perhaps a fn at the top of this file which gets referred via #'var-test-handler or something.

jethroksy13:08:17

i'll cook something up for the time being

jethroksy14:08:40

can I just check if I'm using bidi.ring/make-handler correctly?

jethroksy14:08:44

(def app-routes
  ["/" {"" #'pages/home-page
        "about" #'pages/about-page
        "dev" #'pages/dev-page
        "login" #'login/login-page
        "register" #'registration/register-page}])

#?(:clj (def app-handler
          (->> app-routes
               (w/postwalk #(if (var? %) (layout/render-index %) %))
               make-handler)))

jethroksy14:08:05

Then in another file I do:

(def app-routes
  (routes
   #'app-handler
   #'service-routes
   (route/not-found
    (:body
     (error-page {:status 404
                  :title "page not found"})))))

jethroksy15:08:00

oops I was overcomplicating things

jethroksy15:08:05

fixed it 🙂

malcolmsparks15:08:26

Thanks for the PR.

jethroksy15:08:02

no, thanks for bidi 🙂