base

package
v0.0.0-...-a33cf17 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2016 License: MIT Imports: 6 Imported by: 1

Documentation

Overview

Package base provides core fundation types and structures for haiku.

Index

Constants

This section is empty.

Variables

View Source
var ErrEventNotFound = errors.New("Event not found")

ErrEventNotFound is returned when an event is not found

Functions

func BuildEventID

func BuildEventID(etype, eselect string) string

BuildEventID returns the string represent of the values using the select#event format

func GetEventID

func GetEventID(m EventSubs) string

GetEventID returns the id for a ElemEvent object

Types

type Chain

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

Chain provides a simple middleware like

func NewChain

func NewChain(fx ChainHandler) *Chain

NewChain returns a new Chain instance

func (*Chain) Bind

func (r *Chain) Bind(rnx EventHandler) Chains

Bind provides a wrapper over the Next binder function call

func (*Chain) Chain

func (r *Chain) Chain(rx Chains) Chains

Chain sets the next chains else passes it down to the last chain to set as next chain,returning itself

func (*Chain) HandleContext

func (r *Chain) HandleContext(c Event)

HandleContext calls the next chain if any

func (*Chain) NChain

func (r *Chain) NChain(rx Chains) Chains

NChain sets the next chains else passes it down to the last chain to set as next chain,returning the the supplied chain

func (*Chain) Next

func (r *Chain) Next(rnx ChainHandler) Chains

Next allows the chain of the function as a Handler

func (*Chain) UnChain

func (r *Chain) UnChain()

UnChain unlinks the current chain from the set and reconnects the others

func (*Chain) UseNext

func (r *Chain) UseNext(fl Chains)

UseNext swaps the next chain with the supplied

func (*Chain) UsePrev

func (r *Chain) UsePrev(fl Chains)

UsePrev swaps the previous chain with the supplied

type ChainHandler

type ChainHandler func(Event, EventHandler)

ChainHandler provides a handler for event chain types.

type Chains

type Chains interface {
	HandleContext(Event)
	Next(ChainHandler) Chains
	Chain(Chains) Chains
	NChain(Chains) Chains
	Bind(EventHandler) Chains
	UseNext(Chains)
	UsePrev(Chains)
	UnChain()
}

Chains define a simple chain

func ChainIdentity

func ChainIdentity() Chains

ChainIdentity returns a chain that calls the next automatically

func Connect

func Connect(mo Chains, so ...Chains) Chains

Connect chains second set to the first Chain and returns the first Chain

type ElemEventMux

type ElemEventMux func(Event, func())

ElemEventMux represents a stanard callback function for dom events

type Event

type Event interface {
	Bubbles() bool
	Cancelable() bool
	CurrentTarget() *js.Object
	DefaultPrevented() bool
	EventPhase() int
	Target() *js.Object
	Timestamp() int
	Type() string
	Core() *js.Object
	StopPropagation()
	StopImmediatePropagation()
	PreventDefault()
}

Event defines the base interface for browser events and defines the basic interface methods they must provide

type EventActions

type EventActions interface {
	StopPropagation() bool
	StopImmediatePropagation() bool
	PreventDefault() bool
}

EventActions defines standard actions for event objects.

type EventHandler

type EventHandler func(Event)

EventHandler provides the function type for event callbacks when subscribing to events in Haiku.

type EventManager

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

EventManager provides a deffered event managing sytem for registery events with

func (*EventManager) AddEvent

func (em *EventManager) AddEvent(eo EventSubs) bool

AddEvent adds Event elements into the event manager if a event element is already matching that is the combination of selector#eventtype then it returns false but if added then true

func (*EventManager) AddEvents

func (em *EventManager) AddEvents(ems ...EventSubs)

AddEvents adds a set of ElemEvent into the EventManager

func (*EventManager) AttachManager

func (em *EventManager) AttachManager(esm EventManagers)

AttachManager allows a manager to get attached to another manajor to receive a dom binding when this receives one

func (*EventManager) DetachManager

func (em *EventManager) DetachManager(esm EventManagers)

DetachManager detaches the manager if attached already

func (*EventManager) DisconnectRemoved

func (em *EventManager) DisconnectRemoved()

DisconnectRemoved disconnects all events that must be removed and removes them

func (*EventManager) EachEvent

func (em *EventManager) EachEvent(fx EventSubHandler)

EachEvent runnings a function over all events

func (*EventManager) EachManager

func (em *EventManager) EachManager(fx EventManagerHandler)

EachManager runnings a function over all attached managers

func (*EventManager) GetEvent

func (em *EventManager) GetEvent(event string) (EventSubs, error)

GetEvent returns the event if found by that id

func (*EventManager) HasEvent

func (em *EventManager) HasEvent(m string) bool

HasEvent returns true/false if an event target is already marked using the format selector#eventType

func (*EventManager) HasManager

func (em *EventManager) HasManager(esm EventManagers) bool

HasManager returns true/false if a manager was already attached

func (*EventManager) LoadDOM

func (em *EventManager) LoadDOM(dom *js.Object) bool

LoadDOM passes down the dom element to all EventSub to initialize and listen for their respective events

func (*EventManager) LoadUpEvents

func (em *EventManager) LoadUpEvents()

LoadUpEvents registers the events into the dom object

func (*EventManager) NewEvent

func (em *EventManager) NewEvent(evtype, evselector string) (EventSubs, bool)

NewEvent allows the adding of event using string values

func (*EventManager) NewEventMeta

func (em *EventManager) NewEventMeta(meta EventMeta) (EventSubs, bool)

NewEventMeta allows the adding of event using string values

func (*EventManager) OffloadDOM

func (em *EventManager) OffloadDOM()

OffloadDOM deregisters the dom and offloads its events to allow other dom to be attached. Must call this first before try to use LoadDOM if the EventManager already is loaded

func (*EventManager) RemoveEvent

func (em *EventManager) RemoveEvent(event string)

RemoveEvent removes a event from the list

type EventManagerHandler

type EventManagerHandler func(EventManagers)

EventManagerHandler provides a event type callback for EventManagers.

type EventManagers

type EventManagers interface {
	HasEvent(m string) bool
	GetEvent(event string) (EventSubs, error)
	NewEventMeta(EventMeta) (EventSubs, bool)
	NewEvent(evtype, evselector string) (EventSubs, bool)
	AttachManager(EventManagers)
	DetachManager(EventManagers)
	HasManager(EventManagers) bool
	RemoveEvent(event string)
	AddEvent(EventSubs) bool
	AddEvents(...EventSubs)
	EachEvent(EventSubHandler)
	EachManager(EventManagerHandler)
	DisconnectRemoved()
	OffloadDOM()
	LoadUpEvents()
	LoadDOM(dom *js.Object) bool
}

EventManagers defines the Event.EventManager interface type and is used to clean up import path usage and standardize the api

func NewEventManager

func NewEventManager() EventManagers

NewEventManager returns a new event manager instance

type EventMeta

type EventMeta interface {
	EventActions
	Type() string
	Target() string
	Removed() bool
	Remove()
}

EventMeta provides a basic information about the events and what its targets

type EventMetable

type EventMetable struct {
	EventType                      string
	EventTarget                    string
	ShouldStopPropagation          bool
	ShouldStopImmediatePropagation bool
	ShouldPreventDefault           bool
	ShouldRemove                   bool
}

EventMetable provides a concrete structural implementation of the EventMeta interface.

func (*EventMetable) PreventDefault

func (e *EventMetable) PreventDefault() bool

PreventDefault returns the true/false if event should prevent its default behaviour.

func (*EventMetable) Remove

func (e *EventMetable) Remove()

Remove sets the event meta as removed.

func (*EventMetable) Removed

func (e *EventMetable) Removed() bool

Removed returns true/false if the event meta is marked removed.

func (*EventMetable) StopImmediatePropagation

func (e *EventMetable) StopImmediatePropagation() bool

StopImmediatePropagation returns the true/false if event should stop immediate propagation.

func (*EventMetable) StopPropagation

func (e *EventMetable) StopPropagation() bool

StopPropagation returns the true/false if event should stop propagation.

func (*EventMetable) Target

func (e *EventMetable) Target() string

Target returns the target of event.

func (*EventMetable) Type

func (e *EventMetable) Type() string

