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

ForceUpdate

Class for applying force updates on HTML components.

Functions

check_force_updates

Check if force updates in list are of correct type.

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’.

__repr__()[source]
__slots__

None

__str__()[source]
async generate_patch_and_act(action)[source]

Same implementation as VDOM.diff_and_act but it only generate patches based on parsed updates (i.e. ‘text’/‘inner_html’, ‘props’, ‘style’).

duck.html.components.core.force_update.check_force_updates(updates: List[ForceUpdate])[source]

Check if force updates in list are of correct type.