Documentation ¶
Overview ¶
Package view is a small library for organizing view-related code written in pure go which compiles to javascript via gopherjs (https://github.com/gopherjs/gopherjs). View includes a View interface and some helper functions for operating on views (e.g. Append, Replace, Remove, AddEventListener, etc.). View works great as a stand-alone package or in combination with other Humble packages (https://github.com/go-humble).
Version 0.3.1 ¶
For the full source code, a getting started guide, and more information visit https://github.com/go-humble/view.
Index ¶
- func Append(parent View, child View)
- func AppendToEl(parent dom.Element, child View)
- func Hide(v View)
- func InsertBefore(v View, before View)
- func InsertBeforeEl(v View, before dom.Element)
- func Remove(v View)
- func Replace(new View, old View)
- func ReplaceEl(new View, old dom.Element)
- func Show(v View)
- type DefaultView
- type EventListener
- type View
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Append ¶
Append appends child to a parent View. More specifically, it appends child.Element() to parent.Element() using the appendChild method from the DOM API.
func AppendToEl ¶
AppendToEl appends child to a parent element. More specifically, it appends child.Element() to parent using the appendChild method from the DOM API.
func Hide ¶
func Hide(v View)
Hide hides the view from the DOM by adding the inline style "display:none". Hide is safe to use even if you have other attributes and inline styles. It has no effect if the view is already hidden.
func InsertBefore ¶ added in v0.3.0
InsertBefore inserts v directly before before. More specifically, it inserts v.Element() before before.Element() using the insertBefore method from the DOM API.
func InsertBeforeEl ¶ added in v0.3.0
InsertBeforeEl inserts v directly before before. More specifically, it inserts v.Element() using the insertBefore method from the DOM API.
func Remove ¶
func Remove(v View)
Remove removes the view from the DOM entirely. It does not destory the Element propery of the view.
func Replace ¶
Replace replaces an old View with new. More specifically, it replaces old.Element() with new.Element() using the replaceChild method from the DOM API.
Types ¶
type DefaultView ¶
type DefaultView struct {
// contains filtered or unexported fields
}
DefaultView provides an implementation of the Element method of the View interface, and is meant to be embedded. When Element is called on DefaultView (or a struct that embeds DefaultView), it will create a new div element if an element has not yet been assigned to the view.
func (*DefaultView) Element ¶
func (v *DefaultView) Element() dom.Element
Element satisfies View.Element. If the view does not already have an element assigned, it creates a new div element (but does not insert it into the DOM). If the view already has an element assigned, it returns the element.
func (*DefaultView) SetElement ¶
func (v *DefaultView) SetElement(el dom.Element)
SetElement can be used to manually set the element for a view.
type EventListener ¶ added in v0.2.0
type EventListener struct {
// contains filtered or unexported fields
}
EventListener represents a listener attached to a single type of event on one or more elements.
func AddEventListener ¶ added in v0.2.0
func AddEventListener(view View, eventType string, selector string, listener func(dom.Event)) *EventListener
AddEventListener addds an event listener to one or more child elements of the view. selector is a query selector which starts at the view's root element. AddEventListener will add an event listener to *all* child elements that match the given selector. listener is a function that will be called when the event is triggered. Because of the way gopherjs works, listener cannot be a blocking function. See https://github.com/gopherjs/gopherjs#goroutines for more information. If the view is re-rendered, you may need to remove the old listeners and call AddEventListener again.
func (*EventListener) Elements ¶ added in v0.2.0
func (eventListener *EventListener) Elements() []dom.Element
Elements returns a slice of all elements that the event listener is attached to.
func (*EventListener) Remove ¶ added in v0.2.0
func (eventListener *EventListener) Remove()
Remove removes the event listener from all elements.