refactor(components): split components.js into separate files and add loader; app waits for components before init
This commit is contained in:
16
public/scripts/components/ComponentsLoader.js
Normal file
16
public/scripts/components/ComponentsLoader.js
Normal file
@@ -0,0 +1,16 @@
|
||||
(function(){
|
||||
// Simple readiness flag once all component constructors are present
|
||||
function allReady(){
|
||||
return !!(window.PrimaryNodeComponent && window.ClusterMembersComponent && window.NodeDetailsComponent && window.FirmwareComponent && window.ClusterViewComponent && window.FirmwareViewComponent && window.TopologyGraphComponent && window.MemberCardOverlayComponent && window.ClusterStatusComponent);
|
||||
}
|
||||
window.waitForComponentsReady = function(timeoutMs = 5000){
|
||||
return new Promise((resolve, reject) => {
|
||||
const start = Date.now();
|
||||
(function check(){
|
||||
if (allReady()) return resolve(true);
|
||||
if (Date.now() - start > timeoutMs) return reject(new Error('Components did not load in time'));
|
||||
setTimeout(check, 25);
|
||||
})();
|
||||
});
|
||||
};
|
||||
})();
|
||||
Reference in New Issue
Block a user