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

Minimize delay between clear and re render. #4007

Merged
merged 2 commits into from
Jun 14, 2017
Merged
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
45 changes: 20 additions & 25 deletions src/mixins/canvas_serialization.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,19 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
? JSON.parse(json)
: fabric.util.object.clone(json);

this.clear();
var _this = this,
renderOnAddRemove = this.renderOnAddRemove;
this.renderOnAddRemove = false;

var _this = this;
this._enlivenObjects(serialized.objects, function () {
this._enlivenObjects(serialized.objects, function (enlivenedObjects) {
_this.clear();
_this._setBgOverlay(serialized, function () {
enlivenedObjects.forEach(function(obj, index) {
// we splice the array just in case some custom classes restored from JSON
// will add more object to canvas at canvas init.
_this.insertAt(obj, index);
});
_this.renderOnAddRemove = renderOnAddRemove;
// remove parts i cannot set as options
delete serialized.objects;
delete serialized.backgroundImage;
Expand All @@ -64,6 +72,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
// create the Object instance. Here the Canvas is
// already an instance and we are just loading things over it
_this._setOptions(serialized);
_this.renderAll();
callback && callback();
});
}, reviver);
Expand All @@ -76,13 +85,12 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
* @param {Function} callback Invoked after all background and overlay images/patterns loaded
*/
_setBgOverlay: function(serialized, callback) {
var _this = this,
loaded = {
backgroundColor: false,
overlayColor: false,
backgroundImage: false,
overlayImage: false
};
var loaded = {
backgroundColor: false,
overlayColor: false,
backgroundImage: false,
overlayImage: false
};

if (!serialized.backgroundImage && !serialized.overlayImage && !serialized.background && !serialized.overlay) {
callback && callback();
Expand All @@ -91,7 +99,6 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati

var cbIfLoaded = function () {
if (loaded.backgroundImage && loaded.overlayImage && loaded.backgroundColor && loaded.overlayColor) {
_this.renderAll();
callback && callback();
}
};
Expand Down Expand Up @@ -140,25 +147,13 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
* @param {Function} [reviver]
*/
_enlivenObjects: function (objects, callback, reviver) {
var _this = this;

if (!objects || objects.length === 0) {
callback && callback();
callback && callback([]);
return;
}

var renderOnAddRemove = this.renderOnAddRemove;
this.renderOnAddRemove = false;

fabric.util.enlivenObjects(objects, function(enlivenedObjects) {
enlivenedObjects.forEach(function(obj, index) {
// we splice the array just in case some custom classes restored from JSON
// will add more object to canvas at canvas init.
_this.insertAt(obj, index);
});

_this.renderOnAddRemove = renderOnAddRemove;
callback && callback();
callback && callback(enlivenedObjects);
}, null, reviver);
},

Expand Down