Code Monkey home page Code Monkey logo

gofer's Introduction

some boring projects:

gofer's People

Contributors

nasan016 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

ninedraft otaxhu

gofer's Issues

Bug: WatchEffect is overriding the previous function

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>>>")
	}
}

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:

func main() {
	countNotInEffect := gofer.Ref(0)
	gofer.WatchEffect(func () {
		fmt.Println("executing effect")
	})
	// The effect is executed anyways
	countNotInEffect.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())

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.