Hello Experts,
In my old projects I sometimes load data in the component and publish event to the view.
// Component.js
init: function() {
this.getRouter().initialize();
//do some stuff and then publish event
var eventBus = this.getEventBus();
eventBus.publish("cohen.omri.myapp", "event1");
}
// View
onInit: function() {
var eventBus = this.getOwnerComponent().getEventBus();
eventBus.subscribe("cohen.omri.myapp", "event1", this.myFunc, this);
}
onExit: function() {
var eventBus = this.getOwnerComponent().getEventBus();
eventBus.unsubscribe("cohen.omri.myapp", "event1", this.myFunc, this);
}
This worked in older versions since the router was loaded synchronously.
In "newer" versions like 1.71 the router is loaded async:
https://sapui5.hana.ondemand.com/sdk/#/topic/676b636446c94eada183b1218a824717
This causes to event publishing before the router is loaded and therefore the subscribe function is not called.
The easier (and wrong solution) would be to load the router synchronously but how can I load the router asynchronously and still use eventBus that will call the subscribe function?
Regards,
Omri