Skip to content

Commit

Permalink
cleanup: remove e/on-mount
Browse files Browse the repository at this point in the history
It is a no-op wrapper, just write the code directly.
  • Loading branch information
xificurC committed Mar 3, 2023
1 parent 3fb66e9 commit dfcfe50
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src-docs/user/blinker.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

(e/defn MyComponent []
(dom/h1 (dom/text (e/server (query))))
(e/on-mount #(println 'component-did-mount))
(println 'component-did-mount)
(e/on-unmount #(println 'component-will-unmount)))

(e/defn Blinker []
Expand Down
2 changes: 1 addition & 1 deletion src-docs/user/demo_4_chat_extended.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
(dom/text "electric_jetty_server.clj"))))
(do
(e/server
(e/on-mount #(swap! !present assoc session-id username))
(swap! !present assoc session-id username)
(e/on-unmount #(swap! !present dissoc session-id)))
(dom/p (dom/text "Authenticated as: " username))
(Chat. username))))))
8 changes: 5 additions & 3 deletions src/hyperfiddle/electric.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#?(:cljs [hyperfiddle.electric-client])
[hyperfiddle.electric.impl.io :as io]
[hyperfiddle.electric.debug :as dbg])
#?(:cljs (:require-macros [hyperfiddle.electric :refer [def defn fn boot for for-by local run debounce wrap on-mount on-unmount]]))
#?(:cljs (:require-macros [hyperfiddle.electric :refer [def defn fn boot for for-by local run debounce wrap on-unmount]]))
(:import #?(:clj (clojure.lang IDeref))
(hyperfiddle.electric Pending Failure FailureInfo)
(missionary Cancelled)))
Expand Down Expand Up @@ -318,8 +318,10 @@ executors are allowed (i.e. to control max concurrency, timeouts etc). Currently
(hyperfiddle.electric/fn ~@(when (symbol? F) [F]) [~@rest-args]
(new F# ~@args ~@rest-args))))))

(defmacro on-mount [f] `(new (m/observe (cc/fn [!#] (~f) (!# nil) (cc/fn []))))) ; experimental, may not be needed
(defmacro on-unmount [f] `(new (m/observe (cc/fn [!#] (!# nil) ~f)))) ; experimental
(defmacro on-unmount "Run clojure(script) thunk `f` during unmount.
Standard electric code runs on mount, therefore there is no `on-mount`."
[f] `(new (m/observe (cc/fn [!#] (!# nil) ~f)))) ; experimental

(defn ?PrintServerException [id]
(try (server
Expand Down
4 changes: 2 additions & 2 deletions src/hyperfiddle/electric_ui4.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
(for-truncated [id# (new Options# search#)] 20
(e/client
(dom/li (dom/text (e/server (new OptionLabel# id#)))
(e/on-mount #(swap! !selected# select-if-first dom/node))
(swap! !selected# select-if-first dom/node)
(e/on-unmount #(swap! !selected# ?pass-on-to-first dom/node))
(track-id dom/node id#)
(?mark-selected selected#)
Expand Down Expand Up @@ -270,7 +270,7 @@
(for-truncated [id# (new Options# search#)] 20
(e/client
(dom/li (dom/text (e/server (new OptionLabel# id#)))
(e/on-mount #(swap! !selected# select-if-first dom/node))
(swap! !selected# select-if-first dom/node)
(e/on-unmount #(swap! !selected# ?pass-on-to-first dom/node))
(track-id dom/node id#)
(?mark-selected selected#)
Expand Down

0 comments on commit dfcfe50

Please sign in to comment.