mirror of
https://github.com/penpot/penpot.git
synced 2025-01-24 23:49:45 -05:00
Minor improvements on rstore.
This commit is contained in:
parent
91a06f4d7e
commit
32dfaebbb9
1 changed files with 12 additions and 13 deletions
|
@ -56,7 +56,8 @@
|
|||
(-apply-update [func state]
|
||||
(func state)))
|
||||
|
||||
(defonce bus (rx/bus))
|
||||
(defonce ^:private bus (rx/bus))
|
||||
(defonce stream (rx/map identity bus))
|
||||
|
||||
(defn emit!
|
||||
"Emits an event or a collection of them.
|
||||
|
@ -64,25 +65,24 @@
|
|||
([event]
|
||||
(rx/push! bus event))
|
||||
([event & events]
|
||||
(run! #(rx/push! bus %) (into [event] events))))
|
||||
(run! emit! (cons event events))))
|
||||
|
||||
(defrecord SwapState [f]
|
||||
UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(f state)))
|
||||
|
||||
(defn swap
|
||||
"A helper for just apply some function to state
|
||||
without a need to declare additional event."
|
||||
[f]
|
||||
(reify
|
||||
UpdateEvent
|
||||
(-apply-update [_ state]
|
||||
(f state))))
|
||||
(->SwapState f))
|
||||
|
||||
(defn reset
|
||||
"A event that resets the internal state with
|
||||
the provided value."
|
||||
[state]
|
||||
(reify
|
||||
UpdateEvent
|
||||
(-apply-update [_ _]
|
||||
state)))
|
||||
[v]
|
||||
(->SwapState (fn [_] v)))
|
||||
|
||||
(enable-console-print!)
|
||||
|
||||
|
@ -90,8 +90,7 @@
|
|||
"Initializes the stream event loop and
|
||||
return a stream with model changes."
|
||||
[state]
|
||||
(let [stream (rx/map identity bus)
|
||||
watch-s (rx/filter watch? stream)
|
||||
(let [watch-s (rx/filter watch? stream)
|
||||
effect-s (rx/filter effect? stream)
|
||||
update-s (rx/filter update? stream)
|
||||
state-s (->> update-s
|
||||
|
|
Loading…
Add table
Reference in a new issue