Documentation
¶
Index ¶
Constants ¶
const JSTag template.HTML = `` /* 149-byte string literal not displayed */
JSTag is the script tags that should be included in pages that use live views.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
A Controller manages a collection of live views and their associated websockets.
func (*Controller) QuerySelector ¶
func (c *Controller) QuerySelector(v View, selector string) *ElementRef
QuerySelector returns a reference to the first element in the view that matches selector. It does not check to make sure that the element actually exists in the client browser.
func (*Controller) Register ¶
func (c *Controller) Register(views ...View)
Register registers Views with c, and prepares to receive websocket connections for them.
func (*Controller) Render ¶
func (c *Controller) Render(w io.Writer, v View)
Render renders v to e, wrapped in a div that makes it a live view. The View is automatically Registered if it was not registered already.
func (*Controller) ServeHTTP ¶
func (c *Controller) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements the http.Handler interface, to accept incoming websocket connections and serve the necessary JavaScript file. The Controller should be set up to handle the "/live-view/" path.
func (*Controller) Update ¶
func (c *Controller) Update(v View) error
Update re-renders v and sends the updated HTML to the client.
type ElementRef ¶
type ElementRef struct {
// contains filtered or unexported fields
}
An ElementRef points to an element in a live view, and can be used to perform actions on it remotely.
func (*ElementRef) Do ¶
func (e *ElementRef) Do(script ...interface{}) error
Do executes a snippet of JavaScript on the client. It runs with "this" set to the element referenced by e.
func (*ElementRef) SetInnerHTML ¶
func (e *ElementRef) SetInnerHTML(content ...interface{}) error
SetInnerHTML sets e's innerHTML. The content is processed with an Escaper from github.com/andybalholm/escaper.
func (*ElementRef) SetTextContent ¶
func (e *ElementRef) SetTextContent(s string) error
SetTextContent sets e's textContent to s.
type Event ¶
type Event struct { // Event is the name that was assigned to the event in the HTML markup // (e.g. in the live-click attribute). Event string `json:"event"` // If the target of the event is a form control, Value is its current value. Value string `json:"value"` // If the event is a form submission, FormData is the values from the form. FormData url.Values `json:"form_data"` ChannelID string `json:"channel"` }
An Event represents an action by the user, such as clicking a button. There are also special Events named "connect" and "disconnect" that take place when the View's websocked is connected and disconnected.