controller

package
v0.0.0-...-6d4967a Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package controller manages bindings with a model, and provides mutation methods

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ActionError

func ActionError(code string, err error) error

ActionError returns err with a code for the browser, which looks up a translated message by it and falls back to err's text. Wrapping err keeps it reachable with errors.Is and errors.As.

func AddData

func AddData[K any](c *Controller, formID string, elementIDs []string, source iter.Seq2[K, string]) error

AddData clears and populates a data source from an iterator

Types

type ActionFunc

type ActionFunc func(ctx context.Context, args json.RawMessage) (any, error)

ActionFunc handles an action the browser calls by name and waits on. args is the call's JSON arguments, empty when there are none. The result goes back to the browser as JSON. An error goes back with the code of the first error in its chain that has a Code() string method, such as one made by ActionError, so the browser can show a translated message.

type Controller

type Controller struct {
	Browser wsrpc.Browser
	// contains filtered or unexported fields
}

Controller handles the interaction of observable bindings between the model and the browser. It also handles action bindings with clickable objects.

func New

func New(server *wsrpc.Server, browser wsrpc.Browser, namespace string) *Controller

New creates a new Controller instance given the web server's RPC service and a connection to the browser. namespace specifies the browser's binding namespace to use with this Controller's instance.

func Start

func Start(ctx context.Context, ws *websocket.Conn) (c *Controller, done <-chan struct{}, err error)

Start starts server side rpc and creates a Controller. wait on the returned channel after creating your bindings.

func (*Controller) BindAction

func (c *Controller) BindAction(element, action string, target func(string)) (err error)

func (*Controller) BindValues

func (c *Controller) BindValues(
	name string,
	formID string,
	elements []string,
	source observable.Source,
) error

BindValues creates value bindings.

func (*Controller) HandleAction

func (c *Controller) HandleAction(action string, fn ActionFunc)

HandleAction answers calls to an action from the browser, which waits for fn's result. Unlike Controller.BindAction, it binds no element, so a page that renders its own controls can call it.

Handle actions before binding values: a page that renders its own form takes a bound form as ready, and may call an action straight away.

func (*Controller) Release

func (c *Controller) Release()

Release removes all bindings

Jump to

Keyboard shortcuts

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