tweak: utilise use-layout-effect to safely update atom
This commit is contained in:
parent
e6623ef370
commit
c777771524
|
@ -92,12 +92,18 @@
|
||||||
(defn make-snapshot-handler-factory [snapshot]
|
(defn make-snapshot-handler-factory [snapshot]
|
||||||
(let [storage (rn/use-memo #(atom {}) [])
|
(let [storage (rn/use-memo #(atom {}) [])
|
||||||
capture (rn/use-memo #(atom snapshot) [])
|
capture (rn/use-memo #(atom snapshot) [])
|
||||||
|
_update (rn/use-layout-effect
|
||||||
|
(fn []
|
||||||
|
(swap! capture (fn [_] snapshot)))
|
||||||
|
snapshot)
|
||||||
factory (rn/use-memo
|
factory (rn/use-memo
|
||||||
(do (swap! capture (fn [_] snapshot))
|
(fn []
|
||||||
#(memo storage
|
(fn [handler]
|
||||||
|
((memo storage
|
||||||
(fn [callback]
|
(fn [callback]
|
||||||
(fn [event]
|
(fn [event]
|
||||||
(callback @capture event)))))
|
(callback @capture event))))
|
||||||
|
handler)))
|
||||||
[storage capture])]
|
[storage capture])]
|
||||||
{:factory factory
|
{:factory factory
|
||||||
:storage storage}))
|
:storage storage}))
|
||||||
|
|
Loading…
Reference in New Issue