package react const testVersion = 4 type react struct { } type inputCell struct { cell } type computeCell struct { cell cb map[CallbackHandle]func(int) } func newComputeCell() *computeCell { return &computeCell{cb: make(map[CallbackHandle]func(int))} } type cell struct { value int } func New() Reactor { return &react{} } func (r *react) CreateCompute1(c Cell, f func(int) int) ComputeCell { return &computeCell{ cell: cell{value: f(c.Value())}, cb: make(map[CallbackHandle]func(int)), } } func (r *react) CreateCompute2(c1, c2 Cell, f func(int, int) int) ComputeCell { return &computeCell{ cell: cell{value: f(c1.Value(), c2.Value())}, cb: make(map[CallbackHandle]func(int)), } } func (r *react) CreateInput(i int) InputCell { return &inputCell{ cell: cell{value: i}, } } func (c *computeCell) AddCallback(f func(int)) CallbackHandle { c.cb[&f] = f return &f } func (c *computeCell) RemoveCallback(h CallbackHandle) { delete(c.cb, h) } func (c *inputCell) SetValue(i int) { c.value = i } func (c cell) Value() int { return c.value }