diff --git a/go/react/react.go b/go/react/react.go index e042293..29293c2 100644 --- a/go/react/react.go +++ b/go/react/react.go @@ -1,5 +1,7 @@ package react +import "strconv" + const testVersion = 4 // MyReactor implements Reactor @@ -18,6 +20,7 @@ func New() *MyReactor { func (r *MyReactor) CreateInput(i int) InputCell { r.lastId++ ic := MyCell{val: i, id: r.lastId} + ic.previousVal = ic.Value() return &ic } @@ -27,6 +30,7 @@ func (r *MyReactor) CreateCompute1(c Cell, f func(int) int) ComputeCell { r.lastId++ cc := &MyCell{id: r.lastId, isComputed: true} cc.compVal = func() int { return f(c.Value()) } + cc.previousVal = cc.Value() c.(*MyCell).addDependent(cc) return cc } @@ -37,6 +41,7 @@ func (r *MyReactor) CreateCompute2(c1, c2 Cell, f func(int, int) int) ComputeCel r.lastId++ cc := &MyCell{id: r.lastId, isComputed: true} cc.compVal = func() int { return f(c1.Value(), c2.Value()) } + cc.previousVal = cc.Value() c1.(*MyCell).addDependent(cc) c2.(*MyCell).addDependent(cc) return cc @@ -73,8 +78,13 @@ func (c *MyCell) SetValue(i int) { c.updated() } +func i(v int) string { + return strconv.Itoa(v) +} + func (c *MyCell) updated() { if c.Value() == c.previousVal { + // Value didn't change, done. return } c.previousVal = c.Value()