Fork me on GitHub
#yada
<
2019-03-03
>
Pavel Klavík12:03:12

I have another really basic question about yada and bidi, but I couldn't find it anywhere. Bidi allow to assign identifiers to URIs, which is great, so I have created routes data like this:

(def routes
  ["" [["" :page/index]
       ["/css/" :resource/css]
       ["/js/" :resource/js]
       [true :routes/no-match]]])
Next, I have created a map from these identifiers to yada resources:
{:page/index        (y/as-resource (io/resource "public/index.html"))
      :resource/css      (y.resources-resource/new-resources-resource "public/css/")
      :resource/js       (y.resources-resource/new-resources-resource "public/js/")
      :routes/no-match   (y/as-resource nil)}
But what is the idiomatic way to join these together to create a single yada handler? Currently I am using this, not sure how to change it:
(y/listener
      [""
       [[""  (y/as-resource (io/resource "public/index.html"))]
        ["/css/" (y.resources-resource/new-resources-resource "public/js/")]
        ["/js/" (y.resources-resource/new-resources-resource "public/js/")]
        [true (y/as-resource nil)]]]
      {:port port})

malcolmsparks16:03:56

This is correct. You can associate each yada resource with an id. This is done via the :id key, which you can specify in custom resources and assoc into builtin resources. Then yada/path-for and yada/url-for will work.

Pavel Klavík22:03:41

That makes sense. I already have :id key associated with each resource, but how I do the remaining steps? And how I use resources in the listener? Can I access them via the key?

Pavel Klavík22:03:41

That makes sense. I already have :id key associated with each resource, but how I do the remaining steps? And how I use resources in the listener? Can I access them via the key?