From 4f77bde2a9fbcb7c564426ebb3cb4e3eeb6a5417 Mon Sep 17 00:00:00 2001 From: Asturur Date: Thu, 26 Oct 2017 09:52:24 +0200 Subject: [PATCH 1/2] first change --- src/shapes/object.class.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/shapes/object.class.js b/src/shapes/object.class.js index af0782cf8a2..cc850472f87 100644 --- a/src/shapes/object.class.js +++ b/src/shapes/object.class.js @@ -884,7 +884,8 @@ * @return {fabric.Object} thisArg */ _set: function(key, value) { - var shouldConstrainValue = (key === 'scaleX' || key === 'scaleY'); + var shouldConstrainValue = (key === 'scaleX' || key === 'scaleY'), + isChanged = this[key] !== value; if (shouldConstrainValue) { value = this._constrainScale(value); @@ -906,14 +907,14 @@ this[key] = value; - if (this.cacheProperties.indexOf(key) > -1) { + if (isChanged && this.cacheProperties.indexOf(key) > -1) { if (this.group) { this.group.set('dirty', true); } this.dirty = true; } - if (this.group && this.stateProperties.indexOf(key) > -1 && this.group.isOnACache()) { + if (isChanged && this.group && this.stateProperties.indexOf(key) > -1 && this.group.isOnACache()) { this.group.set('dirty', true); } From 105a2d8aa1e215dead826f0fff4c55b2238f8bba Mon Sep 17 00:00:00 2001 From: Asturur Date: Thu, 26 Oct 2017 10:19:41 +0200 Subject: [PATCH 2/2] added a small test --- test/unit/object.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/unit/object.js b/test/unit/object.js index 22378a776de..5a5866ef29f 100644 --- a/test/unit/object.js +++ b/test/unit/object.js @@ -1225,4 +1225,22 @@ object.shadow.offsetX = 1; assert.equal(object.willDrawShadow(), true, 'object will drawShadow'); }); + + QUnit.test('_set change a property', function(assert) { + var object = new fabric.Object({ fill: 'blue' }); + object._set('fill', 'red'); + assert.equal(object.fill, 'red', 'property changed'); + }); + QUnit.test('_set can rise the dirty flag', function(assert) { + var object = new fabric.Object({ fill: 'blue' }); + object.dirty = false; + object._set('fill', 'red'); + assert.equal(object.dirty, true, 'dirty is rised'); + }); + QUnit.test('_set rise dirty flag only if value changed', function(assert) { + var object = new fabric.Object({ fill: 'blue' }); + object.dirty = false; + object._set('fill', 'blue'); + assert.equal(object.dirty, false, 'dirty is not rised'); + }); })();