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 ¶
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.
Types ¶
type ActionFunc ¶
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 ¶
Controller handles the interaction of observable bindings between the model and the browser. It also handles action bindings with clickable objects.
func New ¶
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.