How to wrap a store without losing reactivity
Given a store like this:
How can I do the following without losing reactivity?
9 Replies
make
userWrapper
a functionIsn't there a way to do this with userWrapper being a proxy?
You could indeed use a real proxy for userWrapper, like:
P.S. this example is incomplete and would need additional code if the proxy has to feel like a real object.
Interesting. Can you clarify what you mean by "feel like a real object"?
The proxy handler would have to include things like
ownKeys
, has
and stuff like that, otherwise Object.keys(theProxy) would return the wrong thingThere's a builtin helper for cases like this 😁 but the original use case was for something fundamental.
🥁 🥁 🥁
Clever, i never had the idea to use mergeProps like this 😆
Yeah, it's the same trick https://playground.solidjs.com/anonymous/2505074a-ab78-42e9-af76-6537ebd107a4 (check output tab)
It's the reactivity's equivalent of js native spread
I was gonna say it would be cool if there was an utility for this. Also didn't know mergeProps could be used here.
Nice! I guess this answers my question 🙂