Jonesie
Jonesie

Reputation: 7285

using fabric.js object:modified event to update underlying model

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

Upvotes: 0

Views: 1288

Answers (1)

AndreaBogazzi
AndreaBogazzi

Reputation: 14731

There are no differences in the event, compared to the last object state. You can implement this by yourself.

object:modified uses a callback that takes an object as unique arg.

let's call it options. options.target is the object that fired the event.

Each fabric.Object has a mixing with the methods for a stateful inspection that must be trigged manually.

so you can do rect.saveState('propsINeedToCheck') and rect.hasStateChanged('propsINeedToCheck')

Where propsINeedToCheck is an array in the prototype:

fabric.Object.prototype.propsINeedToCheck = ['top', 'left', 'angle'] that you have to create.

There is nothing right now that tells you what actually changed, just that something is changed. The effectiveness of this method depends on how many things you want to check.

The alternative is to dump an object state each time and compare with a function that does deep comparing.

Upvotes: 1

Related Questions