Skip to content

Commit

Permalink
Rename chain to context
Browse files Browse the repository at this point in the history
  • Loading branch information
frankiesardo committed Feb 19, 2016
1 parent a007c2d commit c773e82
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@ A common example is short-circuiting the execution. In the example above, `logge
:enter (fn [{:keys [request] :as context]
(if (check-session request)
context
(-> context tripod.chain/terminate (assoc :response "Nope!"))))})
(-> context tripod.context/terminate (assoc :response "Nope!"))))})
```
`tripod.chain/terminate` removes the remaining interceptors in the execution list.
`tripod.context/terminate` removes the remaining interceptors in the execution list.
Because there are no more interceptors to execute in the enter stage, the leave stage will start an the error response will be returned.
Expand Down
2 changes: 1 addition & 1 deletion src/tripod/chain.cljc → src/tripod/context.cljc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns tripod.chain
(ns tripod.context
(:require #?(:clj [tripod.log :as log]
:cljs [tripod.log :as log :include-macros true])))

Expand Down
8 changes: 4 additions & 4 deletions src/tripod/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[tripod.route :as route]
[tripod.router :as router]
[tripod.path :as path]
[tripod.chain :as chain]))
[tripod.context :as context]))

(defn expand-routes
"Creates a route table out of terse routes"
Expand All @@ -25,9 +25,9 @@
[{:keys [::interceptors] :as service-map}]
(when-not interceptors
(throw (ex-info "Initial interceptor queue cannot be empty" {:service-map service-map})))
(let [context (chain/enqueue* {} interceptors)]
(let [context (context/enqueue* {} interceptors)]
(fn [request]
(:response (chain/execute (assoc context :request request))))))
(:response (context/execute (assoc context :request request))))))

;; Defaults

Expand All @@ -45,7 +45,7 @@
(-> context
(assoc :request req)
(assoc :route route)
(chain/enqueue* interceptors))))}))
(context/enqueue* interceptors))))}))

(defn linker-interceptor [{:keys [::routes] :as service-map}]
(let [path-for (path/path-for-routes routes)]
Expand Down
38 changes: 19 additions & 19 deletions test/tripod/chain_test.cljc → test/tripod/context_test.cljc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns tripod.chain-test
(ns tripod.context-test
(:require #?(:clj [clojure.test :refer :all]
:cljs [cljs.test :refer-macros [deftest testing is run-tests]])
[tripod.chain :as chain]))
[tripod.context :as context]))

(defn trace [context direction name]
(update-in context [::trace] (fnil conj []) [direction name]))
Expand All @@ -28,18 +28,18 @@
[:leave :c]
[:leave :b]
[:leave :a]]}
(chain/execute (chain/enqueue {}
(tracer :a)
(tracer :b)
(tracer :c))))))
(context/execute (context/enqueue {}
(tracer :a)
(tracer :b)
(tracer :c))))))

(deftest error-propagates-test
(is (thrown? #?(:clj Exception :cljs js/Error)
(chain/execute (chain/enqueue {}
(tracer :a)
(tracer :b)
(thrower :c)
(tracer :d))))))
(context/execute (context/enqueue {}
(tracer :a)
(tracer :b)
(thrower :c)
(tracer :d))))))

(deftest error-caught-test
(is (= {::trace [[:enter :a]
Expand All @@ -50,13 +50,13 @@
[:error :c :from :f]
[:leave :b]
[:leave :a]]}
(chain/execute (chain/enqueue {}
(tracer :a)
(tracer :b)
(catcher :c)
(tracer :d)
(tracer :e)
(thrower :f)
(tracer :g))))))
(context/execute (context/enqueue {}
(tracer :a)
(tracer :b)
(catcher :c)
(tracer :d)
(tracer :e)
(thrower :f)
(tracer :g))))))


0 comments on commit c773e82

Please sign in to comment.