From 822fcb69a4ad424219b9f9a58e79d8f7a64150b6 Mon Sep 17 00:00:00 2001 From: Asturur Date: Sun, 23 Apr 2017 13:19:34 +0200 Subject: [PATCH 1/2] fixed cache for first draw --- src/shapes/object.class.js | 17 +++-------------- src/shapes/path.class.js | 4 ---- src/shapes/path_group.class.js | 5 ----- src/util/misc.js | 2 +- test/unit/object.js | 10 ---------- test/unit/path.js | 2 +- test/unit/path_group.js | 2 +- 7 files changed, 6 insertions(+), 36 deletions(-) diff --git a/src/shapes/object.class.js b/src/shapes/object.class.js index a47cb0f35af..06b218094ce 100644 --- a/src/shapes/object.class.js +++ b/src/shapes/object.class.js @@ -792,9 +792,9 @@ * When set to `true`, object's cache will be rerendered next render call. * since 1.7.0 * @type Boolean - * @default false + * @default true */ - dirty: false, + dirty: true, /** * When set to `true`, force the object to have its own cache, even if it is inside a group @@ -839,7 +839,6 @@ } if (this.objectCaching) { this._createCacheCanvas(); - this.setupState({ propertySet: 'cacheProperties' }); } }, @@ -848,6 +847,7 @@ * @private */ _createCacheCanvas: function() { + this._cacheProperties = {}; this._cacheCanvas = fabric.document.createElement('canvas'); this._cacheContext = this._cacheCanvas.getContext('2d'); this._updateCacheCanvas(); @@ -1104,17 +1104,6 @@ // implemented by sub-classes, as needed. }, - /** - * Sets sourcePath of an object - * @param {String} value Value to set sourcePath to - * @return {fabric.Object} thisArg - * @chainable - */ - setSourcePath: function(value) { - this.sourcePath = value; - return this; - }, - /** * Retrieves viewportTransform from Object's canvas if possible * @method getViewportTransform diff --git a/src/shapes/path.class.js b/src/shapes/path.class.js index 28fa43da527..f102dfb78f5 100644 --- a/src/shapes/path.class.js +++ b/src/shapes/path.class.js @@ -105,12 +105,8 @@ this._setPositionDimensions(options); - if (options.sourcePath) { - this.setSourcePath(options.sourcePath); - } if (this.objectCaching) { this._createCacheCanvas(); - this.setupState({ propertySet: 'cacheProperties' }); } }, diff --git a/src/shapes/path_group.class.js b/src/shapes/path_group.class.js index 8cf6b5d5fb0..ef5b355e520 100644 --- a/src/shapes/path_group.class.js +++ b/src/shapes/path_group.class.js @@ -54,12 +54,8 @@ } this.setOptions(options); this.setCoords(); - if (options.sourcePath) { - this.setSourcePath(options.sourcePath); - } if (this.objectCaching) { this._createCacheCanvas(); - this.setupState({ propertySet: 'cacheProperties' }); } }, @@ -258,7 +254,6 @@ fabric.PathGroup.fromObject = function(object, callback) { var originalPaths = object.paths; delete object.paths; - // remove this pattern from 2.0 accepts only object if (typeof originalPaths === 'string') { fabric.loadSVGFromURL(originalPaths, function (elements) { var pathUrl = originalPaths; diff --git a/src/util/misc.js b/src/util/misc.js index 963e45d10e0..f2a79764f72 100644 --- a/src/util/misc.js +++ b/src/util/misc.js @@ -392,7 +392,7 @@ object = new fabric.PathGroup(elements, options); if (typeof path !== 'undefined') { - object.setSourcePath(path); + object.sourcePath = path; } return object; }, diff --git a/test/unit/object.js b/test/unit/object.js index 637f3b5fe8b..4d7f6724f9d 100644 --- a/test/unit/object.js +++ b/test/unit/object.js @@ -149,16 +149,6 @@ equal(0.123, cObj.getOpacity()); }); - test('setSourcePath', function() { - var cObj = new fabric.Object(); - var SRC_PATH = 'http://example.com/'; - - ok(typeof cObj.setSourcePath == 'function'); - - cObj.setSourcePath(SRC_PATH); - equal(cObj.get('sourcePath'), SRC_PATH); - }); - test('stateProperties', function() { var cObj = new fabric.Object(); ok(cObj.stateProperties); diff --git a/test/unit/path.js b/test/unit/path.js index 4b463706d9a..63cac0ac9e3 100644 --- a/test/unit/path.js +++ b/test/unit/path.js @@ -140,7 +140,7 @@ deepEqual(path.toDatalessObject(), REFERENCE_PATH_OBJECT); var src = 'http://example.com/'; - path.setSourcePath(src); + path.sourcePath = src; deepEqual(path.toDatalessObject(), fabric.util.object.extend(fabric.util.object.clone(REFERENCE_PATH_OBJECT), { path: src })); diff --git a/test/unit/path_group.js b/test/unit/path_group.js index 02a673bac82..356620ee25a 100644 --- a/test/unit/path_group.js +++ b/test/unit/path_group.js @@ -166,7 +166,7 @@ getPathGroupObject(function(pathGroup) { ok(typeof pathGroup.toDatalessObject == 'function'); - pathGroup.setSourcePath('http://example.com/'); + pathGroup.sourcePath = 'http://example.com/'; var expectedObject = fabric.util.object.extend(fabric.util.object.clone(REFERENCE_PATH_GROUP_OBJECT), { 'paths': 'http://example.com/', 'sourcePath': 'http://example.com/' From ede2126517a289e13688074a72e2df9caa9a7d69 Mon Sep 17 00:00:00 2001 From: Asturur Date: Sun, 23 Apr 2017 13:38:17 +0200 Subject: [PATCH 2/2] fixed tests --- src/mixins/stateful.mixin.js | 3 +++ test/unit/object.js | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/mixins/stateful.mixin.js b/src/mixins/stateful.mixin.js index 083de13bb1d..4af2d405b0b 100644 --- a/src/mixins/stateful.mixin.js +++ b/src/mixins/stateful.mixin.js @@ -57,6 +57,9 @@ hasStateChanged: function(propertySet) { propertySet = propertySet || originalSet; propertySet = '_' + propertySet; + if (!Object.keys(this[propertySet]).length) { + return true; + } return !_isEqual(this[propertySet], this, true); }, diff --git a/test/unit/object.js b/test/unit/object.js index 4d7f6724f9d..d8903606bf5 100644 --- a/test/unit/object.js +++ b/test/unit/object.js @@ -1241,6 +1241,7 @@ test('isCacheDirty statefullCache disabled', function() { var object = new fabric.Object({ scaleX: 3, scaleY: 2}); + equal(object.dirty, true, 'object is dirty after creation'); object.cacheProperties = ['propA', 'propB']; object.dirty = false; object.statefullCache = false; @@ -1258,6 +1259,8 @@ object.propA = 'A'; object.setupState({ propertySet: 'cacheProperties' }); object._createCacheCanvas(); + equal(object.isCacheDirty(), true, 'object is dirty if canvas has been just created'); + object.setupState({ propertySet: 'cacheProperties' }); equal(object.isCacheDirty(), false, 'object is not dirty'); object.propA = 'B'; equal(object.isCacheDirty(), true, 'object is dirty because change in propA is detected by statefullCache');