This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-06-15
Channels
- # beginners (56)
- # boot (4)
- # cider (22)
- # clara (10)
- # cljs-dev (50)
- # cljsrn (27)
- # clojure (27)
- # clojure-conj (4)
- # clojure-dev (3)
- # clojure-italy (17)
- # clojure-nl (12)
- # clojure-norway (3)
- # clojure-spec (10)
- # clojure-uk (137)
- # clojurescript (132)
- # cursive (4)
- # datascript (2)
- # datomic (109)
- # devcards (2)
- # editors (1)
- # emacs (4)
- # euroclojure (2)
- # events (4)
- # figwheel (1)
- # fulcro (15)
- # jobs (1)
- # jobs-discuss (4)
- # juxt (3)
- # leiningen (2)
- # off-topic (21)
- # onyx (13)
- # other-languages (8)
- # pedestal (6)
- # re-frame (22)
- # reagent (5)
- # reitit (1)
- # ring-swagger (3)
- # shadow-cljs (75)
- # sql (6)
- # tools-deps (2)
- # vim (1)
- # yada (8)
Hey, #re-frame is fun! https://github.com/kennytilton/rehiring/blob/master/README.md
In re-frame, how do I update the database with a value in a form field. I'd like the database value to change whenever the form field value changes.
I'm relatively new to modern re-frame myself, but here's how I'm doing it:
(rf/reg-event-db
:register-input
(fn-traced [db [_ cur-input]]
(assoc db :input-storage-key cur-input)))
and then in the view:
[:input {:type "text"
:on-change #(rf/dispatch [:register-input (.-value (.-target %))])}]
Note that that'll update app-db
for every keystroke -- depending on your use case, that may be more noise in event history than you want. You could implement some debouncing to decrease the noise.
@scott.archer Warning: I am new, too. I would have a handler (rfr/dispatch {:ff-set :ff-name value])
, then have a (reg-event-db :ff-set etc) simply (assoc-in db [:path-to-fields ff-name] value)
. But…
If you use on-change
, it will fire on each keystroke, because React is a bit nutty. I have been duplicating the handling in :on-blur and :on-key-press, checking for the enter key on the latter.
Unless of course you want to react to each keystroke, then on-change is fine.
@hiskennyness you can also implement event “denouncing” with re-frame event handler and effect handler.
google…google…google… 🙂
Just FYI. It can make it less intense by delaying a reaction until the keystrokes have paused for some given window of time
I ended up implementing my own, but inspired by examples. Can’t recall all details. Will see if I find a link
I think I drew inspiration from https://github.com/johnswanson/re-frame-debounce-fx/blob/develop/README.md
I think it is worth looking at the impl and understanding the interaction with the events and effects.
Drat, I have been “denouncing” FB engineers for a while, you got my hopes up!
Thx for the links. My use cases so far just want to wait until the user makes the standard blur/hit enter gestures.