0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-11 07:11:32 -05:00

Improve canvas assignation on shapes changes.

This commit is contained in:
Andrey Antukh 2019-09-21 20:14:07 +02:00
parent ddaf6bfc92
commit bb6ec9f89f
2 changed files with 43 additions and 2 deletions

View file

@ -999,3 +999,42 @@
project (get-in state [:projects (:project page)])
url (str cfg/viewurl "?v=" rval "#/preview/" (:share-token project) "/" page-id)]
(js/open url "new tab" ""))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Page Changes Reactions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn start-shapes-watcher
[id]
(s/assert ::us/uuid id)
(letfn [(on-change [[old new]]
(reduce-kv (fn [acc k v]
(if (identical? v (get old k))
acc
(conj acc k)))
#{}
new))
(select-shapes [state]
(let [ids (get-in state [:pages id :shapes])]
(select-keys (:shapes state) ids)))
]
(ptk/reify ::watch-page-changes
ptk/WatchEvent
(watch [_ state stream]
(let [stoper (rx/filter #(= % ::stop-shapes-watcher) stream)
ids (get-in state [:pages id :shapes])
local (volatile! nil)
into* (fn [dst srcs] (reduce #(into %1 %2) dst srcs))]
(->> (rx/merge st/store (rx/of state))
(rx/map select-shapes)
(rx/buffer 2 1)
(rx/map on-change)
(rx/buffer-time 300)
(rx/map #(into* #{} %))
(rx/filter (complement empty?))
(rx/tap #(prn "changed" %))
(rx/mapcat (fn [items] (rx/from-coll
(map rehash-shape-relationship items))))
(rx/take-until stoper)))))))

View file

@ -63,9 +63,11 @@
[canvas page]
;; (scroll/scroll-to-page-center (mf/ref-node canvas) page)
(st/emit! (udp/watch-page-changes (:id page))
(udu/watch-page-changes (:id page)))
(udu/watch-page-changes (:id page))
(dw/start-shapes-watcher (:id page)))
(let [sub (shortcuts/init)]
#(do (st/emit! ::udp/stop-page-watcher)
#(do (st/emit! ::udp/stop-page-watcher
::dw/stop-shapes-watcher)
(rx/cancel! sub))))
(mf/defc workspace