Replies: 4 comments 4 replies
-
Sorry for the confusion. import {memoize} from 'proxy-memoize'
const _c = memoize(snap => snap.a + snap.b)
const store = proxy({
a: 1,
b: 2,
get c() {
- return _c(snapshot(store))
+ return _c(snapshot(snapshot(store)))
}
}) |
Beta Was this translation helpful? Give feedback.
-
looks like the double snapshot not working |
Beta Was this translation helpful? Give feedback.
-
Re-reading the description, I think nested computeds are not supported now. Maybe a workaround is to use |
Beta Was this translation helpful? Give feedback.
-
can it be written like this @dai-shi ?
or |
Beta Was this translation helpful? Give feedback.
-
CSB
https://codesandbox.io/s/valtio-countdown-to-do-list-forked-c4bii0?file=/src/App.tsx
valtio has deprecated
proxyWithComputed
and recommend usegetter
to implement computed.I never read the source code of
proxyWithComputed
, but a lot with getter computed because I'm troubled.useSnapshot
normal case if our code is using
useSnapshot
.snapshot()
get xxxgetter(){ }
getters are evaluated frequently, so we need cache.
cache is hard
recommend way
this pattern has unexpected when computed nested
for
x
, insideget x(){}
snapshot(store).y
isundefined
because insidesnapshot()
useReflect.ownKeys(target).forEach((key) =>{})
,x
index smaller thany
for
z
, insideget z(){}
snapshot(store).y
has value, but still NaN insnap.y
https://codesandbox.io/s/valtio-countdown-to-do-list-forked-c4bii0?file=/src/App.tsx
with valtio@1.5.2
with valtio@1.10.3
I have tried remove
snapshot()
in getters and manualy select dep likestore.y
, make snapshot(dep), and use plainmemoize-one
, butsnapshot()
is not smart enough.if store.y returns a array, in x or z, store.y switchs between
Proxy target an Array
andAn array of Proxied Items
.snapshot()
fails onAn array of Proxied Items
.SO I end up with no cache. Can't make things work with cache 😂
Beta Was this translation helpful? Give feedback.
All reactions