# How can I prevent Plotly functions from emitting similar events?

**URL:** <https://community.plotly.com/t/how-can-i-prevent-plotly-functions-from-emitting-similar-events/85776>\
**Category:** plotly.js\
**Tags:** question\
**Created:** [July 12, 2024, 6:15pm UTC](https://community.plotly.com/t/how-can-i-prevent-plotly-functions-from-emitting-similar-events/85776 "2024-07-12T18:15:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Saratoga](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/saratoga/32/28634_2.png) [@Saratoga](https://community.plotly.com/u/Saratoga)\
**Post date:** [July 12, 2024, 6:15pm UTC](https://community.plotly.com/t/how-can-i-prevent-plotly-functions-from-emitting-similar-events/85776/1 "2024-07-12T18:15:40Z")

</div>

Is there a way to prevent the homonymous event from being launched when using the relayout, restyle, update functions? Currently, I capture the plotly\_relayout event to make some adjustments when the window is zoomed, dragged or resized, but when I use the relayout function it is also launched. the relayout event executing the code that I also have in the event, what I do to avoid this is use the Plotly.update function since I do not have code in the plotly\_update event, however I recently found a small error with the Plotly.update function which does not happen when using Plotly.relayout. Furthermore, I think it is more efficient to use the relayout function when the only thing you want is to change layout properties, as well as restyle when you only change plot properties. I consider that emitting the event after calling the function It causes performance problems and if you are not careful you can crash the program as easily as doing the following

```auto
layer.on("plotly_relayout", e => { Plotly.relayout(layer, {...}) })
layer.on("plotly_update", e => { Plotly.update(layer, {...}, {...}) })

```

https://codepen.io/saratoga01/embed/preview/ZEdGyXw?default-tabs=js%2Cresult&height=300&host=https%3A%2F%2Fcodepen.io&slug-hash=ZEdGyXw

I could also try to add conditionals inside the event to avoid the execution of the code but I think that is not the case since as the app grows I will have the need to add more and more conditions in the event to prevent it from being executed just for using its function homonymous and maybe I even forgot to add some conditions, I think it would be a good idea in the future to add a property to the configuration to cancel the events something like the following

`emitevent: false`

And so we could decide whether or not we want the event to be launched when using the Plotly functions

As I mentioned, the solution I use at the moment is to use Plotly.update because it did not capture the plotly\_update event, but I don’t know, maybe in the future I will have to do it and as I mentioned I found an error using the update function when making some changes to the shapes which forces me to have to change the updates for relayouts, so well I have a job,

---

<div class="post-metadata">

**Author:** ![Saratoga](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/saratoga/32/28634_2.png) [@Saratoga](https://community.plotly.com/u/Saratoga)\
**Post date:** [July 24, 2024, 5:57pm UTC](https://community.plotly.com/t/how-can-i-prevent-plotly-functions-from-emitting-similar-events/85776/2 "2024-07-24T17:57:11Z")

</div>

In order to use the relayout function and prevent the plotly\_relayout event code from being executed, this is my solution

```auto
Plotly.relayout(layer, { "stop": true , ... })

layer.on("plotly_relayout", e => {
     if(e.stop) return
     ...
     ...
     ...
})

```
