nasan016 / gofer Goto Github PK
View Code? Open in Web Editor NEWVue.js reactivity in Go
Vue.js reactivity in Go
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"
)
func main() {
count1 := gofer.Ref(0)
count2 := gofer.Ref(0)
gofer.WatchEffect(func() {
// Operations that I want to execute only if count1 changes
fmt.Println("count1 = ", count1.GetValue())
})
// BUG: This function overrides the previous function
gofer.WatchEffect(func() {
// Operations that I want to execute only if count2 changes
fmt.Println("count2 = ", count2.GetValue())
})
scanner := bufio.NewScanner(os.Stdin)
fmt.Print(">>> ")
for scanner.Scan() {
text := scanner.Text()
if text == "increment count1" {
count1.SetValue(count1.GetValue() + 2)
}
if text == "increment count2" {
count2.SetValue(count2.GetValue() + 3)
}
fmt.Print("\n>>>")
}
}
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:
func main() {
countNotInEffect := gofer.Ref(0)
gofer.WatchEffect(func () {
fmt.Println("executing effect")
})
// The effect is executed anyways
countNotInEffect.SetValue(countNotInEffect.GetValue() + 1)
}
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())
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.