Fork me on GitHub

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 simple_smile