self._collected = tuple()
-class IntoUpdateValueMixin(AutoAttrMixin):
- 'Provides .into_update_value(), exportable for module-external consumers.'
+class IntoEndnodeUpdatesMixin(AutoAttrMixin):
+ 'Provides .into_endnode_updates exportable for module-external consumers.'
- def into_update_value(self) -> Any:
- 'Return non-updating copy of self.'
- if isinstance(self, _Dict):
- return None
+ def into_endnode_updates(self, path: tuple[str, ...]
+ ) -> list[tuple[tuple[str, ...], Any]]:
+ 'Return path-value pairs for any update-worthy sub-elements.'
if isinstance(self, _CompletableStringsCollection):
- return self._completed
+ return ([(path, self._completed)] if self._completed is not None
+ else [])
if isinstance(self, _CompletableTopic):
- return Topic(*self._completed)
- for cls in [cls for cls in self.__class__.__mro__
- if AutoAttrMixin not in cls.__mro__]:
- obj = cls()
- break
- for key in self._deep_annotations():
- attr_val = getattr(self, key)
- setattr(obj, key,
- attr_val if not isinstance(attr_val, _UpdatingMixin)
- else attr_val.static_copy)
- return obj
-
-
-class _UpdatingMixin(IntoUpdateValueMixin):
+ return [(path, Topic(*self._completed))]
+ updates = []
+ for key, val in (self._dict.items() if isinstance(self, Dict)
+ else ((k, getattr(self, k))
+ for k in self._deep_annotations())):
+ p = path + (key,)
+ updates += (val.into_endnode_updates(p)
+ if isinstance(val, IntoEndnodeUpdatesMixin)
+ else [(p, val)])
+ return updates
+
+
+class _UpdatingMixin(IntoEndnodeUpdatesMixin):
_on_update: Callable
def __init__(self, on_update: Callable, **kwargs) -> None:
CMD_SHORTCUTS)
from ircplom.client import (
AutoAttrMixin, Client, ClientQueueMixin, Dict, DictItem,
- IntoUpdateValueMixin, IrcConnSetup, LogScope, NewClientEvent,
+ IntoEndnodeUpdatesMixin, IrcConnSetup, LogScope, NewClientEvent,
NickUserHost, ServerCapability, SharedClientDbFields, Topic)
CMD_SHORTCUTS['disconnect'] = 'window.disconnect'
value = ((parent[last_step] if last_step in parent.keys()
else None) if isinstance(parent, Dict)
else getattr(parent, last_step))
- if isinstance(value, IntoUpdateValueMixin):
- value = value.into_update_value()
- self._client_tui_trigger('update_db', update=_Update(path, value))
+ for path, value in (value.into_endnode_updates(path)
+ if isinstance(value, IntoEndnodeUpdatesMixin)
+ else [(path, value)]):
+ self._client_tui_trigger('update_db', update=_Update(path, value))