Skip to content

otaxhu/go-ref

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Reactive primitives in Go

Library for reactive values in idiomatic Go

Installation:

  1. Execute this command on your terminal:
$ go get github.com/otaxhu/go-ref
  1. Import this library with the name ref, given that go-ref is an invalid import name

Quick Usage:

package main

import (
    "context"

    "github.com/otaxhu/go-ref"
)

func main() {
    // optionally you can specify the generic type
    count := ref.NewRef[int](0)

    ref.Watch[int](func(actualValues, prevValues []int, ctx context.Context) {
        fmt.Println("the actual value of count is:", actualValues[0])
        fmt.Println("the previous value of count was:", prevValues[0])
    }, count)

    // Some event that triggers the change of count
    if userClicked {
        count.SetValue(count.Value() + 1)
    }
}

You can also use the ctx variable inside of the WatcherFunc to pass it to functions that performs cancelation logic, this cancel signal is send only if there is a new value setted to the Ref

About

Reactive primitives in Go.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages