duck.html.components.core.utils¶
Helper functions for the component system.
Module Contents¶
Functions¶
Executes JavaScript on the client and optionally waits for a result. |
|
Executes JavaScript on the client and retrieves the value of a specific variable. |
|
Returns the current/latest websocket view for sending data and do magical staff. |
API¶
- async duck.html.components.core.utils.execute_js(code: str, script_type: str = 'text/javascript', timeout: Union[int, float] = None, wait_for_result: bool = True) Optional[Any]¶
Executes JavaScript on the client and optionally waits for a result.
- Parameters:
code – JavaScript code to execute.
script_type – MIME type of the script. Defaults to “text/javascript”.
timeout – Max time (in seconds) to wait for result.
wait_for_result – Whether to wait for a return value. Defaults to True.
- Returns:
Result from the client if wait_for_result is True, otherwise None.
- Return type:
Optional[Any]
- Raises:
ExecutionError – If execution is cancelled (e.g., WebSocket disconnected).
ExecutionTimedOut – If no result is received within timeout.
- async duck.html.components.core.utils.get_js_result(code: str, variable: str, script_type: str = 'text/javascript', timeout: Union[int, float, None] = None) Any¶
Executes JavaScript on the client and retrieves the value of a specific variable.
- Parameters:
code – JavaScript code to execute.
variable – Name of the variable to retrieve.
script_type – MIME type of the script. Defaults to “text/javascript”.
timeout – Max time (in seconds) to wait for result.
- Returns:
Value of the specified variable from the client.
- Return type:
Any
- Raises:
ExecutionError – If execution is cancelled (e.g., WebSocket disconnected).
ExecutionTimedOut – If no result is received within timeout.
- duck.html.components.core.utils.get_websocket_view() duck.html.core.system.LivelyComponentSystem¶
Returns the current/latest websocket view for sending data and do magical staff.