I am trying to use paperjs to create shapes. I also want to implement undo functionality, so when the shape is created I push it into a undoList
const myCircle = new Path.Ellipse({ point: firstPoint, size: calculateSize(firstPoint, secondPoint) }); this.undoList.push({ name: myCircle.name, id: myCircle.id, type: "shape", object: myCircle }); Then I change the color of this created circle and again push to undoList.
myCircle.strokeColor = "#ffffff; this.undoList.push({ name: myCircle.name, id: myCircle.id, type: "shape", object: myCircle }); In my undo function, I am trying to delete the item using item.remove(). This item is fetched using the id of undoList. After removing, I add the previous element of undoList if it has the same id (so that previous state is restored).
Now although I have changed the color, both the items in the undoList have the same color. So, there is no change visible. I think this is happening because they are both pointing to the same object.
How can I overcome this issue?