Return separate sub state for epoch and inter-epoch

This commit is contained in:
Daniel Compton 2018-02-09 02:50:09 +13:00
parent 4a5b00b713
commit 0259ef0a58
2 changed files with 53 additions and 34 deletions

View File

@ -433,46 +433,59 @@
(defn prepare-pod-info
"Returns sub info prepared for rendering in pods"
[[sub-info sub-state]]
(let [rx-state (:reaction-state sub-state)
subx (->>
rx-state
(remove (fn [me] (nil? (:order (val me)))))
(map (fn [me] (let [state (val me)
subscription (:subscription state)
sub {:id (key me)
:reagent-id (key me)
:layer (get-in sub-info [(first subscription) :layer])
:path-data subscription
:path (pr-str subscription)
:order (:order state)
:sub/traits (:sub/traits state)}
sub (if (contains? state :value)
(assoc sub :value (:value state))
sub)
sub (if (contains? state :previous-value)
(assoc sub :previous-value (:previous-value state))
sub)]
sub))))
[[sub-info sub-state] [subscription]]
(let [remove-fn (if (= subscription :subs/inter-epoch-subs)
(fn [me] (nil? (:order (val me))))
(constantly false))
subx (->> sub-state
(remove remove-fn)
(map (fn [me] (let [state (val me)
subscription (:subscription state)
sub {:id (key me)
:reagent-id (key me)
:layer (get-in sub-info [(first subscription) :layer])
:path-data subscription
:path (pr-str subscription)
:order (:order state)
:sub/traits (:sub/traits state)}
sub (if (contains? state :value)
(assoc sub :value (:value state))
sub)
sub (if (contains? state :previous-value)
(assoc sub :previous-value (:previous-value state))
sub)]
sub)))
(sort-by :path))
]
(utils/spy "subx" subx)
#_(utils/spy "subx" subx)
(when-not (s/valid? :subs/view-subs subx)
#_(when-not (s/valid? :subs/view-subs subx)
(js/console.error (expound/expound-str :subs/view-subs subx)))
subx))
(rf/reg-sub
:subs/pre-epoch-state
:<- [:subs/current-epoch-sub-state]
(fn [sub-state]
(:pre-epoch-state sub-state)))
(rf/reg-sub
:subs/reaction-state
:<- [:subs/current-epoch-sub-state]
(fn [sub-state]
(:reaction-state sub-state)))
(rf/reg-sub
:subs/inter-epoch-subs
:<- [:subs/subscription-info]
:<- [:subs/current-epoch-sub-state]
:<- [:subs/pre-epoch-state]
prepare-pod-info)
(rf/reg-sub
:subs/all-subs
:<- [:subs/subscription-info]
:<- [:subs/current-epoch-sub-state]
:<- [:subs/reaction-state]
prepare-pod-info)
(rf/reg-sub

View File

@ -152,6 +152,7 @@
(def no-prev-value-msg [:p {:style {:font-style "italic"}} "No previous value exists to diff"])
(def unchanged-value-msg [:p {:style {:font-style "italic"}} "Subscription value is unchanged"])
(def not-run-msg [rc/label :style {:font-style "italic"} :label "Subscription not run, so no value produced."])
(defn pod [{:keys [id layer path open? diff?] :as pod-info}]
(let [render-diff? (and open? diff?)
@ -181,7 +182,7 @@
[components/simple-render
main-value
["sub-path" path]]
[rc/label :style {:font-style "italic"} :label "Subscription not run, so no value produced."]
not-run-msg
)]]))]
[animated/component
(animated/v-box-options {:enter-animation "accordionVertical"
@ -277,13 +278,18 @@
:overflow-y "auto"}})
]
[rc/line :size "5px"
:style {:margin "19px 0px"}]
[:h2 {:class "bm-heading-text"
:style {:margin "19px 0px"}} "Inter-epoch subscriptions"]
(for [p inter-epoch-subs]
^{:key (:id p)}
[pod (merge p (get sub-expansions (:id p)))])
(when (seq inter-epoch-subs)
(list
^{:key "inter-epoch-line"}
[rc/line :size "5px"
:style {:margin "19px 0px"}]
^{:key "inter-epoch-title"}
[:h2 {:class "bm-heading-text"
:style {:margin "19px 0px"}} "Inter-epoch subscriptions"]
(for [p inter-epoch-subs]
^{:key (:id p)}
[pod (merge p (get sub-expansions (:id p)))])))
#_[animated/component
(animated/v-box-options {:on-finish #(reset! *finished-animation? true)