简体   繁体   中英

Obtaining initial state of target object in object:modified event in fabric.js

I have a drawing application that uses fabric.js and I have implemented an undo/redo function based on the fabric-history repository on github. However, because this approach saves entire canvas states in a stack, the browser quickly becomes non-responsive as it deals with all this data. I would like an undo/redo method that only saves the object that is changed in an interaction with an object on the canvas and not the whole canvas. Using the object:modified event, I see I can get the target object of the event after it is modified, but I also need the object target state before the modification was made to restore it in an undo. Any suggestions on how to obtain this state of an object would be appreciated.

I think you can use the saveState method for it. After calling this method object gets _stateProperty object that contains current values of left, top, and other properties. You can read more about saveState method in doc

I've made a simple example to demonstrate this approach here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM