0

I am looking for a way within SAPUI5/OpenUI5 to determine if Component-preload.js was loaded or if the original controllers and views were loaded.

So far...

  • I tried to exploit the namespace of my project by accessing the global JS objects my.namespace.controller, my.namespace.Component, etc. and trying to find differences when Component-preload.js was loaded vs. not loaded.
  • I tried to use $.sap.getAllDeclaredModules() and see differences when loaded vs. not loaded.
  • I tried to capture the onload event of the Component-preload.js from within my SAPUI5 code but I found no reliable way to attach my event handler before the loading happens.
  • I tried to compile a dummy controller into my Component-preload.js that is not really used in the project. But I did not find a way to create any difference between the state when Component-preload.js was loaded vs. not loaded.

I am clearly running out of ideas.

2
  • 2
    Out of curiosity: Whats the point?
    – Marc
    Apr 8, 2020 at 6:50
  • @Marc: In our dev team we want to make sure that devs are reminded if the Comp-preload.js is active. To do that we want to show a warning msg. On the live system we want to do the opposite: show a warning if the Comp-preload is missing. (This is a non-Fiory solution, so Comp-preload must be actively generated through Grunt.)
    – Jpsy
    Apr 8, 2020 at 7:25

1 Answer 1

1

Not sure if this is optimal but a small and simple solution I came up with:

The following function tries to load the Component-preload.js file

checkComponentPreloaded: function () {
    return new Promise((resolve, reject) => {
        try {
            sap.ui.require(["com/your/namespace/Component-preload"], (CP) => {
                resolve();
            });
        } catch (e) {
            reject();
        }
    });
}

Then somewhere else (e.g. init of your Component.js) you can handle the promise and do stuff (probably set some property in a config/view model):

this.checkComponentPreloaded()
    .then(() => { Log.error("Preloaded"); })
    .catch(() => { Log.error("Not preloaded"); });

Slight catch: If the Component-preload is available but empty it will still tell you it's preloaded.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.