mirror of
https://github.com/penpot/penpot.git
synced 2025-01-09 08:20:45 -05:00
⚡ Make efficiency improvements to use-shared-state hook
This commit is contained in:
parent
e9c55e9eb4
commit
9619fcbc1f
1 changed files with 8 additions and 6 deletions
|
@ -294,19 +294,21 @@
|
||||||
`key` for new values."
|
`key` for new values."
|
||||||
[key default]
|
[key default]
|
||||||
(let [id (mf/use-id)
|
(let [id (mf/use-id)
|
||||||
state (mf/use-state (get @storage key default))
|
state* (mf/use-state #(get @storage key default))
|
||||||
|
state (deref state*)
|
||||||
stream (mf/with-memo [id]
|
stream (mf/with-memo [id]
|
||||||
(->> mbc/stream
|
(->> mbc/stream
|
||||||
(rx/filter #(not= (:id %) id))
|
(rx/filter #(not= (:id %) id))
|
||||||
(rx/filter #(= (:type %) key))
|
(rx/filter #(= (:type %) key))
|
||||||
(rx/map deref)))]
|
(rx/map deref)))]
|
||||||
|
|
||||||
(mf/with-effect [@state key id]
|
(mf/with-effect [state key id]
|
||||||
(mbc/emit! id key @state)
|
(mbc/emit! id key state)
|
||||||
(swap! storage assoc key @state))
|
(swap! storage assoc key state))
|
||||||
|
|
||||||
(use-stream stream (partial reset! state))
|
(use-stream stream (partial reset! state*))
|
||||||
state))
|
|
||||||
|
state*))
|
||||||
|
|
||||||
(defonce ^:private intersection-subject (rx/subject))
|
(defonce ^:private intersection-subject (rx/subject))
|
||||||
(defonce ^:private intersection-observer
|
(defonce ^:private intersection-observer
|
||||||
|
|
Loading…
Reference in a new issue