Created
July 28, 2015 17:02
-
-
Save npfitz/4f83b489409d5551b50a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
onCellChange: function(eventName, cell, change, opt) { | |
opt = opt || {}; | |
// Do not react on changes that happened inside this inspector. This would | |
// cause a re-render of the same inspector triggered by an input change in this inspector. | |
if (opt.inspector == this.cid) return; | |
// Note that special care is taken for all the transformation attribute changes | |
// (`position`, `size` and `angle`). See below for details. | |
switch (eventName) { | |
case 'remove': | |
// Make sure the element inspector gets removed when the cell is removed from the graph. | |
// Otherwise, a zombie cell could possibly be updated. | |
this.remove(); | |
break; | |
case 'change:position': | |
// Make a special case for `position` as this one is performance critical. | |
// There is no need to rerender the whole inspector but only update the position input. | |
this.updateInputPosition(); | |
break; | |
case 'change:size': | |
// Make a special case also for the `size` attribute for the same reasons as for `position`. | |
this.updateInputSize(); | |
break; | |
case 'change:angle': | |
// Make a special case also for the `angle` attribute for the same reasons as for `position`. | |
this.updateInputAngle(); | |
break; | |
case 'change:source': | |
case 'change:target': | |
case 'change:vertices': | |
// Make a special case also for the 'source' and 'target' of a link for the same reasons | |
// as for 'position'. We don't expect source or target to be configurable. | |
// That's why we do nothing here. | |
break; | |
default: | |
// Re-render only on specific attributes changes. These are all events that starts with `'change:'`. | |
// Otherwise, the re-render would be called unnecessarily (consider generic `'change'` event, `'bach:start'`, ...). | |
var changeAttributeEvent = 'change:'; | |
if (eventName.slice(0, changeAttributeEvent.length) === changeAttributeEvent) { | |
this.render(); | |
} | |
break; | |
} | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment