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.