Skip to content

Commit ca2cb63

Browse files
authored
refactor: simplify bootstrap (#190)
1 parent cbc9c75 commit ca2cb63

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

packages/base/src/sap/ui/webcomponents/base/Bootstrap.js

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import whenDOMReady from "./util/whenDOMReady";
22
import EventEnrichment from "./events/EventEnrichment";
33
import { insertIconFontFace } from "./IconFonts";
44
import DOMEventHandler from "./DOMEventHandler";
5+
import whenPolyfillLoaded from "./compatibility/whenPolyfillLoaded";
56

67
EventEnrichment.run();
78

@@ -14,22 +15,12 @@ const Bootstrap = {
1415
return bootPromise;
1516
}
1617

17-
bootPromise = new Promise(resolve => {
18-
whenDOMReady().then(() => {
19-
insertIconFontFace();
20-
DOMEventHandler.start();
21-
22-
if (window.WebComponents && window.WebComponents.waitFor) {
23-
// the polyfill loader is present
24-
window.WebComponents.waitFor(() => {
25-
// the polyfills are loaded, safe to execute code depending on their APIs
26-
resolve();
27-
});
28-
} else {
29-
// polyfill loader missing, modern browsers only
30-
resolve();
31-
}
32-
});
18+
bootPromise = new Promise(async resolve => {
19+
await whenDOMReady();
20+
insertIconFontFace();
21+
DOMEventHandler.start();
22+
await whenPolyfillLoaded();
23+
resolve();
3324
});
3425

3526
return bootPromise;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
let polyfillLoadedPromise;
2+
3+
const whenPolyfillLoaded = () => {
4+
if (polyfillLoadedPromise) {
5+
return polyfillLoadedPromise;
6+
}
7+
8+
polyfillLoadedPromise = new Promise(resolve => {
9+
if (window.WebComponents && window.WebComponents.waitFor) {
10+
// the polyfill loader is present
11+
window.WebComponents.waitFor(() => {
12+
// the polyfills are loaded, safe to execute code depending on their APIs
13+
resolve();
14+
});
15+
} else {
16+
// polyfill loader missing, modern browsers only
17+
resolve();
18+
}
19+
});
20+
21+
return polyfillLoadedPromise;
22+
};
23+
24+
export default whenPolyfillLoaded;

0 commit comments

Comments
 (0)