I’m using <ReactDiagram>
and am trying to use its onModelChange
event to watch for changes in my node’s position. I feel like I have it wired up correctly, since the event gets called when I change some text, but not when I change the position (via the dragging tool).
Here’s my node template and the basic onModelChange callback:
export const myNodeTemplate: go.Node = $(
go.Node,
'Auto',
{
isLayoutPositioned: false,
},
new go.Binding('position', 'position', (data, obj) => {
return new go.Point(data.x, data.y)
}).makeTwoWay((val, data, model) => {
console.log('position changed')
return {
...data.position,
x: val.x,
y: val.y,
}
}),
$(go.Shape, 'Rectangle', { fill: 'cyan', width: 150, height: 150 }),
$(
go.TextBlock,
{ editable: true },
new go.Binding('text', 'label').makeTwoWay((val, data, model) => {
console.log('text changed')
return val
})
)
)
const onModelChange = (e: go.IncrementalData) => {
console.log('model changed')
}
// jsx for diagram
<ReactDiagram
ref={diagramRef}
divClassName='diagram-editor'
initDiagram={initDiagram}
nodeDataArray={diagramNodes}
linkDataArray={diagramLinks}
onModelChange={onModelChange}
skipsDiagramUpdate={false}
/>
I see that the makeTwoWay functions are being called for both position
and text
. I also see that onModelChange
is being called after changes to the text, but not after changes to the position.
Why is onModelChange not being called after changes to my position here? How can I get my dragged node position changes to be passed on to onModelChange?