DeloitteAU / react-habitat

⚛️ 🛅 A React DOM Bootstrapper designed to harmonise a hybrid 'CMS + React' application.
Other
262 stars 42 forks source link

Promise fired when all lazily components are loaded #45

Open niespodd opened 5 years ago

niespodd commented 5 years ago

Is it possible to fire a callback when all components registered with registerAsync are loaded? So far I resorted to a dirty hack (which is not fully correct, but gives an idea what I want to do) shown below.

// ...
const build = containerBuilder.build();
Promise.all(Object.values(build._registrations).map((registration) => registration._operator()))
   .then(() => console.log("hurray"));

Is there a cleaner way to do that?

The reason I want this is that I want to avoid flickering when N different components are loaded individually. I want all of them to render at once and at the same time if a component is not used I'ld like to not download it's chunk.