From d51d266642a747281db3fd61638221a719e7451c Mon Sep 17 00:00:00 2001 From: miruka Date: Sat, 5 Sep 2020 17:33:08 -0400 Subject: [PATCH] Add ModelItem.notify_change() for list/dicts --- src/backend/models/model_item.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/backend/models/model_item.py b/src/backend/models/model_item.py index fb57c5ed..81430d0f 100644 --- a/src/backend/models/model_item.py +++ b/src/backend/models/model_item.py @@ -101,3 +101,18 @@ class ModelItem: fields[name] = self.serialize_field(name) self._notify_parent_model(fields) + + + def notify_change(self, *fields: str) -> None: + """Manually notify the parent model that a field changed. + + The model cannot automatically detect changes inside object + fields, such as list or dicts having their data modified. + + Use this method to manually notify it that such fields were changed, + and avoid having to reassign the field itself. + """ + + self._notify_parent_model({ + name: self.serialize_field(name) for name in fields + })