Bootstrap
Start an Angular app on Lynx and register the renderer that draws it. import { bootstrapApplication, provideRenderer, loadLazyBundle } from '@blotch/angular-lynx';
Usage
ng add @blotch/angular-lynx writes both files for you.
API
bootstrapApplication()
Starts your app on Lynx. Use it instead of the bootstrapApplication from @angular/platform-browser, which needs a browser DOM.
- Starts the app on the main thread, once Lynx is ready to render the page.
- Starts nothing on the background thread. That thread doesn't load your
main.ts: it starts from an entry the build generates, with your background functions. Ifmain.tsdefines a background function itself, it loads there too, and the promise this returns there never settles, so code chained on it runs once. See Threads. - Hot reload. Calling it again destroys the running app first, then starts the new one.
- Returns the
ApplicationRef, as Angular's version does.
provideRenderer()
Registers the renderer that turns your templates into Lynx elements. Every app needs it. Change detection needs no provider: without Zone.js, Angular is zoneless by default.
It also provides these Angular tokens:
loadLazyBundle()
Loads a component from a separately built Lynx bundle at runtime.
- Resolves with the bundle's default export, or with all its exports when it has no default.
- Caches by
source: repeat calls return the same promise. - On the background thread, it rejects when the bundle fails to load or run.
- On the main thread, it loads synchronously. If loading fails, the promise never settles and the component doesn't appear.
- Rejects when Lynx's bundle loader isn't available, such as in unit tests.
Lazy routes with import() and @defer blocks don't need loadLazyBundle(). The build includes their code for you. These docs don't yet cover how to build a standalone component bundle.
Types
This page uses only Angular types: ApplicationConfig, ApplicationRef, EnvironmentProviders and Type from @angular/core.
Related
- Quick Start: create an app that already has this setup.
- How a Lynx app runs
- Signals and change detection: why the app must be zoneless.
- Routing: add
provideRouter()next toprovideRenderer(). - Errors and logging
