Documentation ¶
Index ¶
- type CaptureFunc
- type Capturer
- type Emitter
- func (em *Emitter) AddCapturer(handler CaptureFunc) (capturer *Capturer)
- func (em *Emitter) AddListener(event EventType, handler HandleFunc) (listener *Listener)
- func (em *Emitter) EmitEvent(event EventType, arguments ...interface{})
- func (em *Emitter) ListenOnce(event EventType, handler HandleFunc) (listener *Listener)
- func (em *Emitter) RemoveAllCapturers()
- func (em *Emitter) RemoveAllListeners()
- func (em *Emitter) RemoveAllListenersForEvent(event EventType)
- func (em *Emitter) RemoveCapturer(capturer *Capturer)
- func (em *Emitter) RemoveListener(event EventType, listener *Listener)
- type EventEmitter
- type EventType
- type HandleFunc
- type Listener
- type Observable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CaptureFunc ¶
type CaptureFunc func(event EventType, arguments ...interface{})
CaptureFunc is a capturer function that can capture all emitted events
type Capturer ¶
type Capturer struct {
// contains filtered or unexported fields
}
Capturer is a container struct used to remove the capturer
type Emitter ¶
type Emitter struct {
// contains filtered or unexported fields
}
Emitter is the base struct which manages event subscriptions and calls all registered handlers on event emits.
func NewEmitter ¶
NewEmitter creates a new event emitter that implements the Observable interface. Async determines whether events listeners fire in separate goroutines or not.
func (*Emitter) AddCapturer ¶
func (em *Emitter) AddCapturer(handler CaptureFunc) (capturer *Capturer)
AddCapturer adds an event capturer for all events
func (*Emitter) AddListener ¶
func (em *Emitter) AddListener(event EventType, handler HandleFunc) (listener *Listener)
AddListener adds a listener for the given event type
func (*Emitter) ListenOnce ¶
func (em *Emitter) ListenOnce(event EventType, handler HandleFunc) (listener *Listener)
ListenOnce adds a listener for the given event type that removes itself after it has been fired once
func (*Emitter) RemoveAllCapturers ¶
func (em *Emitter) RemoveAllCapturers()
RemoveAllCapturers removes all registered capturers
func (*Emitter) RemoveAllListeners ¶
func (em *Emitter) RemoveAllListeners()
RemoveAllListeners removes all registered listeners for all event types
func (*Emitter) RemoveAllListenersForEvent ¶
RemoveAllListenersForEvent removes all registered listeners for a given event type
func (*Emitter) RemoveCapturer ¶
RemoveCapturer removes the given capturer
func (*Emitter) RemoveListener ¶
RemoveListener removes the registered given listener for the given event
type EventEmitter ¶
type EventEmitter interface { // EmitEvent emits the given event to all listeners and capturers EmitEvent(event EventType, arguments ...interface{}) }
EventEmitter is the interface which allows implementers to emit events
type EventType ¶
type EventType string
EventType is a type of event, each type of event should have a different type
type HandleFunc ¶
type HandleFunc func(arguments ...interface{})
HandleFunc is a handler function for a given event type
type Listener ¶
type Listener struct {
// contains filtered or unexported fields
}
Listener is a container struct used to remove the listener
type Observable ¶
type Observable interface { // AddListener adds a listener for the given event type AddListener(event EventType, handler HandleFunc) (listener *Listener) // ListenOnce adds a listener for the given event type that removes itself after it has been fired once ListenOnce(event EventType, handler HandleFunc) (listener *Listener) // AddCapturer adds an event capturer for all events AddCapturer(handler CaptureFunc) (capturer *Capturer) // RemoveListener removes the registered given listener for the given event RemoveListener(event EventType, listener *Listener) // RemoveCapturer removes the given capturer RemoveCapturer(capturer *Capturer) }
Observable describes an object that can be listened to by event listeners and capturers