-
Notifications
You must be signed in to change notification settings - Fork 0
/
observableObject.go
49 lines (39 loc) · 1.07 KB
/
observableObject.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
type Event struct {
EType int
Object interface{}
Payload interface{}
}
type EventChanel chan Event
type ObservableObjectInterface interface {
Trigger(event Event, object interface{}, payload interface{})
GetEventChanel() EventChanel
}
type ObservableObject struct {
Owner ObservableObjectInterface
output EventChanel
}
func (receiver *ObservableObject) Trigger(event Event, object interface{}, payload interface{}) {
event.Object = object
event.Payload = payload
if DEBUG_EVENT {
logger.Printf("trigger event %d, %T, %+v \n", event.EType, object, object)
}
receiver.output <- event
}
func (receiver *ObservableObject) GetEventChanel() EventChanel {
return receiver.output
}
func (receiver *ObservableObject) Free() error {
return nil
}
func (receiver *ObservableObject) Copy() *ObservableObject {
instance := *receiver
return &instance
}
func NewObservableObject(output EventChanel, owner ObservableObjectInterface) (*ObservableObject, error) {
instance := new(ObservableObject)
instance.Owner = owner
instance.output = output
return instance, nil
}