-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dynamic-import-handler): add "withDynamicImportHandler" to make …
…things easier
- Loading branch information
Showing
4 changed files
with
38 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
projects/ng-error-handlers/dynamic-import-handler/public-api.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./dynamic-import-handler"; | ||
export * from "./with-dynamic-import-handler"; |
29 changes: 29 additions & 0 deletions
29
projects/ng-error-handlers/dynamic-import-handler/with-dynamic-import-handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { | ||
ERROR_HANDLERS, | ||
ErrorHandlerFn, | ||
ErrorHandlersFeature, | ||
ErrorHandlersFeatureKind, | ||
makeErrorHandlersFeature, | ||
} from "ng-error-handlers"; | ||
import { dynamicImportHandler } from "./dynamic-import-handler"; | ||
|
||
/** | ||
* Provides an error handler that handles failed dynamic imports such as lazy components. | ||
* @param callback A callback that will be executed when a dynamic import fails. If not provided | ||
* then the page will be reloaded. | ||
* @example | ||
* provideErrorHandlers( | ||
* withDynamicImportHandler(), // with default behaviour (page reload) | ||
* withDynamicImportHandler(failedImport => alert(failedImport)), // with custom behaviour | ||
*/ | ||
export function withDynamicImportHandler( | ||
callback?: ErrorHandlerFn, | ||
): ErrorHandlersFeature<ErrorHandlersFeatureKind.FuncHandlers> { | ||
return makeErrorHandlersFeature(ErrorHandlersFeatureKind.FuncHandlers, [ | ||
{ | ||
provide: ERROR_HANDLERS, | ||
useFactory: () => dynamicImportHandler(callback), | ||
multi: true, | ||
}, | ||
]); | ||
} |