Fork me on GitHub
#yada
<
2017-02-15
>
malcolmsparks08:02:24

(:import [yada.resource Resource])

malcolmsparks08:02:33

`(defn add-interceptors [t] (postwalk (fn [x] (cond-> x (instance? Resource x) (assoc :interceptor-chain (concat [(fn [ctx] (assoc ctx :db @db))] (yada/interceptor-chain nil))))) t))`

malcolmsparks08:02:50

(waiting for slack to process the same in a code block)

malcolmsparks08:02:05

hope this helps

stijn08:02:45

3 backticks @malcolmsparks 🙂

malcolmsparks08:02:18

(defn add-interceptors [t]
  (postwalk
   (fn [x]
     (cond-> x (instance? Resource x)
             (assoc :interceptor-chain (concat [(fn [ctx] (assoc ctx :db @db))]
                                               (yada/interceptor-chain nil)))))
   t))

stijn08:02:09

(defn update-resources [routes f & args]
  (postwalk
    (fn [x]
      (if (instance? Resource x)
        (resource (apply f x args))
        x))
    routes))

stijn08:02:35

this is what we do, I think it's taken from a very early version of yada 🙂

malcolmsparks08:02:18

@stijn - your version has the advantage that resources will be re-validated, which is very useful

malcolmsparks09:02:19

@vinnyataide hi - the problem is that you're not creating a yada resource - you need

(y/resource {})
. You can then wrap that resource with a yada/handler so it could be
(y/handler (y/resource {}))

malcolmsparks09:02:38

As a technical point, you only need

(y/resource)

malcolmsparks09:02:11

reason is, that yada resources satisfy bidi's bidi.ring.Ring protocol which means that bidi knows how to route Ring requests to them directly

malcolmsparks09:02:35

the implementation of this actually simply wraps the resource in a yada handler

malcolmsparks09:02:02

one advantage of using naked resources in your bidi routing tree is to make it easier to treat them as pure data and post-process them, as @danielcompton is asking about