I'm trying to accomplish undo/redo. I'm using loadFromJSON(...) to re-build the canvas from the canvas states I've stored in an array. Basically, my idea is to destroy the existing canvas and re-construct canvas. Here is my code.
// TODO: How to destroy existing canvas?
canvas = new fabric.Canvas('canvas', {
containerClass : 'myCanvasContainer',
});
canvas.loadFromJSON(history[historyStep]);
This code adds another canvas on top of existing canvas. However, I need a way to destroy the canvas and to build brand new canvas from my JSON data (replacing old canvas with new one).
Please advise whether it's possible or any other options I have.