Closed abdel-17 closed 1 month ago
Latest commit: 4ff1e8a2bf80c328af8e96c4ae755c6e7c98319b
The changes in this PR will be included in the next version bump.
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR
Name | Status | Preview | Last Commit |
---|---|---|---|
runed | ✅ Ready (View Log) | Visit Preview | 4ff1e8a2bf80c328af8e96c4ae755c6e7c98319b |
This PR changes two things about the
watch
helper.Remove the
once: boolean
option in favor of a separatewatchOnce
function. The default behavior forwatch
is to run immediately, unlike in Vue where it runs lazily when a dependency changes, so havingonce: true
behave just likeonMount
by default makes no sense. As an added bonus,watch
is now much simpler internally.To watch for changes to multiple values, you pass an array of getters. Previously, you would pass a getter to an array of state values, but this is kind of ambiguous. What if I want to watch for changes to a single state that happens to be an array?
// proposed change: let a = $state(); let b = $state(); watch([() => a, () => b], ([a, b], [prevA, prevB]) => {...});