From dfcfe505e8142f06b5001d0eda00f7b406d1bb95 Mon Sep 17 00:00:00 2001 From: xificurC Date: Fri, 3 Mar 2023 09:37:22 +0100 Subject: [PATCH] cleanup: remove e/on-mount It is a no-op wrapper, just write the code directly. --- src-docs/user/blinker.cljc | 2 +- src-docs/user/demo_4_chat_extended.cljc | 2 +- src/hyperfiddle/electric.cljc | 8 +++++--- src/hyperfiddle/electric_ui4.cljc | 4 ++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src-docs/user/blinker.cljc b/src-docs/user/blinker.cljc index 527ce42a1..31eeb369b 100644 --- a/src-docs/user/blinker.cljc +++ b/src-docs/user/blinker.cljc @@ -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 [] diff --git a/src-docs/user/demo_4_chat_extended.cljc b/src-docs/user/demo_4_chat_extended.cljc index a0c350689..5b39f2c1f 100644 --- a/src-docs/user/demo_4_chat_extended.cljc +++ b/src-docs/user/demo_4_chat_extended.cljc @@ -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)))))) diff --git a/src/hyperfiddle/electric.cljc b/src/hyperfiddle/electric.cljc index 11e8858ee..0292c0203 100644 --- a/src/hyperfiddle/electric.cljc +++ b/src/hyperfiddle/electric.cljc @@ -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))) @@ -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 diff --git a/src/hyperfiddle/electric_ui4.cljc b/src/hyperfiddle/electric_ui4.cljc index c9b5ee263..ef4db4e73 100644 --- a/src/hyperfiddle/electric_ui4.cljc +++ b/src/hyperfiddle/electric_ui4.cljc @@ -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#) @@ -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#)