Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stronger check for middleware #127

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/system/components/handler.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(ns system.components.handler
(:require [com.stuartsierra.component :as component]
[lang-utils.core :refer [contains+?]]))
[system.components.middleware])
(:import [system.components.middleware Middleware]))

(defn- endpoints
"Find all endpoints this component depends on, returns map entries of the form
Expand All @@ -16,15 +17,15 @@
(with-middleware endpoints true))
([endpoints flag]
(let [f (if flag
(fn [[k v]] (contains+? v :middleware))
(fn [[k v]] (not (contains+? v :middleware))))]
(fn [[k v]] (instance? Middleware v))
(fn [[k v]] (not (instance? Middleware v))))]
(filter f endpoints))))

(defn- middleware-key
"Given the endpoint map-entry this returns the key of the
middleware dependency if any, or an empty map."
[endpoint]
(reduce-kv (fn [_ k v] (if (contains+? v :middleware) (reduced k) _)) {} (val endpoint)))
(reduce-kv (fn [_ k v] (if (instance? Middleware v) (reduced k) _)) {} (val endpoint)))

(defrecord Handler [router shared-root-middleware?]
component/Lifecycle
Expand Down