changed events

This commit is contained in:
John Lancaster
2026-02-22 18:19:48 -06:00
parent 62204abdd0
commit 07bdbe0b46
4 changed files with 12 additions and 11 deletions

View File

@@ -16,6 +16,7 @@ class HookFunction(Protocol):
class HookedContainer(ABC, Sized, Iterable[T], Container[T]):
_path: MutableSequence[int]
_root: MutableMapping[T] | MutableSequence[T] | None = None
hook: HookFunction
def __repr__(self):
@@ -36,12 +37,12 @@ class HookedContainer(ABC, Sized, Iterable[T], Container[T]):
def __setitem__(self, s, value):
self._data[s] = value
if self.hook:
self.hook(e.SetItemEvent(index=s, item=value, path=self._path))
self.hook(e.SetItemEvent(self.new_path(s), value))
def __delitem__(self, s):
item = self._data.pop(s)
if self.hook:
self.hook(e.RemoveItemEvent(index=s, item=item, path=self._path))
self.hook(e.RemoveItemEvent(self.new_path(s), item))
@abstractmethod
def insert(self, index, value): ...