don't send event when value doesn't change

This commit is contained in:
Jakob Ketterl 2020-03-25 17:59:00 +01:00
parent 0e19a40968
commit 14382e012f
2 changed files with 23 additions and 5 deletions

View File

@ -182,12 +182,12 @@ class PropertyStack(PropertyManager):
def replaceLayer(self, priority: int, pm: PropertyManager):
layers = [x for x in self.layers if x["priority"] == priority]
changes = {}
if layers:
changes = self._removeLayer(layers[0])
for k, v in self._addLayer(priority, pm).items():
changes[k] = v
originalState = self.__dict__()
changes = self._removeLayer(layers[0]) if layers else {}
changes = {**changes, **self._addLayer(priority, pm)}
changes = {k: v for k, v in changes.items() if k not in originalState or originalState[k] != v}
self._fireChanges(changes)

View File

@ -167,3 +167,21 @@ class PropertyStackTest(TestCase):
layer["testkey"] = "after"
mock.method.assert_not_called()
def testReplaceLayerNoEventWhenValueUnchanged(self):
fixed = PropertyLayer()
fixed["testkey"] = "fixed value"
first_layer = PropertyLayer()
first_layer["testkey"] = "same value"
second_layer = PropertyLayer()
second_layer["testkey"] = "same value"
stack = PropertyStack()
stack.addLayer(1, fixed)
stack.addLayer(0, first_layer)
mock = Mock()
stack.wire(mock.method)
mock.method.assert_not_called()
stack.replaceLayer(0, second_layer)
mock.method.assert_not_called()