continuing to refactor form.

This commit is contained in:
Bryce Covert
2019-04-26 14:14:13 -07:00
parent 058d8b95bd
commit 5d5db63ed6
4 changed files with 84 additions and 66 deletions

View File

@@ -47,6 +47,8 @@
[form-name]
(re-frame/path [::forms form-name]))
(re-frame/reg-event-db
::change
(fn [db [_ form & path-pairs]]
@@ -74,6 +76,16 @@
(assoc-in [::forms id :status] :loading)
(assoc-in [::forms id :error] nil)))
(defn triggers-loading [form]
(re-frame/enrich
(fn [db event]
(loading db form))))
(defn triggers-stop [form]
(re-frame/enrich
(fn [db event]
(stop-form db form))))
(defn save-succeeded [db id]
(-> db
(assoc-in [::forms id :status] nil)
@@ -82,13 +94,15 @@
(defn vertical-form [{:keys [can-submit id change-event submit-event ]}]
{:form (fn [{:keys [title] :as params} & children]
(let [{:keys [data active? error]} @(re-frame/subscribe [::form id])]
(let [{:keys [data active? error]} @(re-frame/subscribe [::form id])
can-submit @(re-frame/subscribe can-submit)]
(into ^{:key id} [:form { :on-submit (fn [e]
(when (.-stopPropagation e)
(.stopPropagation e)
(.preventDefault e))
(re-frame/dispatch-sync (conj submit-event params)))}
(when (.-stopPropagation e)
(.stopPropagation e)
(.preventDefault e))
(when can-submit
(re-frame/dispatch-sync (conj submit-event params))))}
[:h1.title.is-2 title]
]