summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-08-28 19:07:03 +0200
committerDimitri Sokolyuk <demon@dim13.org>2016-08-28 19:07:03 +0200
commit13444d068d2428fd2592420591a7a5f2432350e0 (patch)
tree8093ea9409dfd9d7c1db4be9d81dc658e4e183f3
parent9e60fbfff0e68460629a8560a50a418227a514a8 (diff)
React WIP
-rw-r--r--go/react/react.go64
1 files changed, 64 insertions, 0 deletions
diff --git a/go/react/react.go b/go/react/react.go
new file mode 100644
index 0000000..1f93906
--- /dev/null
+++ b/go/react/react.go
@@ -0,0 +1,64 @@
+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
+}