0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-18 21:06:11 -05:00

Add additional parameter to watch event protocol method.

This commit is contained in:
Andrey Antukh 2016-03-19 12:48:39 +02:00
parent e71502f182
commit 409cd05739

View file

@ -24,7 +24,7 @@
;; of `UpdateEvent`, `WatchEvent` or `EffectEvent`. ;; of `UpdateEvent`, `WatchEvent` or `EffectEvent`.
(defprotocol WatchEvent (defprotocol WatchEvent
(-apply-watch [event state])) (-apply-watch [event state s]))
;; An abstraction for perform just side effects. It ;; An abstraction for perform just side effects. It
;; receives state and its return value is completly ;; receives state and its return value is completly
@ -90,9 +90,10 @@
"Initializes the stream event loop and "Initializes the stream event loop and
return a stream with model changes." return a stream with model changes."
[state] [state]
(let [watch-s (rx/filter watch? bus) (let [stream (rx/map identity bus)
effect-s (rx/filter effect? bus) watch-s (rx/filter watch? stream)
update-s (rx/filter update? bus) effect-s (rx/filter effect? stream)
update-s (rx/filter update? stream)
state-s (->> update-s state-s (->> update-s
(rx/scan #(-apply-update %2 %1) state) (rx/scan #(-apply-update %2 %1) state)
(rx/share))] (rx/share))]
@ -101,7 +102,7 @@
;; pushed to the event-stream bus ;; pushed to the event-stream bus
(as-> watch-s $ (as-> watch-s $
(rx/with-latest-from vector state-s $) (rx/with-latest-from vector state-s $)
(rx/flat-map (fn [[event model]] (-apply-watch event model)) $) (rx/flat-map (fn [[event model]] (-apply-watch event model stream)) $)
(rx/on-value $ emit!)) (rx/on-value $ emit!))
;; Process effects: combine with the latest model to process the new effect ;; Process effects: combine with the latest model to process the new effect