From 6c43164ed1a485ff4ee255572b5b708f875c7726 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Sat, 24 Sep 2016 21:15:51 +0300 Subject: [PATCH] Add new approach for images page initialization. --- src/uxbox/main/data/images.cljs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/uxbox/main/data/images.cljs b/src/uxbox/main/data/images.cljs index 9da61e8b04..5aba4d4e13 100644 --- a/src/uxbox/main/data/images.cljs +++ b/src/uxbox/main/data/images.cljs @@ -10,6 +10,7 @@ [beicon.core :as rx] [uxbox.util.uuid :as uuid] [uxbox.util.rstore :as rs] + [uxbox.util.router :as r] [uxbox.main.state :as st] [uxbox.main.repo :as rp])) @@ -18,23 +19,30 @@ (declare fetch-collections) (declare collections-fetched?) -(defrecord Initialize [] +(defrecord Initialize [type id] + rs/UpdateEvent + (-apply-update [_ state] + (let [type (or type :builtin) + id (or id (if (= type :builtin) 1 nil)) + data {:type type :id id :selected #{} + :section :dashboard/images}] + (assoc state :dashboard data))) + rs/EffectEvent (-apply-effect [_ state] - (when-not (seq (:images-by-id state)) + (when (nil? (:images-by-id state)) (reset! st/loader true))) rs/WatchEvent (-apply-watch [_ state s] - (let [images (seq (:images-by-id state))] - (if images - (rx/empty) - (rx/merge - (rx/of (fetch-collections)) + (if (nil? (:images-by-id state)) + (rx/merge + (rx/of (fetch-collections)) (->> (rx/filter collections-fetched? s) (rx/take 1) (rx/do #(reset! st/loader false)) - (rx/ignore))))))) + (rx/ignore))) + (rx/empty)))) (defn initialize []