Skip to content

Commit

Permalink
feat(loader): add scope parameter (#537)
Browse files Browse the repository at this point in the history
  • Loading branch information
imtaotao committed Aug 10, 2022
1 parent 2f9f1ce commit c285c0b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/loader/src/index.ts
Expand Up @@ -78,14 +78,15 @@ export class Loader {
public requestConfig: RequestInit | ((url: string) => RequestInit);

public hooks = new PluginSystem({
error: new SyncHook<[Error], void>(),
error: new SyncHook<[Error, { scope: string }], void>(),
loaded: new SyncWaterfallHook<LoadedHookArgs<Manager>>('loaded'),
clear: new SyncWaterfallHook<{
scope: string;
fileType?: FileTypes;
}>('clear'),
beforeLoad: new SyncWaterfallHook<{
url: string;
scope: string;
requestConfig: ResponseInit;
}>('beforeLoad'),
fetch: new AsyncHook<[string, RequestInit], Response | void | false>(
Expand Down Expand Up @@ -190,6 +191,7 @@ export class Loader {
requestConfig.credentials = CrossOriginCredentials[crossOrigin];
const resOpts = this.hooks.lifecycle.beforeLoad.emit({
url,
scope,
requestConfig,
});

Expand Down Expand Up @@ -251,7 +253,7 @@ export class Loader {
})
.catch((e) => {
__DEV__ && error(e);
this.hooks.lifecycle.error.emit(e);
this.hooks.lifecycle.error.emit(e, { scope });
throw e; // Let the upper application catch the error
})
.finally(() => {
Expand Down

1 comment on commit c285c0b

@vercel
Copy link

@vercel vercel bot commented on c285c0b Aug 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.