Skip to content

Commit

Permalink
Improved lazy loading with global pilets
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianRappl committed Sep 28, 2023
1 parent 84e22fa commit 1b6514e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/converters/piral-blazor/src/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ export function createConverter(
},
});

convert.boot = () => boot(opts);
convert.loader = loader;
convert.lazy = lazy;
return convert;
Expand Down
12 changes: 8 additions & 4 deletions src/converters/piral-blazor/src/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,20 @@ export function createDependencyLoader(convert: ReturnType<typeof createConverte
window.dispatchEvent(new CustomEvent('loaded-blazor-pilet', { detail: meta }));
};

const lazy = convert.lazy && kind !== 'global';

depWithPrio.load = () => {
if (!result) {
result = !lazy ? convert.loader.then(load) : Promise.resolve();
result = convert.loader.then(load);
}

return result;
};
result = !lazy && convert.loader.then(load);

if (kind === 'global' && !convert.loader) {
result = convert.boot().then(load);
} else if (!convert.lazy || kind === 'global') {
result = convert.loader.then(load);
}

dependency = (config) => result || (result = load(config));

if (prio) {
Expand Down

0 comments on commit 1b6514e

Please sign in to comment.