Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | 1x 1x 3x 2x 2x | import { ApplicationConfig, ApplicationRef } from '@angular/core';
import type { bootstrapApplication } from '@angular/platform-browser';
import { resolveDependencies } from './resolve-dependencies';
import { FastApplicationConfig, FastComponent } from './types';
/**
* Dynamically loads the specified providers in the configuration and bootstraps an Angular application.
*
* This function uses the custom applicationBoostrap function argument to start an Angular application with providers
* that are dynamically loaded and resolved. The application configuration can include providers that need to
* be loaded asynchronously. This function handles resolving these providers and passing them to the custom bootstrap function.
*
* @param bootstrap - The Angular application's bootstrap function (typically `bootstrapApplication`).
* @param rootComponent - The root component of the application, which should be of type `FastComponent`
* (ie. Type<unknown> or lazy module that return this component).
* @param options - (Optional) The application configuration, including the providers to be loaded. It should conform
* to the `FastApplicationConfig` type. Providers can be `Provider`, `EnvironmentProviders`,
* or lazy modules that return these providers.
*
* @returns A Promise that resolves to an `ApplicationRef` instance of the bootstrapped application. The bootstrap
* method is called with the root component and the updated configuration with the resolved providers.
*
* @example
* ```typescript
* import { AppComponent } from './app.component';
* import { bootstrapApplication } from '@angular/platform-browser';
* import { fast } from 'ngx-fastboot';
*
* fast(bootstrapApplication, AppComponent, {
* providers: [
* MyProvider,
* () => import('./my-provider.module'),
* ]
* }).then(() => console.log('App is bootstrapped'))
* .catch(error => {
* console.error('Error bootstrapping the app', error);
* });
* ```
*/
export const fast = async (
bootstrap: typeof bootstrapApplication,
rootComponent: FastComponent,
options?: FastApplicationConfig,
): Promise<ApplicationRef> => {
const { component, providers } = await resolveDependencies(
rootComponent,
options?.providers ?? [],
);
const nextOptions: ApplicationConfig = {
...options,
providers,
};
return bootstrap(component, nextOptions);
};
|