diff --git a/frontend/src/app/main/data/workspace/thumbnails.cljs b/frontend/src/app/main/data/workspace/thumbnails.cljs index 467a99919..11d1503bd 100644 --- a/frontend/src/app/main/data/workspace/thumbnails.cljs +++ b/frontend/src/app/main/data/workspace/thumbnails.cljs @@ -10,6 +10,7 @@ [app.common.files.helpers :as cfh] [app.common.logging :as l] [app.common.thumbnails :as thc] + [app.common.types.component :as ctc] [app.common.uuid :as uuid] [app.main.data.changes :as dch] [app.main.data.helpers :as dsh] @@ -184,11 +185,11 @@ (rx/filter (ptk/type? ::clear-thumbnail)) (rx/filter #(= (deref %) object-id)))))))))) -(defn- extract-root-frame-changes +(defn- extract-frame-changes "Process a changes set in a commit to extract the frames that are changing" [page-id [event [old-data new-data]]] - (let [changes (:changes event) + (let [changes (:changes event) lookup-data-objects (fn [data page-id] (dm/get-in data [:pages-index page-id :objects])) @@ -205,21 +206,28 @@ get-frame-ids (fn get-frame-ids [id] - (let [old-objects (lookup-data-objects old-data page-id) - new-objects (lookup-data-objects new-data page-id) + (let [old-objects (lookup-data-objects old-data page-id) + new-objects (lookup-data-objects new-data page-id) - new-shape (get new-objects id) - old-shape (get old-objects id) + new-shape (get new-objects id) + old-shape (get old-objects id) - old-frame-id (if (cfh/frame-shape? old-shape) id (:frame-id old-shape)) - new-frame-id (if (cfh/frame-shape? new-shape) id (:frame-id new-shape))] + old-frame-id (if (cfh/frame-shape? old-shape) id (:frame-id old-shape)) + new-frame-id (if (cfh/frame-shape? new-shape) id (:frame-id new-shape)) + + root-frame-old? (cfh/root-frame? old-objects old-frame-id) + root-frame-new? (cfh/root-frame? new-objects new-frame-id) + instance-root? (ctc/instance-root? new-shape)] (cond-> #{} - (cfh/root-frame? old-objects old-frame-id) - (conj old-frame-id) + root-frame-old? + (conj ["frame" old-frame-id]) - (cfh/root-frame? new-objects new-frame-id) - (conj new-frame-id) + root-frame-new? + (conj ["frame" new-frame-id]) + + instance-root? + (conj ["component" id]) (and (uuid? (:frame-id old-shape)) (not= uuid/zero (:frame-id old-shape))) @@ -266,7 +274,7 @@ (rx/map deref) (rx/observe-on :async) (rx/with-latest-from workspace-data-s) - (rx/merge-map (partial extract-root-frame-changes page-id)) + (rx/merge-map (partial extract-frame-changes page-id)) (rx/tap #(l/trc :hint "inconming change" :origin "all" :frame-id (dm/str %))) (rx/share)) @@ -281,15 +289,15 @@ ;; and interrupt any ongoing update-thumbnail process ;; related to current frame-id (->> all-commits-s - (rx/mapcat (fn [frame-id] - (rx/of (clear-thumbnail file-id page-id frame-id "frame") - (clear-thumbnail file-id page-id frame-id "component"))))) + (rx/mapcat (fn [[tag frame-id]] + (rx/of (clear-thumbnail file-id page-id frame-id tag))))) ;; Generate thumbnails in batches, once user becomes ;; inactive for some instant. (->> all-commits-s (rx/buffer-until notifier-s) (rx/mapcat #(into #{} %)) - (rx/map #(update-thumbnail file-id page-id % "frame" "watch-state-changes")))) + (rx/map (fn [[tag frame-id]] + (update-thumbnail file-id page-id frame-id tag "watch-state-changes"))))) (rx/take-until stopper-s))))))