Skip to content

Commit

Permalink
fix(service): fix hooks failing to run
Browse files Browse the repository at this point in the history
  • Loading branch information
gshokanov committed Apr 15, 2020
1 parent 720640a commit 3e2c261
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,13 @@ export class LazyElementsLoaderService {
const notifier = this.addElement(url);
const script = document.createElement('script') as HTMLScriptElement;
const beforeLoadHook =
hooksConfig?.beforeLoad ?? this.options?.hooks?.beforeLoad;
hooksConfig?.beforeLoad ??
config?.hooks?.beforeLoad ??
this.options?.hooks?.beforeLoad;
const afterLoadHook =
hooksConfig?.afterLoad ?? this.options?.hooks?.afterLoad;
hooksConfig?.afterLoad ??
config?.hooks?.afterLoad ??
this.options?.hooks?.afterLoad;
if (isModule) {
script.type = 'module';
}
Expand Down Expand Up @@ -161,7 +165,7 @@ export class LazyElementsLoaderService {
}

private isPromise<T>(obj: T | Promise<T>): obj is Promise<T> {
return typeof (obj as any).then === 'function';
return typeof (obj as any)?.then === 'function';
}

private handleHook(hook: Hook, tag: string): Promise<void> {
Expand Down

0 comments on commit 3e2c261

Please sign in to comment.