Fork me on GitHub
#re-frame
<
2015-09-05
>
timgilbert01:09:16

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)]))

timgilbert01:09:20

…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)

timgilbert01:09:08

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

timgilbert01:09:24

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

paulspencerwilliams12:09:23

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 simple_smile