Skip to content

Commit

Permalink
Merge pull request #2247 from Avaiga/refactor/expand-set-entityownner…
Browse files Browse the repository at this point in the history
…-of-Properties

Refactor - Split the `_set_entity_owner()` on the `_Properties` to make it overridable
  • Loading branch information
trgiangdo authored Nov 14, 2024
2 parents 66f78c5 + 2bd467f commit eaa65b6
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions taipy/core/_entity/_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,14 @@ def __setitem__(self, key, value):
super(_Properties, self).__setitem__(key, value)

if hasattr(self, "_entity_owner"):
from ... import core as tp

event = _make_event(
self._entity_owner,
EventOperation.UPDATE,
attribute_name=self.__PROPERTIES_ATTRIBUTE_NAME,
attribute_value=value,
)
if not self._entity_owner._is_in_context:
tp.set(self._entity_owner)
self._set_entity_owner(self._entity_owner)
Notifier.publish(event)
else:
if key in self._pending_deletions:
Expand All @@ -53,18 +51,21 @@ def __delitem__(self, key):
super(_Properties, self).__delitem__(key)

if hasattr(self, "_entity_owner"):
from ... import core as tp

event = _make_event(
self._entity_owner,
EventOperation.UPDATE,
attribute_name=self.__PROPERTIES_ATTRIBUTE_NAME,
attribute_value=None,
)
if not self._entity_owner._is_in_context:
tp.set(self._entity_owner)
self._set_entity_owner(self._entity_owner)
Notifier.publish(event)
else:
self._pending_changes.pop(key, None)
self._pending_deletions.add(key)
self._entity_owner._in_context_attributes_changed_collector.append(event)

def _set_entity_owner(self, entity_owner):
from ... import core as tp

tp.set(entity_owner)

0 comments on commit eaa65b6

Please sign in to comment.