event

package
v0.4.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 22, 2021 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Enum

type Enum int

Enum is to distinguish event enumeration

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler allows callback registration and event fireing, its simply a way of comunication that comes handy in some cases, though is has performance cost, events are mapped to reflect.Type of an inputted anything, enum events are accessed by indexing into slice, if you don't have to pass arguments with event use Handler.Trigger and Handler.Run as it is cleaner and faster

func NHandler

func NHandler() *Handler

NHandler initializes inner map

func (*Handler) Fire

func (e *Handler) Fire(ev interface{})

Fire launches all event callbacks for given type

func (*Handler) On

func (e *Handler) On(ev interface{}, f func(interface{}))

On registers event callback

func (*Handler) Run

func (e *Handler) Run(en Enum, f func())

Run register enum event callback

func (*Handler) Trigger

func (e *Handler) Trigger(en Enum)

Trigger launches enum event callbacks

type Listener

type Listener struct {
	Name   string
	Block  bool
	Runner StringRunner
	// contains filtered or unexported fields
}

Listener holds function tha gets called when event is triggered if events returns true, all consequent events will get blocked, execution goes from newest to oldest event listener

func (*Listener) Remove

func (e *Listener) Remove()

Remove removes the listener from event handler

type String

type String map[string][]*Listener

String handles event registration for elements

func (String) Add

func (e String) Add(listener *Listener)

Add adds listener to handler, keep the listener accessable if you want to remove it later

func (String) Invoke

func (e String) Invoke(name string, ed interface{})

Invoke invokes the event listeners, removed listeners are skipped and deleted

type StringRunner

type StringRunner func(i interface{})

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL