Makes transaction rule form much better; state visible

This commit is contained in:
Bryce Covert
2020-08-03 07:31:27 -07:00
parent 45ff1deed6
commit bb5196b9f8
7 changed files with 159 additions and 28 deletions

View File

@@ -0,0 +1,68 @@
(ns auto-ap.status
(:require [re-frame.core :as re-frame]))
;; (re-frame/reg-sub
;; ::status
;; (fn [db [_ which]]
;; (get-in db [::status which])))
;;
;;
;; (defn loading [db which]
;; (-> db
;; (assoc-in [::status which :state] :loading)
;; (assoc-in [::status which :error] nil)))
;;
;; (defn completion [db which]
;; (-> db
;; (assoc-in [::status which :state] :loading)
;; (assoc-in [::status which :error] nil)))
;;
;; (defn triggers-loading [which]
;; (re-frame/enrich
;; (fn [db event]
;; (loading db which))))
;;
;; (defn triggers-completion [which]
;; (re-frame/enrich
;; (fn [db event]
;; (completion db which))))
;;
(defn class-for [which]
(cond (= :loading (:state which))
["is-loading"]
(= :error (:state which))
["animated" "shake"]
:else
[]))
(re-frame/reg-sub
::multi
(fn [db [_ multi]]
(get-in db [::status multi])))
(re-frame/reg-event-db
::loading-multi
[(re-frame/path [::status]) ]
(fn [db [_ multi which]]
(assoc-in db [multi which] {:state :loading
:error nil})))
(re-frame/reg-event-db
::completed-multi
[(re-frame/path [::status]) ]
(fn [db [_ multi which]]
(assoc-in db [multi which] {:state nil
:error nil})))
(re-frame/reg-event-db
::error-multi
[(re-frame/path [::status]) ]
(fn [db [_ multi which error]]
(assoc-in db [multi which] {:state :error
:error error})))
(defn reset-multi [db multi]
(assoc-in db [::status multi] {}))