comm

– import “gomatcha.io/matcha/comm”

Package comm provides primitives for signaling when an object has changed. This is done through the Notifier interface and its related children.

type BoolNotifier

type BoolNotifier interface {
	Notifier
	Value() bool
}

BoolNotifier wraps Notifier with an additional Value() method which returns a bool.

type BoolRWNotifier

type BoolRWNotifier interface {
	BoolNotifier
	SetValue(bool)
}

BoolRWNotifier wraps BoolNotifier with an additional SetValue(bool) method.

type BoolValue

type BoolValue struct {
}

BoolValue implements the BoolRWNotifier interface.

func (*BoolValue) Notify

func (v *BoolValue) Notify(f func()) Id

Notify implements the BoolNotifier interface.

func (*BoolValue) SetValue

func (v *BoolValue) SetValue(val bool)

SetValue updates v.Value() and notifies any observers.

func (*BoolValue) Unnotify

func (v *BoolValue) Unnotify(id Id)

Unnotify implements the BoolNotifier interface.

func (*BoolValue) Value

func (v *BoolValue) Value() bool

Value implements the BoolNotifier interface.

type Bytes

type Bytes struct {
}

Bytes implements the BytesRWNotifier interface.

func (*Bytes) Notify

func (v *Bytes) Notify(f func()) Id

Notify implements the BytesNotifier interface.

func (*Bytes) SetValue

func (v *Bytes) SetValue(val []byte)

SetValue updates v.Value() and notifies any observers.

func (*Bytes) Unnotify

func (v *Bytes) Unnotify(id Id)

Unnotify implements the BytesNotifier interface.

func (*Bytes) Value

func (v *Bytes) Value() []byte

Value implements the BytesNotifier interface.

type BytesNotifier

type BytesNotifier interface {
	Notifier
	Value() []byte
}

BytesNotifier wraps Notifier with an additional Value() method which returns a []byte.

type BytesRWNotifier

type BytesRWNotifier interface {
	BytesNotifier
	SetValue([]byte)
}

BytesRWNotifier wraps BytesNotifier with an additional SetValue([]byte) method.

type ColorNotifier

type ColorNotifier interface {
	Notifier
	Value() color.Color
}

ColorNotifier wraps Notifier with an additional Value() method which returns a color.Color.

type ColorRWNotifier

type ColorRWNotifier interface {
	ColorNotifier
	SetValue(color.Color)
}

ColorRWNotifier wraps ColorNotifier with an additional SetValue(color.Color) method.

type ColorValue

type ColorValue struct {
}

ColorValue implements the ColorRWNotifier interface.

func (*ColorValue) Notify

func (v *ColorValue) Notify(f func()) Id

Notify implements the ColorRWNotifier interface.

func (*ColorValue) SetValue

func (v *ColorValue) SetValue(val color.Color)

SetValue updates v.Value() and notifies any observers.

func (*ColorValue) Unnotify

func (v *ColorValue) Unnotify(id Id)

Unnotify implements the ColorRWNotifier interface.

func (*ColorValue) Value

func (v *ColorValue) Value() color.Color

Value returns the color.Color stored in v.

type Float64Notifier

type Float64Notifier interface {
	Notifier
	Value() float64
}

Float64Notifier wraps Notifier with an additional Value() method which returns a float64.

type Float64RWNotifier

type Float64RWNotifier interface {
	Float64Notifier
	SetValue(float64)
}

Float64RWNotifier wraps Float64Notifier with an additional SetValue(float64) method.

type Float64Value

type Float64Value struct {
}

Float64Value implements the Float64RWNotifier interface.

func (*Float64Value) Notify

func (v *Float64Value) Notify(f func()) Id

Notify implements the Float64Notifier interface.

func (*Float64Value) SetValue

func (v *Float64Value) SetValue(val float64)

SetValue updates v.Value() and notifies any observers.

func (*Float64Value) Unnotify

func (v *Float64Value) Unnotify(id Id)

Unnotify implements the Float64Notifier interface.

func (*Float64Value) Value

func (v *Float64Value) Value() float64

Value implements the Float64Notifier interface.

type Id

type Id int64

