Is fetchData supposed to cause all listeners to receive data?

1141
4
03-08-2017 12:10 PM
JoeJoyce
New Contributor II

I have a widget A that publishes data and two more widgets B and C. When B calls fetchData for widget A the onReceiveData events fire for both B and C. Is that supposed to happen? I would expect only B's onReceiveData event to fire since it is the one who called fetchData.

0 Kudos
4 Replies
RobertScheitlin__GISP
MVP Emeritus

Joe,


  If you just do widget.fetchData(); the you get that result. But if you provide a widget ID in the fetchData(someWidgetId); then you can limit it.

0 Kudos
JoeJoyce
New Contributor II

Hmm still happens. Does it matter that C had called fetchData(someWidgetId) in the past before B calls fetchData(someWidgetId)? It seems C is now subscribed to receive data whenever a fetch is requested for A.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Joe,

  In the BaseWidget.js file there is this:

//listenWidgetIds: String[]
// app use this property to filter data message, if not set, all message will be received.
// this property can be set in config.json
this.listenWidgetIds = [];

0 Kudos
JoeJoyce
New Contributor II

I don't think that will work for me. I would have to update listenWidgetIds property before every fetch to make sure only the caller is receiving the data. I want all my widgets to be able to get data from widget A but I only want a widget to receive the data if it is the source of the fetch call.

I'm just going to use the WidgetManager to get a reference to my A widget and then directly access properties that I set on it.

var widgets = this.appConfig.getConfigElementsByName('MyWidget');
var widgetId = widgets[0].id;
var myWidget = this.widgetManager.getWidgetById(widgetId);
// Access data of widget directly
var data = myWidget.someProperty;
// use data...‍‍‍‍‍‍‍