Skip to content

Latest commit

 

History

History
46 lines (34 loc) · 909 Bytes

README.md

File metadata and controls

46 lines (34 loc) · 909 Bytes

Go LiveView

Go backend library for the Phoenix LiveView JS client. Enables rich, real-time user experiences with server-rendered HTML.

This is still very much a work in progress. The API is not stable and is subject to change.

Basic Example:

type Live struct {
	Count int
}

func (l *Live) Event(s lv.Socket, event string, _ params.Params) error {
	if event == "inc" {
		l.Count++
	}

	if event == "dec" {
		l.Count--
	}

	return nil
}

func (l *Live) Render(_ rend.Node) (rend.Node, error) {
	return html.Div(
		html.H1(
			std.Text(&l.Count), // use pointer for dynamic values to optimize diffs to the client.
		),
		html.Button(
			std.Text("inc"),
			html.Attr("phx-click", "inc"),
		),
		html.Button(
			std.Text("dec"),
			html.Attr("phx-click", "dec"),
		),
	), nil
}

See the examples directory for full examples.