don't send event when value doesn't change
This commit is contained in:
parent
0e19a40968
commit
14382e012f
@ -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)
|
||||
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user