Type returns the type of event.

type EventObject

type EventObject struct {
	*js.Object
}

EventObject implements the Event interface and is embedded by concrete event types.

func (*EventObject) Bubbles

func (ev *EventObject) Bubbles() bool

Bubbles returns true/false if the event can bubble up

func (*EventObject) Cancelable

func (ev *EventObject) Cancelable() bool

Cancelable returns true/false if the event is cancelable

func (*EventObject) Core

func (ev *EventObject) Core() *js.Object

Core returns the internal js object for the event

func (*EventObject) CurrentTarget

func (ev *EventObject) CurrentTarget() *js.Object

CurrentTarget returns the current target of the event when received

func (*EventObject) DefaultPrevented

func (ev *EventObject) DefaultPrevented() bool

DefaultPrevented returns true/false if the event was prevented

func (*EventObject) EventPhase

func (ev *EventObject) EventPhase() int

EventPhase returns the state of the event

func (*EventObject) PreventDefault

func (ev *EventObject) PreventDefault()

PreventDefault prevents the default value of the event

func (*EventObject) StopImmediatePropagation

func (ev *EventObject) StopImmediatePropagation()

StopImmediatePropagation stops the propagation of the event forcefully

func (*EventObject) StopPropagation

func (ev *EventObject) StopPropagation()

StopPropagation stops the propagation of the event

func (*EventObject) Target

func (ev *EventObject) Target() *js.Object

Target returns the target of the event as a js.Object

func (*EventObject) Timestamp

func (ev *EventObject) Timestamp() int

Timestamp returns the event timestamp value as a int (in seconds)

func (*EventObject) Type

func (ev *EventObject) Type() string

Type returns the event type value

type EventSub

type EventSub struct {
	EventMeta
	Chains
	// contains filtered or unexported fields
}

EventSub represent a single event configuration for dom.Elem objects instance which allows chaining of events listeners like middleware

func MetaEventSub

func MetaEventSub(meta EventMeta) *EventSub

MetaEventSub returns a new event using the supplied EventMeta

func NewEventSub

func NewEventSub(evtype, evtarget string) *EventSub

NewEventSub returns a new event element config

func (*EventSub) DOM

func (e *EventSub) DOM(dom *js.Object)

DOM sets up the event subs for listening

func (*EventSub) ID

func (e *EventSub) ID() string

ID returns the event id that EventManager use for this event

func (*EventSub) Offload

func (e *EventSub) Offload()

Offload removes all event bindings from current dom element

func (*EventSub) Trigger

func (e *EventSub) Trigger(h Event)

Trigger provides bypass for triggering this event sub by passing down an event directly without matching target or selector

func (*EventSub) TriggerMatch

func (e *EventSub) TriggerMatch(h Event)

TriggerMatch check if the current event from a specific parent matches the eventarget by using the eventsub selector,if the target is within the results for that selector then it triggers the event subscribers

type EventSubHandler

type EventSubHandler func(EventSubs)

EventSubHandler provides a event type callback for EventSubs.

type EventSubs

type EventSubs interface {
	EventMeta
	Chains
	Offload()
	DOM(*js.Object)
}

EventSubs provides a interface for event registeration subscribers.

type JSEventMux

type JSEventMux func(*js.Object)

JSEventMux represents a js.listener function which is returned when attached using AddEventListeners and is used for removals with RemoveEventListeners

type ListenerStack

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

ListenerStack provides addition of functions into a stack

func NewListenerStack

func NewListenerStack() *ListenerStack

NewListenerStack returns a new ListenerStack instance

func (*ListenerStack) Add

func (f *ListenerStack) Add(fx ElemEventMux) int

Add adds a function into the stack

func (*ListenerStack) Clear

func (f *ListenerStack) Clear()

Clear flushes the stack listener

func (*ListenerStack) DeleteIndex

func (f *ListenerStack) DeleteIndex(ind int)

DeleteIndex removes the function at the provided index

func (*ListenerStack) Each

func (f *ListenerStack) Each(d Event)

Each runs through the function lists and executing with args

func (*ListenerStack) Size

func (f *ListenerStack) Size() int

Size returns the total number of listeners

Jump to

Keyboard shortcuts

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