Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix group becoming cachrable #5021

Merged
merged 5 commits into from
Jun 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/shapes/object.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},

/**
Expand Down Expand Up @@ -1002,6 +1004,7 @@
if (this.shouldCache()) {
if (!this._cacheCanvas) {
this._createCacheCanvas();

}
if (this.isCacheDirty()) {
this.statefullCache && this.saveState({ propertySet: 'cacheProperties' });
Expand Down
13 changes: 9 additions & 4 deletions test/unit/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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');
Expand Down