changed events
This commit is contained in:
@@ -35,13 +35,14 @@ class HookedMapping(HookedContainer[T], MutableMapping[T, MutableNesting[T]]):
|
||||
def insert(self, key: T, value: MutableNesting[T]) -> None:
|
||||
self._data[key] = value
|
||||
if self.hook:
|
||||
self.hook(e.AddItemEvent(index=key, item=value, path=self.new_path(key)))
|
||||
self.hook(e.AddItemEvent(value, path=self.new_path(key)))
|
||||
|
||||
# HookedContainer methods
|
||||
|
||||
def __getitem__(self, key: T) -> MutableNesting[T]:
|
||||
if key not in self._data:
|
||||
self.insert(key, {})
|
||||
return HookedMapping(self._data[key], hook=self.hook, path=self.new_path(key))
|
||||
value = self._data[key]
|
||||
match value:
|
||||
case HookedMapping(_data=seq):
|
||||
@@ -54,13 +55,13 @@ class HookedMapping(HookedContainer[T], MutableMapping[T, MutableNesting[T]]):
|
||||
def __setitem__(self, key: T, value: MutableNesting[T]) -> None:
|
||||
if key not in self._data:
|
||||
self.insert(key, value)
|
||||
return
|
||||
self._data[key] = value
|
||||
if self.hook:
|
||||
self.hook(e.SetItemEvent(index=key, item=value, path=self.new_path(key)))
|
||||
else:
|
||||
self._data[key] = value
|
||||
if self.hook:
|
||||
self.hook(e.SetItemEvent(value, path=self.new_path(key)))
|
||||
|
||||
def __delitem__(self, key: T) -> None:
|
||||
item = self._data[key]
|
||||
del self._data[key]
|
||||
if self.hook:
|
||||
self.hook(e.RemoveItemEvent(index=key, item=item, path=self.new_path(key)))
|
||||
self.hook(e.RemoveItemEvent(item, path=self.new_path(key)))
|
||||
|
||||
Reference in New Issue
Block a user