A Go reactive library inspired by Vue.js.
use go get
to install this package
go get github.com/nasan016/gofer
To start, define the GofeR package and import the library.
package main
import(
gf "github.com/nasan016/gofer"
)
GofeR brings the following reactive primitives from Vue to Go:
Revenue
package main
import (
"fmt"
gf "github.com/nasan016/gofer"
)
func main() {
price := gf.Ref(2)
quantity := gf.Ref(1000)
revenue := gf.Computed(func() int {
return price.GetValue() * quantity.GetValue()
})
gf.WatchEffect(func() {
fmt.Println("revenue:", revenue.GetValue())
})
price.SetValue(price.GetValue() / 2)
price.SetValue(price.GetValue() * 10)
quantity.SetValue(quantity.GetValue() + 500)
}
Output
revenue: 2000
revenue: 1000
revenue: 10000
revenue: 15000
Increment
package main
import (
"fmt"
gf "github.com/nasan016/gofer"
)
func main() {
x := gf.Ref(0)
y := gf.Ref(0)
gf.WatchEffect(func() {
fmt.Println("x: ", x.GetValue())
fmt.Println("y: ", y.GetValue())
fmt.Println("")
})
increment(x)
increment(y)
increment(x)
}
func increment(ref *gf.RefImpl[int]) {
ref.SetValue(ref.GetValue() + 1)
}
Output
x: 0
y: 0
x: 1
y: 0
x: 1
y: 1
x: 2
y: 1