In FabricJS I can trap the object:modified event. I want to use this to update an underlying object model of the canvas. IE, we have our own definition of a diagram.
I can't see how the event object relates the actual change made to the canvas. Has anyone seen any documentation or sample for this?
Thanks
答案 0 :(得分:1)
与最后一个对象状态相比,事件没有差异。 您可以自己实现。
object:modified
使用一个将对象作为唯一arg的回调。
让我们称之为选项。 options.target是触发事件的对象。
每个fabric.Object都混合了必须手动触发的状态检查方法。
所以你可以rect.saveState('propsINeedToCheck')
和rect.hasStateChanged('propsINeedToCheck')
propsINeedToCheck
是原型中的数组:
fabric.Object.prototype.propsINeedToCheck = ['top', 'left', 'angle']
您必须创建。
现在没有什么可以告诉你实际改变了什么,只是改变了一些东西。此方法的有效性取决于您要检查的内容。
另一种方法是每次转储一个对象状态,并与进行深度比较的函数进行比较。