Replies: 2 comments 2 replies
-
|
I'm not sure the exact requirement, but have you looked / tried this? https://github.com/pmndrs/valtio/blob/main/docs/guides/computed-properties.mdx |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
@dai-shi Thanks, I probably overlooked this kind of usage from the docs: const user = proxy({
name: 'John',
})
const greetings = proxy({
user, // attach the `user` proxy object
// OK - can reference user props via `this`
get greetingEn() {
return 'Hello ' + this.user.name
},
})So it appears that the state above could be written as: const four = proxy({
counter4: 0,
oneTwoThree,
get sum() {
return this.oneTwoThree.counter1And2.counter1 + this.oneTwoThree.counter1And2.counter2 + this.counter4
},
})What's the use case for derive() then in a similar situation? Except that it provides fine control with underive |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm moving pinia stores that are basically thin wrappers around vue reactivity api to valtio:
From what I see, it would be rewritten as:
Currently derive() looks like a close relative to computeds/getters but it's low level. The problem I see is that when there's a need to refactor a oneTwoThreeFour store to oneTwoThree and four, this results in more code changes including the need to keep state and derived state in separate variables (four and fourPartial). While the extraction of useOneTwoThree in pinia was trivial (getters also can uniformly refer a store through
this, both state and other getters)The thing that concerns me is the necessity to explicitly use get() in derive. Since both proxies are valtio, it could be expected that they could be able to be aware of each other and be able to track changes.
Any suggestions how the situation could it be improved? I hope I could end up with some more high level api for the stores
Beta Was this translation helpful? Give feedback.
All reactions