Implementing the IAsyncContentCreation interface in UI5

To ensure sap.ui.core.UIComponent to be created fully asynchronously, we need to implement the IAsyncContentCreation interface:

metadata: {
    interfaces: [
        "sap.ui.core.IAsyncContentCreation"
    ],
    manifest: "json"
}

That’s totally OK.
Exploring the SAP apps samples, I’ve found out the following code snippet, where the hard-coded and, thus error prone, interface name is replaced with code, which can be automatically checked:

sap.ui.define([
    "sap/ui/core/library",
    "sap/ui/core/UIComponent",
    …
], function(library, UIComponent, models, History) {
    "use strict";

    return UIComponent.extend("sap.ui.demo.toolpageapp.Component", {

        metadata: {
            interfaces: [
                library.IAsyncContentCreation
            ],
            manifest: "json"
        }
        …

    }
}

I’ve tried to check the content of library in DevTools, but I get a ReferenceError exception instead of the library‘s values:

Uncaught ReferenceError: library is not defined
    at eval (eval at init (Component.js:24), <anonymous>:1:1)
    at f.init (Component.js:24)
    at sap-ui-core.js:315
    at f.constructor (sap-ui-core.js:315)
    at f.constructor (sap-ui-core.js:585)
    at f.constructor (library-preload.js:1154)
    at f [as constructor] (sap-ui-core.js:547)
    at new o1 (sap-ui-core.js:632)
    at H (sap-ui-core.js:628)
    at sap-ui-core.js:628

How can I ensure that library.IAsyncContentCreation is really properly defined and returns "sap.ui.core.IAsyncContentCreation" as intended?

Answer

I’ve tried to check the content of library in DevTools, but I get a ReferenceError exception.

Most probably, you’ve encountered the V8’s debugger limitation, where the unused closure variables (here: library) are not evaluated by the V8 during the debugger session, and thus not accessible from the devtool console. See Why does Chrome debugger think closed local variable is undefined? and also the V8 issues #3491 and #2710.

The above limitation applies only to V8’s debugger. When the code is executed at runtime, library.IAsyncContentCreation will be resolved to the string "sap.ui.core.IAsyncContentCreation" as expected so you won’t get the ReferenceError.

Exploring the SAP apps samples, […] interface name is replaced with code.

It’s unclear why the sample author decided to require the core library in the first place. Those interfaces in UI5 Objects await string literals. And UI5 interfaces are simple marker interfaces (aka. tagging interfaces). They don’t specify any behavior in code. Adding the interface name (string literal) simply tells how the class implementing the interface is supposed to behave. So adding the string literal is sufficient.

interfaces: [
  "sap.ui.core.IAsyncContentCreation"
],