Issue with FabricJS with clone after serialization

When I change the flip of an object, everything looks correct on the canvas, but when I serialize the canvas and serialize later, it accepts the wrong flip. Flip change method:

if(object) {
    if(type === 'flip-x'){
        (object.flipX ? object.set({ flipX: false }) : object.set({ flipX: true }));
    }else{
        (object.flipY ? object.set({ flipY: false }) : object.set({ flipY: true }));
    }
}
canvas.renderAll();

After that, I clone the object in two different ways:

//1
var clonedObj = jQuery.extend(true, {}, arr[i]);
//2
savingOptions=['id'];
arr[i].clone(function(clonedObj){
    // getting clonedObj
},savingOptions);

Both works may need improvement at first, but on both, after serialization, the cloned object lost its flipX and flipY, regardless of what I do. The serialization I'm doing is:

var data=JSON.stringify(canvas.toObject(savingOptions));
canvas.loadFromJSON(data,function(){
    canvas.renderAll();
});

I also check object.originalState, and all this is normal.

+4
source share

Source: https://habr.com/ru/post/1628713/


All Articles