Makes transaction rule form much better; state visible
This commit is contained in:
68
src/cljs/auto_ap/status.cljs
Normal file
68
src/cljs/auto_ap/status.cljs
Normal 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] {}))
|
||||
Reference in New Issue
Block a user