Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

topic.publish not triggered on the first load ?

Vote:
 

We are using functions to listen to page change and then do something. For this we are using topic.subscribe and topic.publish in the following manner

      postCreate: function () {
            if (typeof SiteAttention !== 'undefined' ) {
                try {
                    SiteAttention.quit();
                } catch (ex) {
                    console.log('SiteAttention: ' + ex);
                }
            }
            
            if (!EPiServerSiteAttentionData.OnModelChangeSubscribed) {
                topic.subscribe("siteattention/modelchanged", lang.hitch(this, "_onModelChanged"));
                EPiServerSiteAttentionData.OnModelChangeSubscribed = true;
            }

            when(this.getCurrentContent(), function (contentData) {
                topic.publish("siteattention/modelchanged", { contentData: contentData });
            });

        },

There are two places in the code where topic.publish is used, one as shown above and the other as below.

In both the cases the topic.publish does not trigger on the first load of the page, where as on the second load of the page it works.

There are also issues on the order in which topic.publish is called, ideally the topic.publish in the postCreate has to be called before the topic.publish in the updateCommandModel. But it is not the case always.

updateCommandModel: function (model) {

            this.inherited(arguments);

            this._model = model;
            this._refreshDataModel();

            topic.publish("siteattention/modelchanged", model);
        }

Do you have a solution to the above issues ? Also could you provide documentation on  updateCommandModel ? 

Thanks

Mariam Reba

#194557
Edited, Jun 25, 2018 13:33
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.