projectstorm / react-diagrams

a super simple, no-nonsense diagramming library written in react that just works
https://projectstorm.cloud/react-diagrams
MIT License
8.61k stars 1.17k forks source link

Make new custom listener for customNodeModel #712

Closed agarwalishan closed 4 years ago

agarwalishan commented 4 years ago

Hey, can someone please tell me how can I make a custom event listener on my customNodeModel? I want this listener to fire when I right click on node.

renato-bohler commented 4 years ago

In your CustomNodeWidget, you have access to the engine. If you haven't, change your CustomNodeFactory to pass this.engine as a prop to your widget.

Now, you can call this.props.engine.fireEvent(event, 'myCustomListenerName'), where event is any object you want.

To listen to this event:

engine.registerListener({
  myCustomListenerName: event => console.log('TODO: handle event', event),
})
agarwalishan commented 4 years ago

@renato-bohler Thanks man you saved my life it worked perfectly.