This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-02-15
Channels
- # aws (1)
- # beginners (6)
- # boot (25)
- # cider (30)
- # cljs-dev (50)
- # cljsrn (45)
- # clojure (98)
- # clojure-austin (5)
- # clojure-czech (1)
- # clojure-dev (21)
- # clojure-dusseldorf (29)
- # clojure-germany (2)
- # clojure-greece (117)
- # clojure-italy (2)
- # clojure-nl (4)
- # clojure-russia (26)
- # clojure-serbia (10)
- # clojure-spec (123)
- # clojure-turkiye (1)
- # clojure-uk (27)
- # clojured (13)
- # clojurescript (57)
- # core-async (18)
- # cursive (13)
- # datomic (20)
- # defnpodcast (16)
- # emacs (8)
- # events (2)
- # figwheel (3)
- # instaparse (1)
- # jobs (3)
- # jobs-discuss (39)
- # klipse (9)
- # lumo (100)
- # mount (1)
- # numerical-computing (1)
- # off-topic (22)
- # om (34)
- # onyx (17)
- # pedestal (1)
- # perun (29)
- # re-frame (60)
- # reagent (16)
- # remote-jobs (8)
- # rethinkdb (6)
- # ring-swagger (19)
- # rum (1)
- # slack-help (1)
- # specter (3)
- # untangled (1)
- # yada (17)
@danielcompton we do this a lot
(:import [yada.resource Resource])
`(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))`
(waiting for slack to process the same in a code block)
hope this helps
3 backticks @malcolmsparks 🙂
(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))
(defn update-resources [routes f & args]
(postwalk
(fn [x]
(if (instance? Resource x)
(resource (apply f x args))
x))
routes))
@stijn - your version has the advantage that resources will be re-validated, which is very useful
@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 {}))
As a technical point, you only need
(y/resource)
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
the implementation of this actually simply wraps the resource in a yada handler
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
Thanks!
great!