risa.binding¶
Putting handlers on components, with or without wire arguments.
bind
module-attribute
¶
Put a handler on a component together with its wire arguments.
ui.Button(risa.bind(self.vote, 2)) routes a click on that button to
vote(ctx, 2). It is functools.partial, so arguments go by position or by name,
and nested bind calls merge as partials do: a keyword given twice takes the outer
value.
BindTarget
¶
A handler accessed on a view, as a type checker sees it: a callable of its wire parameters.
Handlerish
¶
What a component takes as its handler: self.vote, or risa.bind(self.vote, 2).
Binding
¶
Binding(
handler_id: str,
version: int,
token: str,
fingerprint: str,
frames: Sequence[Frame],
func_name: str,
owner: type[View] | None = None,
)
Bases: Struct
A handler resolved for one component: where a click routes, and what it carries.
Components resolve the handler they are given into one; it is rarely built by hand.
Attributes:
-
handler_id(str) –The id of the handler.
-
version(int) –The version of the handler.
-
token(str) –The routing token of the handler.
-
fingerprint(str) –The hash of the handler's wire signature, empty without wire arguments.
-
frames(Sequence[Frame]) –The encoded wire arguments.
-
func_name(str) –The handler's qualified name, for messages.
-
owner(type[View] | None) –The view class the handler is defined on.
Frame
¶
HandlerBinder
¶
HandlerBinder(
*,
handler_id: str,
version: int,
token: str,
signature: HandlerSignature,
func_name: str,
owner: type[View] | None,
)
A handler accessed on a view instance, as self.vote.
Put it on a component bare, or with wire arguments through risa.bind. Calling it
raises HandlerNotCallableError, since only risa dispatches handlers.
bind
¶
Resolve this handler and its wire arguments into a Binding.
risa.bind(self.vote, 2) ends up here when the component is built.
Parameters:
-
*args(object, default:()) –The wire arguments, in the order of the handler's wire parameters.
-
**kwargs(object, default:{}) –Wire arguments by parameter name. An argument may be left out only if its parameter has a default and every later one is left out too; this holds for positional arguments as well.
Returns:
-
Binding–The handler's identity and its encoded arguments.
Raises:
-
ArgBindError–If an argument names no wire parameter, is given twice, is missing, or holds a value its parameter cannot carry.
resolve
¶
resolve(handler: Handlerish) -> Binding
Return the Binding that handler routes to.
Parameters:
-
handler(Handlerish) –A handler accessed on a view instance, as
self.vote, bare or throughrisa.bind. ABindingis accepted and returned as it is.
Returns:
-
Binding–The handler's identity and its encoded arguments.
Raises:
-
NotAHandlerError–If
handleris not a handler accessed on a view instance, bare or bound. -
ArgBindError–If its wire arguments do not fit the handler.