0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-16 01:31:22 -05:00

Add new approach for images page initialization.

This commit is contained in:
Andrey Antukh 2016-09-24 21:15:51 +03:00
parent 5dfaf8e4be
commit 6c43164ed1
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95

View file

@ -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
[]