diff --git a/django_unicorn/views/action_parsers/sync_input.py b/django_unicorn/views/action_parsers/sync_input.py index ab52d929..a5d7e9c6 100644 --- a/django_unicorn/views/action_parsers/sync_input.py +++ b/django_unicorn/views/action_parsers/sync_input.py @@ -8,4 +8,17 @@ def handle(component_request: ComponentRequest, component: UnicornView, payload: Dict): property_name = payload.get("name") property_value = payload.get("value") - set_property_value(component, property_name, property_value, component_request.data) + + call_updated_method = True + + # If there is more than one action then only call the updated methods for the last action in the queue + if len(component_request.action_queue) > 1: + call_updated_method = False + last_action = component_request.action_queue[-1:][0] + + if last_action.payload.get("name") == property_name and last_action.payload.get("value") == property_value: + call_updated_method = True + + set_property_value( + component, property_name, property_value, component_request.data, call_updated_method=call_updated_method + ) diff --git a/django_unicorn/views/action_parsers/utils.py b/django_unicorn/views/action_parsers/utils.py index 82319447..5c5db8ae 100644 --- a/django_unicorn/views/action_parsers/utils.py +++ b/django_unicorn/views/action_parsers/utils.py @@ -12,6 +12,7 @@ def set_property_value( property_name: str, property_value: Any, data: Optional[Dict] = None, + call_updated_method=True, ) -> None: """ Sets properties on the component. @@ -59,8 +60,8 @@ class TestView(UnicornView): component_or_field._set_property( property_name_part, property_value, - call_updating_method=False, - call_updated_method=True, + call_updating_method=False, # the updating method has already been called above + call_updated_method=call_updated_method, ) else: # Handle calling the updating/updated method for nested properties @@ -101,7 +102,7 @@ class TestView(UnicornView): if not is_relation_field: setattr(component_or_field, property_name_part, property_value) - if hasattr(component, updated_function_name): + if hasattr(component, updated_function_name) and call_updated_method: getattr(component, updated_function_name)(property_value) data_or_dict[property_name_part] = property_value @@ -128,4 +129,5 @@ class TestView(UnicornView): else: break - component.updated(property_name, property_value) + if call_updated_method: + component.updated(property_name, property_value)