How to detect changes on canvas in fabricJS?

Are there any options for detecting changes in fabricJS? I use the following program to save my canvas. Then, when you save it again, I have to determine if there are any changes on the canvas before saving it again. How to do it?

            var printImg  = canvas.toDataURL({
                format: 'png',
                multiplier: multi,
                left: (canvas.width - maskWidth)/2,
                height: maskOriHeight/multi,
                width: maskOriWidth/multi
            });
+4
source share
1 answer

I use the following code to compare objects.

var oldJSON = JSON.stringify(canvas.toDatalessJSON(['id']));
var newJSON = JSON.stringify(canvas.toDatalessJSON(['id']));
if(newJSON === oldJSON) {
    console.log('Equal');
} else {
    console.log('Not Equal');
}
+3
source

All Articles