package react const testVersion = 4 /* reactor */ type react struct { } func New() Reactor { return &react{} } func (r *react) CreateCompute1(c Cell, f func(int) int) ComputeCell { cc := &compuCell{ eval: func() int { return f(c.Value()) }, cb: make(map[CallbackHandle]func(int)), } return cc } func (r *react) CreateCompute2(c1, c2 Cell, f func(int, int) int) ComputeCell { cc := &compuCell{ eval: func() int { return f(c1.Value(), c2.Value()) }, cb: make(map[CallbackHandle]func(int)), } return cc } func (r *react) CreateInput(i int) InputCell { return &inputCell{ value: i, } } /* input cell */ type inputCell struct { value int } func (c *inputCell) SetValue(i int) { // TODO call back if c.value != i { c.value = i } } func (c *inputCell) Value() int { return c.value } /* compute cell */ type compuCell struct { eval func() int cb map[CallbackHandle]func(int) } func (c *compuCell) AddCallback(f func(int)) CallbackHandle { c.cb[&f] = f return &f } func (c *compuCell) RemoveCallback(h CallbackHandle) { delete(c.cb, h) } func (c *compuCell) Value() int { return c.eval() }