mirror of
https://github.com/penpot/penpot.git
synced 2025-02-04 13:29:14 -05:00
Simplify the page changes watcher of history.
This commit is contained in:
parent
955b864da5
commit
70c5a29862
2 changed files with 20 additions and 36 deletions
|
@ -89,39 +89,22 @@
|
|||
([id params]
|
||||
(map->FetchPageHistory (assoc params :id id))))
|
||||
|
||||
;; --- Clean Page History
|
||||
|
||||
(defrecord CleanPageHistory []
|
||||
rs/UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(assoc-in state [:workspace :history] {})))
|
||||
|
||||
(defn clean-page-history
|
||||
[]
|
||||
(CleanPageHistory.))
|
||||
|
||||
(defn clean-page-history?
|
||||
[v]
|
||||
(instance? CleanPageHistory v))
|
||||
|
||||
;; --- Watch Page Changes
|
||||
|
||||
(defrecord WatchPageChanges []
|
||||
rs/WatchEvent
|
||||
(-apply-watch [_ state s]
|
||||
(let [stoper (->> (rx/filter clean-page-history? s)
|
||||
(rx/take 1))]
|
||||
(->> (rx/filter udp/page-synced? s)
|
||||
(rx/take-until stoper)
|
||||
(rx/delay 1000)
|
||||
(rx/map (comp :id :page))
|
||||
(rx/mapcat #(rx/of
|
||||
(fetch-page-history %)
|
||||
(fetch-pinned-page-history %)))))))
|
||||
|
||||
(defn watch-page-changes
|
||||
"A function that starts watching for `IPageUpdate`
|
||||
events emited to the global event stream and just
|
||||
reacts on them emiting an other event that just
|
||||
persists the state of the page in an undo stack."
|
||||
[]
|
||||
(WatchPageChanges.))
|
||||
(letfn [(on-value [id]
|
||||
(rs/emit! (fetch-page-history id)
|
||||
(fetch-pinned-page-history id)))]
|
||||
(as-> rs/stream $
|
||||
(rx/filter udp/page-synced? $)
|
||||
(rx/delay 500 $)
|
||||
(rx/map (comp :id :page) $)
|
||||
(rx/on-value $ on-value))))
|
||||
|
||||
;; --- Select Page History
|
||||
|
||||
|
|
|
@ -38,8 +38,7 @@
|
|||
(defn- workspace-will-mount
|
||||
[own]
|
||||
(let [[projectid pageid] (:rum/args own)]
|
||||
(rs/emit! (dw/initialize projectid pageid)
|
||||
(udh/watch-page-changes))
|
||||
(rs/emit! (dw/initialize projectid pageid))
|
||||
own))
|
||||
|
||||
(defn- workspace-did-mount
|
||||
|
@ -47,23 +46,25 @@
|
|||
(let [[projectid pageid] (:rum/args own)
|
||||
sub1 (scroll/watch-scroll-interactions own)
|
||||
sub2 (udp/watch-page-changes pageid)
|
||||
sub3 (udh/watch-page-changes)
|
||||
dom (mx/ref-node own "workspace-canvas")]
|
||||
|
||||
;; Set initial scroll position
|
||||
(set! (.-scrollLeft dom) (* c/canvas-start-scroll-x @wb/zoom-ref))
|
||||
(set! (.-scrollTop dom) (* c/canvas-start-scroll-y @wb/zoom-ref))
|
||||
|
||||
(assoc own ::sub1 sub1 ::sub2 sub2)))
|
||||
(assoc own
|
||||
::sub1 sub1
|
||||
::sub2 sub2
|
||||
::sub3 sub3)))
|
||||
|
||||
(defn- workspace-will-unmount
|
||||
[own]
|
||||
(rs/emit! (udh/clean-page-history))
|
||||
|
||||
;; Close subscriptions
|
||||
(.close (::sub1 own))
|
||||
(.close (::sub2 own))
|
||||
|
||||
(dissoc own ::sub1 ::sub2))
|
||||
(.close (::sub3 own))
|
||||
(dissoc own ::sub1 ::sub2 ::sub3))
|
||||
|
||||
(defn- workspace-did-remount
|
||||
[old-state state]
|
||||
|
|
Loading…
Add table
Reference in a new issue