Created
April 18, 2017 19:38
-
-
Save ricardo-rossi/0e51e871b8dba9016d435c0147b51190 to your computer and use it in GitHub Desktop.
CLJS Routing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defresource contact [handlers] | |
:allowed-methods #{:delete :put} | |
:available-media-types #{"application/json"} | |
:handle-ok (fn [{{{id :id} :route-params routes :routes} :request}] | |
(assert (realized? handlers)) | |
(html [:div [:h2 "Contact: " id] | |
[:a {:href (path-for routes (:contacts @handlers))} "Index"]]))) | |
(defn make-handlers [database] | |
(let [p (promise)] | |
;; Deliver the promise so it doesn't escape this function. | |
@(deliver p {:contacts (contacts database p) | |
:contact (contact p)}))) | |
(defn make-routes [handlers] | |
["/" [["contacts" (:contacts handlers)] | |
[["contact/" :id] (:contact handlers)] | |
]]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment