duck.html.components.core.force_update¶
Module containing a class to force update a component, i.e. force generate a patch on event binding. Very useful for components updated using JS.
Usage Example:
# views.py
from duck.html.components.page import Page
from duck.html.components.button import Button
def myview(request):
def on_button_click(btn, *_):
# The following will return update the Button text/innerHTML regardless. Even if it was modified through Javascript.
return ForceUpdate(btn, ["text"]) # Or return a list of ForceUpdates
# Do some page logic
page = Page(request)
btn = Button(text="Some text")
# Add button to page
page.add_to_body(btn)
# Bind btn click, but disable any component update by default.
btn.bind("click", on_button_click, update_self=False, update_targets=[])
# Return page or ComponentResponse
return page
Module Contents¶
Classes¶
Class for applying force updates on HTML components. |
Functions¶
Check if force updates in list are of correct type. |
|
Track ForceUpdate objects that actually execute through |
|
Sync current updates to the client immediately. |
Data¶
API¶
- class duck.html.components.core.force_update.ForceUpdate(component: duck.html.components.Component, updates: List[str] = None)[source]¶
Class for applying force updates on HTML components.
Notes:
These updates are only limited to components in the DOM/Component tree.
You cannot add/remove a component from tree with this approach, rather use the default approach.
Initialization
Initialize force update on a component on event.
- Parameters:
component – The HTML component to target.
updates – List of updates to regenerated. These updates are limited to ‘props’, ‘text’, ‘inner_html’, ‘style’, ‘all’.
- __slots__¶
None
- duck.html.components.core.force_update._executed_update_now_force_updates¶
‘ContextVar(…)’
- duck.html.components.core.force_update.check_force_updates(updates: List[ForceUpdate])[source]¶
Check if force updates in list are of correct type.
- duck.html.components.core.force_update.track_update_now_force_updates()[source]¶
Track ForceUpdate objects that actually execute through
updated_nowfunction.
- async duck.html.components.core.force_update.update_now(component: duck.html.components.Component, updates: List[str], ws_view, track_update: bool = True)[source]¶
Sync current updates to the client immediately.
- Parameters:
component – Single component to target.
updates – List of updates to target e.g. text, inner_html, props, style, all.
track_update – Whether to track executed updates for
track_force_updatescontext manager.