From 9e60fbfff0e68460629a8560a50a418227a514a8 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sun, 28 Aug 2016 14:53:42 +0200 Subject: Import react problem --- go/react/interfaces.go | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 go/react/interfaces.go (limited to 'go/react/interfaces.go') diff --git a/go/react/interfaces.go b/go/react/interfaces.go new file mode 100644 index 0000000..05f3e42 --- /dev/null +++ b/go/react/interfaces.go @@ -0,0 +1,49 @@ +package react + +// A Reactor manages linked cells. +type Reactor interface { + // CreateInput creates an input cell linked into the reactor + // with the given initial value. + CreateInput(int) InputCell + + // CreateCompute1 creates a compute cell which computes its value + // based on one other cell. The compute function will only be called + // if the value of the passed cell changes. + CreateCompute1(Cell, func(int) int) ComputeCell + + // CreateCompute2 is like CreateCompute1, but depending on two cells. + // The compute function will only be called if the value of any of the + // passed cells changes. + CreateCompute2(Cell, Cell, func(int, int) int) ComputeCell +} + +// A Cell is conceptually a holder of a value. +type Cell interface { + // Value returns the current value of the cell. + Value() int +} + +// An InputCell has a changeable value, changing the value triggers updates to +// other cells. +type InputCell interface { + Cell + + // SetValue sets the value of the cell. + SetValue(int) +} + +// A ComputeCell always computes its value based on other cells and can +// call callbacks upon changes. +type ComputeCell interface { + Cell + + // AddCallback adds a callback which will be called when the value changes. + // It returns a callback handle which can be used to remove the callback. + AddCallback(func(int)) CallbackHandle + + // RemoveCallback removes a previously added callback, if it exists. + RemoveCallback(CallbackHandle) +} + +// A CallbackHandle is used to remove previously added callbacks, see ComputeCell. +type CallbackHandle interface{} -- cgit v1.2.3