EventBus per panel within a dashboard

Hi, how do I publish and subscribe to events in my custom plugin? This is how I’m currently achieving the desired behavior.

Publish

this.props.context.eventBus.publish(new MyCustomEvent(...));

Subscribe

this.props.eventBus
      .getStream(MyCustomEvent)
      .subscribe(event => { ... /* e.g. console.log("payload") */ })

The issue with this code is that when I have multiple panels on one dashboard, they all get triggered (e.g. all of the console.logs go off) when just a single panel’s event is published. What’s the best way to fix this?

Thanks!

pass panel id in payload: if (pId !== evt.payload.pId) return

panel id is passed in props to your plugin