Fork me on GitHub
#hyperfiddle
<
2024-03-29
>
J13:04:18

Is there a repo about that?

wei17:03:32

this input is supposed to add a new item, then clear itself on blur.

(ns test.test
  (:require [hyperfiddle.electric :as e]
            [hyperfiddle.electric-ui4 :as ui]
            [hyperfiddle.electric-dom2 :as dom :refer [div text props on]]))

#?(:clj (def !items (atom ["a" "b" "c"])))

(e/defn Test []
  (e/client
   (div (text (pr-str (e/server (e/watch !items)))))
   (let [!v (atom "")
         *v (e/watch !v)]

     ;; new item ui
     (ui/input
      *v
      (e/fn [s] (reset! !v s))
      (on "blur"
          (when-not (empty? *v)
            (e/fn [e]
              (e/server (swap! !items conj *v)) ;; add new item
              (reset! !v "") ;; clear the input for the next new item
              )))))))
why do i get this error?
#error {:message called `new` on nil, :data {}}
when I comment out the (reset! v! "") on the last line, i don't get the error anymore.

noonian17:03:53

If *v is blank, you are registering nil as the blur handler. I think you probably want to check for blank inside your blur handler efn

🙏 1
wei18:03:54

good catch, thanks! the e/fn should wrap the when-not not the other way around.

👍 1
Adrian Smith20:03:37

Has any one got flow storm debugger working with electric?