This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-09-05
Channels
- # beginners (8)
- # boot (6)
- # cider (9)
- # clojure (43)
- # clojure-art (1)
- # clojure-australia (3)
- # clojure-berlin (1)
- # clojure-japan (4)
- # clojure-russia (13)
- # clojurescript (72)
- # core-matrix (1)
- # cursive (2)
- # datomic (1)
- # events (1)
- # hoplon (312)
- # jobs (1)
- # ldnclj (5)
- # off-topic (52)
- # overtone (2)
- # re-frame (5)
- # reagent (6)
- # testing (1)
I have a very form-ish app, sort of a CRUD app talking to back-end REST services. What I do is keep a model of the json data I’m eventually going to send to the REST endpoint, and then in the :on-change
of the text fields I have functions like (fn [event] (dispatch [:form-value-updated :name-of-endpoint :first-name (.. event -target -value)]))
…then the handler for :form-value-updated
winds up setting the value similarly to (assoc-in db [:json-payloads :name-of-endpoint :first-name] value-from-dom-event)
and the submit button does something like (dispatch [:submit-button-clicked :name-of-endpoint])
, whose handler then constructs the json payload via (get-in db [:json-payloads :name-of-endpoint])
and fires off an http request with that body
I like this approach because you can add sort of arbitrary fields to the payload and it’s easy to hook up new fields to them
cheers @mikethompson @timgilbert my simple app is v. basic crud so I’ll follow @mikethompson’s approach until I (hopefully don’t) grow out of it