Select to view content in your preferred language

dojo topic pub/sub

1360
2
Jump to solution
03-30-2017 04:47 AM
wadsonmakari
Occasional Contributor

To support my custom workflow I have made small change jimu.js/LayoutManager.js. The change that I have made is creating an object that I then publish within this file as follows

topic.publish("channel_id","object with attributes i need to pass to widget");

I have a custom widget in my application that I would like to subscribe to the channel specified above when the user launches the widget to use it.

i have tried this in the startup method of my custom widget

topic.subscribe("channel_id",function (e){

alert(JSON.stringify(e));

});

My custom widget does seem to be able to subscribe to the channel published from LayoutManager.js. Is this possible? Is there any other way I can achieve this? Any pointers will be gratefully received.

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Wadson,

   The issue is that the LayoutManager is created and publishes the data before the widget gets created and thus the widget subscribes to the topic after it has occurred. Have the LayoutManager subscribe to a "my widget is started" topic and the widget still subscribe to the "channel_id" in its startup event and publish the "my widget is started" topic and the LayoutManager subscribe to a "my widget is started" topic would publish the "channel_id" topic.

I think a much cleaner and better route would be to use the global window._layoutManager to get to variable that you want to pass to your widget though. In the LayoutManager it sets the window._layoutManager var to an instance of it self and if you create a public var in the LayoutManager and then have your widget just use window._layoutManager.yourPublicVar in its startup function.

View solution in original post

2 Replies
RobertScheitlin__GISP
MVP Emeritus

Wadson,

   The issue is that the LayoutManager is created and publishes the data before the widget gets created and thus the widget subscribes to the topic after it has occurred. Have the LayoutManager subscribe to a "my widget is started" topic and the widget still subscribe to the "channel_id" in its startup event and publish the "my widget is started" topic and the LayoutManager subscribe to a "my widget is started" topic would publish the "channel_id" topic.

I think a much cleaner and better route would be to use the global window._layoutManager to get to variable that you want to pass to your widget though. In the LayoutManager it sets the window._layoutManager var to an instance of it self and if you create a public var in the LayoutManager and then have your widget just use window._layoutManager.yourPublicVar in its startup function.

wadsonmakari
Occasional Contributor

Thank you very much Robert, I have with a window variable as you suggested above and it has worked.

Regards,

0 Kudos