You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So I tried the next code (minimal representation) and got an unexpected behaviour:
main.go:
package main
import (
"bufio""fmt""os""github.com/nasan016/gofer"
)
funcmain() {
count1:=gofer.Ref(0)
count2:=gofer.Ref(0)
gofer.WatchEffect(func() {
// Operations that I want to execute only if count1 changesfmt.Println("count1 = ", count1.GetValue())
})
// BUG: This function overrides the previous functiongofer.WatchEffect(func() {
// Operations that I want to execute only if count2 changesfmt.Println("count2 = ", count2.GetValue())
})
scanner:=bufio.NewScanner(os.Stdin)
fmt.Print(">>> ")
forscanner.Scan() {
text:=scanner.Text()
iftext=="increment count1" {
count1.SetValue(count1.GetValue() +2)
}
iftext=="increment count2" {
count2.SetValue(count2.GetValue() +3)
}
fmt.Print("\n>>>")
}
}
What I expected:
I thought that WatchEffect tracks the Refs, but this is not the case, even if I set Ref's value that are not supposed to be tracked by the effect (because this are not inside of the effect), the WatchEffect function is executed anyways. Something like this:
funcmain() {
countNotInEffect:=gofer.Ref(0)
gofer.WatchEffect(func () {
fmt.Println("executing effect")
})
// The effect is executed anywayscountNotInEffect.SetValue(countNotInEffect.GetValue() +1)
}
Suggested solution:
See vue's watch function, note that takes in an array of reactive dependencies, suggested function signature to mimic the vue's: Watch[T any](deps []*gofer.RefImpl[T], effectFunc func())
The text was updated successfully, but these errors were encountered:
So I tried the next code (minimal representation) and got an unexpected behaviour:
main.go
:What I expected:
I thought that WatchEffect tracks the Refs, but this is not the case, even if I set Ref's value that are not supposed to be tracked by the effect (because this are not inside of the effect), the WatchEffect function is executed anyways. Something like this:
Suggested solution:
See vue's
watch
function, note that takes in an array of reactive dependencies, suggested function signature to mimic the vue's:Watch[T any](deps []*gofer.RefImpl[T], effectFunc func())
The text was updated successfully, but these errors were encountered: