mirror of
https://github.com/penpot/penpot.git
synced 2025-05-22 22:36:12 +02: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]
|
(-apply-update [func state]
|
||||||
(func state)))
|
(func state)))
|
||||||
|
|
||||||
(defonce bus (rx/bus))
|
(defonce ^:private bus (rx/bus))
|
||||||
|
(defonce stream (rx/map identity bus))
|
||||||
|
|
||||||
(defn emit!
|
(defn emit!
|
||||||
"Emits an event or a collection of them.
|
"Emits an event or a collection of them.
|
||||||
|
@ -64,25 +65,24 @@
|
||||||
([event]
|
([event]
|
||||||
(rx/push! bus event))
|
(rx/push! bus event))
|
||||||
([event & events]
|
([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
|
(defn swap
|
||||||
"A helper for just apply some function to state
|
"A helper for just apply some function to state
|
||||||
without a need to declare additional event."
|
without a need to declare additional event."
|
||||||
[f]
|
[f]
|
||||||
(reify
|
(->SwapState f))
|
||||||
UpdateEvent
|
|
||||||
(-apply-update [_ state]
|
|
||||||
(f state))))
|
|
||||||
|
|
||||||
(defn reset
|
(defn reset
|
||||||
"A event that resets the internal state with
|
"A event that resets the internal state with
|
||||||
the provided value."
|
the provided value."
|
||||||
[state]
|
[v]
|
||||||
(reify
|
(->SwapState (fn [_] v)))
|
||||||
UpdateEvent
|
|
||||||
(-apply-update [_ _]
|
|
||||||
state)))
|
|
||||||
|
|
||||||
(enable-console-print!)
|
(enable-console-print!)
|
||||||
|
|
||||||
|
@ -90,8 +90,7 @@
|
||||||
"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 [stream (rx/map identity bus)
|
(let [watch-s (rx/filter watch? stream)
|
||||||
watch-s (rx/filter watch? stream)
|
|
||||||
effect-s (rx/filter effect? stream)
|
effect-s (rx/filter effect? stream)
|
||||||
update-s (rx/filter update? stream)
|
update-s (rx/filter update? stream)
|
||||||
state-s (->> update-s
|
state-s (->> update-s
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue