Recording nodes being moved
Like a few other people I'm trying to store node positions. I've done a hack using the MouseUp, but this affecting the performance of a few other things and I'd really like to try and use events.
I've found lots of posts that suggest:
You can subscribe to actionStartedFiring/actionStillFiring, and it will fire MoveItemsAction where you can access moved items from action.selectionModels
But no code to show how this works
i.e. in this code, all of these events work
this.diagramModel = new DiagramModel()
this.diagramModel.addListener({
linksUpdated: this.onUpdateLinks.bind(this),
offsetUpdated: _.debounce(this.updateOffset.bind(this),500),
zoomUpdated: this.updateZoom.bind(this),
actionStillFiring: (a) => console.log(a),
})
But actionStartedFiring/actionStillFiring are never called, MoveItemsAction is never called.. I just can't find any way of listening for nodes being moved.
Please can someone give me some example code to show how this works?
Hi, thanks for this research and you are almost there!
The thing is that actionStartedFiring/actionStillFiring are widget events, not model, so apropriate usage will be like this
<DiagramWidget
{...props}
actionStartedFiring={this.onDiagramActionStarted}
actionStoppedFiring={this.onDiagramActionStopped}
/>
Ahh right. Cool thanks!
Hmm if I add
actionStartedFiring={this.onDiagramActionStarted.bind(this)}
actionStoppedFiring={this.onDiagramActionStopped.bind(this)}
onDiagramActionStarted(event){
console.log(event)
}
onDiagramActionStopped(event){
console.log(event)
}
I can no longer drag the diagram? Am I supposed to deal with the events myself if I use this?
Hey, that's curious, I will take a look today
Ah ok, I looked into implementation and you need to return true from actionStartedFiring listener.
https://github.com/projectstorm/react-diagrams/blob/fa34f5c98b42eb4b6770a64d9d06373cc153e4c6/src/widgets/DiagramWidget.tsx#L200
I think returning falsy value is basically a way to stop event from firing. And that's what happening in your case
^ as per https://github.com/projectstorm/react-diagrams/issues/267 this listeners is now available on all classes which extend BasePositionModel (NodeModel, PointModel etc..)
thank @JokerNN , it need to return true to works