Skip to content

Commit

Permalink
Move hf/*http-request* to e/*http-request*
Browse files Browse the repository at this point in the history
*http-request* is specific to the Electric
  • Loading branch information
ggeoffrey committed Mar 13, 2023
1 parent ad3f670 commit 9f6f167
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 9 deletions.
5 changes: 2 additions & 3 deletions src-docs/user/demo_chat_extended.cljc
@@ -1,7 +1,6 @@
(ns user.demo-chat-extended
(:require
contrib.str
[hyperfiddle.api :as hf]
[hyperfiddle.electric :as e]
[hyperfiddle.electric-dom2 :as dom]))

Expand Down Expand Up @@ -41,8 +40,8 @@
(e/defn ChatExtended []
(e/client
(dom/h1 (dom/text "Multiplayer chat app with auth and presence"))
(let [session-id (e/server (get-in hf/*http-request* [:headers "sec-websocket-key"]))
username (e/server (get-in hf/*http-request* [:cookies "username" :value]))]
(let [session-id (e/server (get-in e/*http-request* [:headers "sec-websocket-key"]))
username (e/server (get-in e/*http-request* [:cookies "username" :value]))]
(if-not (some? username)
(do (dom/p (dom/text "Set login cookie here: ") (dom/a (dom/props {::dom/href "/auth"}) (dom/text "/auth")) (dom/text " (blank password)"))
(dom/p (dom/text "Example HTTP endpoint is here: ")
Expand Down
5 changes: 2 additions & 3 deletions src/contrib/element_syntax.cljc
Expand Up @@ -76,7 +76,6 @@
(:require
contrib.str
[contrib.element-syntax :refer [<%]]
[hyperfiddle.api :as hf]
[hyperfiddle.electric :as e]
[hyperfiddle.electric-dom2 :as dom]))

Expand Down Expand Up @@ -113,8 +112,8 @@
(e/defn App []
(e/client
(<% :h1 "Multiplayer chat app with auth and presence")
(let [session-id (e/server (get-in hf/*http-request* [:headers "sec-websocket-key"]))
username (e/server (get-in hf/*http-request* [:cookies "username" :value]))]
(let [session-id (e/server (get-in e/*http-request* [:headers "sec-websocket-key"]))
username (e/server (get-in e/*http-request* [:cookies "username" :value]))]
(if-not (some? username)
(do (<% :p "Set login cookie here: " (<% :a {:href "/auth"} "/auth") " (blank password)")
(<% :p "Example HTTP endpoint is here: "
Expand Down
2 changes: 0 additions & 2 deletions src/hyperfiddle/api.cljc
Expand Up @@ -131,8 +131,6 @@

(defmacro branch [& body] `(new Branch (e/fn [] ~@body)))

(def ^:dynamic *http-request* "Bound to the HTTP request of the page in which the current Electric program is running." nil)

(e/def page-drop -1)
(e/def page-take -1)

Expand Down
2 changes: 2 additions & 0 deletions src/hyperfiddle/electric.cljc
Expand Up @@ -397,3 +397,5 @@ running on a remote host.
{:status :waiting
:since time
:delay 1000})))))))

(def ^:dynamic *http-request* "Bound to the HTTP request of the page in which the current Electric program is running." nil)
2 changes: 1 addition & 1 deletion src/hyperfiddle/electric_jetty_adapter.clj
Expand Up @@ -84,7 +84,7 @@
program named by the client. Original HTTP upgrade ring request map is
accessible using `(ring.adapter.jetty9/req-of ws)`."
[ring-req write-msg read-msg]
(binding [hf/*http-request* ring-req]
(binding [e/*http-request* ring-req]
;; Electric can resolve any dynamic var bound at this point
(let [resolvef (bound-fn [not-found x] (r/dynamic-resolve not-found x))]
(m/sp
Expand Down

0 comments on commit 9f6f167

Please sign in to comment.