sap.ui.core.ComponentContainer isComponentLoaded() promise
The ComponentContainer does not have an indication whether it has been loaded or not. When I instantiate a ComponentContainer via an XML view, I do not know when the contained component is loaded.
<core:ComponentContainer id="CompCont" name="be.myCompany.Comp" />
So when I want to retrieve a handle to the embedded component in the controller, I don't really know when to do so.
this.getView().byId("CompCont").getComponent(); might return me null, of a handle, depending on the timing.
It would be very handy if there where a loaded-promise on the componentcontainer, so I could do something like:
this.getView().byId("CompCont").isComponentLoaded().then(function(oComponent){
oComponent.attachSomethingHappened(..)
});
Yes, you're right and we internally even have a pending change that adds a whenLoaded() function to the component container.
However, we struggled a bit with the use case of changing the component (over time) and when to create a new promise in that case. That's why the change is still pending (since begin of May).
The contract of getComponentInstance() won't be changed for compatibility reasons, although it would be natural to return the promise there as well.
This issue ticket will motivate us to bring the change forward.
That's good news to hear!
I had the same reasoning with regards to getComponentInstance().
It would be natural to return a promise there, but then again I go by the principle:
- getSomething must return the value instantly
- loadSomething must return a promise (and I'm open to alternative verbs instead of load, but the idea must be respected)
@FiddleBe Not a promise but as of https://github.com/SAP/openui5/commit/f2f6ddef22b1b8a2f4be390bbc1131e8d890f96b, the event componentCreated can be used to get notified about the component availability.
<core:ComponentContainer id="CompCont"
name="be.myCompany.Comp"
componentCreated=".onComponentCreated"
/>
Exactly. With 1.50, we've introduced the componentCreated Event, see:
https://openui5.hana.ondemand.com/#/api/sap.ui.core.ComponentContainer/events/componentCreated
Sorry for not updating this issue. I think we somehow lost track of it when implementing the event.