Should improve perf somewhat

This commit is contained in:
Bryce Covert
2020-05-02 08:09:26 -07:00
parent 532e35bb50
commit 5643b98b13
6 changed files with 116 additions and 91 deletions

View File

@@ -65,17 +65,26 @@
(fn [db]
(-> db ::check-results)))
(re-frame/reg-sub
::last-params
(fn [db]
(-> db ::last-params)))
(re-frame/reg-sub
::params
:<- [::last-params]
:<- [::subs/client]
:<- [::side-bar/filter-params]
:<- [::table/table-params]
(fn [[client filter-params table-params]]
(re-frame/dispatch [::params-change])
(cond-> {:import-status "imported"}
client (assoc :client-id (:id client))
(seq filter-params) (merge filter-params)
(seq table-params) (merge @(re-frame/subscribe [::table/table-params])))))
(fn [[last-params client filter-params table-params]]
(let [params (cond-> {:import-status "imported"}
client (assoc :client-id (:id client))
(seq filter-params) (merge filter-params)
(seq table-params) (merge table-params))]
(when (not= params last-params)
(println "DISPATCHING" params last-params)
(re-frame/dispatch [::params-change]))
params)))
(re-frame/reg-event-db
::invoice-updated
@@ -84,20 +93,19 @@
[::invoice-page :invoices]
replace-by :id (assoc invoice :class "live-added"))))
(re-frame/reg-event-fx
::params-change
[with-user (re-frame/inject-cofx ::inject/sub [::params])]
(fn [{::keys [params] :as cofx} _]
(when (not= params (::last-params (:db cofx)))
{:db (-> (:db cofx)
(assoc-in [:status :loading] true)
(assoc-in [::last-params] params))
:graphql {:token (-> cofx :db :user)
:query-obj (table/query params )
:on-success [::received]
:on-error [::events/page-failed]}})))
(println "params" params)
{:db (-> (:db cofx)
(assoc-in [:status :loading] true)
(assoc-in [::last-params] params))
:graphql {:token (-> cofx :db :user)
:query-obj (table/query params )
:on-success [::received]
:on-error [::events/page-failed]}}))
(re-frame/reg-event-fx
::unmounted
@@ -622,13 +630,11 @@
:checked checked
:on-check-changed (fn [which invoice]
(re-frame/dispatch [::toggle-check which invoice]))
:expense-event [::expense-accounts-dialog/change-expense-accounts]}]
]))
:expense-event [::expense-accounts-dialog/change-expense-accounts]}]]))
(defn unpaid-invoices-page [params]
(r/create-class
{:display-name "invoices-page"
:component-did-mount #(re-frame/dispatch [::params-change])
:component-will-unmount #(re-frame/dispatch [::unmounted])
:reagent-render
(fn []