Skip to content

nasan016/gofer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GofeR logo

Go

GofeR

A Go reactive library inspired by Vue.js.

Install

use go get to install this package

go get github.com/nasan016/gofer

Getting Started

To start, define the GofeR package and import the library.

package main

import(
    gf "github.com/nasan016/gofer"
)

Usage

GofeR brings the following reactive primitives from Vue to Go:

Examples

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

Checkout Effekt by bendgk

Releases

No releases published

Packages

No packages published

Languages