type IntNotifier

type IntNotifier interface {
	Notifier
	Value() int
}

IntNotifier wraps Notifier with an additional Value() method which returns an int.

type IntRWNotifier

type IntRWNotifier interface {
	IntNotifier
	SetValue(int)
}

IntRWNotifier wraps IntNotifier with an additional SetValue(int) method.

type IntValue

type IntValue struct {
}

IntValue implements the IntRWNotifier interface.

func (*IntValue) Notify

func (v *IntValue) Notify(f func()) Id

Notify implements the IntNotifier interface.

func (*IntValue) SetValue

func (v *IntValue) SetValue(val int)

SetValue updates v.Value() and notifies any observers.

func (*IntValue) Unnotify

func (v *IntValue) Unnotify(id Id)

Unnotify implements the IntNotifier interface.

func (*IntValue) Value

func (v *IntValue) Value() int

Value implements the IntNotifier interface.

type InterfaceNotifier

type InterfaceNotifier interface {
	Notifier
	Value() interface{}
}

InterfaceNotifier wraps Notifier with an additional Value() method which returns an empty interface.

type InterfaceRWNotifier

type InterfaceRWNotifier interface {
	InterfaceNotifier
	SetValue(interface{})
}

InterfaceRWNotifier wraps InterfaceNotifier with an additional SetValue(interface{}) method.

type InterfaceValue

type InterfaceValue struct {
}

InterfaceValue implements the InterfaceRWNotifier interface.

func (*InterfaceValue) Notify

func (v *InterfaceValue) Notify(f func()) Id

Notify implements the InterfaceNotifier interface.

func (*InterfaceValue) SetValue

func (v *InterfaceValue) SetValue(val interface{})

SetValue updates v.Value() and notifies any observers.

func (*InterfaceValue) Unnotify

func (v *InterfaceValue) Unnotify(id Id)

Unnotify implements the InterfaceNotifier interface.

func (*InterfaceValue) Value

func (v *InterfaceValue) Value() interface{}

Value returns the interface{} stored in v.

type Notifier

type Notifier interface {
	Notify(f func()) Id
	Unnotify(id Id)
}

Notifier is the interface the wraps the Notify and Unnotify methods.

Notify stores the function f, and calls in the future it when the object updates. It returns an Id which can be used to stop notifications. Every call to Notify should have a corresponding Unnotify or there could be leaks.

type Relay

type Relay struct {
}

Relay implements the Notifier interface, and provides methods for triggering notifications and republishing notifications from other notifiers. It can be embeded into other structs.

func (*Relay) Notify

func (r *Relay) Notify(f func()) Id

Notify implements the Notifier interface.

func (*Relay) Signal

func (r *Relay) Signal()

Signal causes all Notifiers on r to be triggered.

func (*Relay) Subscribe

func (r *Relay) Subscribe(n Notifier)

Subscribes to notifications from n. When n posts a notification, r will also post a notification. For every Subscribe there should be a corresponding Unsubscribe or memory leaks may occur.

func (*Relay) Unnotify

func (r *Relay) Unnotify(id Id)

Unnotify implements the Notifier interface.

func (*Relay) Unsubscribe

func (r *Relay) Unsubscribe(n Notifier)

Unsubscribes from n.

type StringNotifier

type StringNotifier interface {
	Notifier
	Value() string
}

StringNotifier wraps Notifier with an additional Value() method which returns a string.

type StringRWNotifier

type StringRWNotifier interface {
	StringNotifier
	SetValue(string)
}

StringRWNotifier wraps StringNotifier with an additional SetValue(string) method.

type StringValue

type StringValue struct {
}

StringValue implements the StringRWNotifier interface.

func (*StringValue) Notify

func (v *StringValue) Notify(f func()) Id

Notify implements the StringNotifier interface.

func (*StringValue) SetValue

func (v *StringValue) SetValue(val string)

SetValue updates v.Value() and notifies any observers.

func (*StringValue) Unnotify

func (v *StringValue) Unnotify(id Id)

Unnotify implements the StringNotifier interface.

func (*StringValue) Value

func (v *StringValue) Value() string

Value returns the string stored in v.