From fa9fb8a0f107337e4574c7f71bd3a438cdebeae8 Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Mon, 4 Jun 2018 11:13:39 +0200 Subject: [PATCH] fix group becoming cachrable (#5021) * fix group becoming cacheable --- src/shapes/object.class.js | 3 +++ test/unit/object.js | 13 +++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/shapes/object.class.js b/src/shapes/object.class.js index 1e069bcd160..5052302e0b2 100644 --- a/src/shapes/object.class.js +++ b/src/shapes/object.class.js @@ -617,6 +617,8 @@ this._cacheCanvas = fabric.document.createElement('canvas'); this._cacheContext = this._cacheCanvas.getContext('2d'); this._updateCacheCanvas(); + // if canvas gets created, is empty, so dirty. + this.dirty = true; }, /** @@ -1002,6 +1004,7 @@ if (this.shouldCache()) { if (!this._cacheCanvas) { this._createCacheCanvas(); + } if (this.isCacheDirty()) { this.statefullCache && this.saveState({ propertySet: 'cacheProperties' }); diff --git a/test/unit/object.js b/test/unit/object.js index 8caa11924f2..9df3028feaa 100644 --- a/test/unit/object.js +++ b/test/unit/object.js @@ -1019,13 +1019,21 @@ assert.equal(object.dirty, true, 'after setting a property from cache, dirty flag is true'); }); + QUnit.test('_createCacheCanvas sets object as dirty', function(assert) { + var object = new fabric.Object({ scaleX: 3, scaleY: 2, width: 1, height: 2}); + assert.equal(object.dirty, true, 'object is dirty after creation'); + object.dirty = false; + assert.equal(object.dirty, false, 'object is not dirty after specifying it'); + object._createCacheCanvas(); + assert.equal(object.dirty, true, 'object is dirty again if cache gets created'); + }); + QUnit.test('isCacheDirty statefullCache disabled', function(assert) { var object = new fabric.Object({ scaleX: 3, scaleY: 2, width: 1, height: 2}); assert.equal(object.dirty, true, 'object is dirty after creation'); object.cacheProperties = ['propA', 'propB']; object.dirty = false; object.statefullCache = false; - object._createCacheCanvas(); assert.equal(object.isCacheDirty(), false, 'object is not dirty if dirty flag is false'); object.dirty = true; assert.equal(object.isCacheDirty(), true, 'object is dirty if dirty flag is true'); @@ -1038,9 +1046,6 @@ object.statefullCache = true; object.propA = 'A'; object.setupState({ propertySet: 'cacheProperties' }); - object._createCacheCanvas(); - assert.equal(object.isCacheDirty(), true, 'object is dirty if canvas has been just created'); - object.setupState({ propertySet: 'cacheProperties' }); assert.equal(object.isCacheDirty(), false, 'object is not dirty'); object.propA = 'B'; assert.equal(object.isCacheDirty(), true, 'object is dirty because change in propA is detected by statefullCache');