Host data
Read the data your native app passes in, as signals, and transform it before your app sees it. import { LynxInitData, LynxGlobalData, registerDataProcessors, type InitData, type GlobalData, type InitDataRaw, type DataProcessorDefinition } from '@blotch/angular-lynx';
The host app (the native iOS or Android app that runs your bundle) sends two kinds of data:
- InitData: data for this one page, passed when the host opens it.
- GlobalData: app-wide values, such as the theme or locale, shared by every page.
Usage
API
LynxInitData
The page's InitData as a signal.
LynxInitData.initData
Starts with the InitData the host passed when it opened the page, after your default data processor has run on it. It's {} when the host passes none, and outside Lynx. AngularLynx also keeps the value as lynx.__initData, as React Lynx does. When the host sends new data, it's merged into the current value. When the host resets the data, the new data replaces it.
LynxGlobalData
The app-wide GlobalData as a signal. LynxTheme, LynxLocale and LynxSafeArea read their values from it.
LynxGlobalData.globalData
Starts with the global values at launch, or {} when the host sets none. When the host changes them, the new values are merged into the current ones.
registerDataProcessors()
Registers functions that transform the host's InitData before your app receives it. Call it in main.ts before bootstrapApplication().
- Default processor: used when the host sends data without naming a processor.
- Named processors: used when the host names one. An unknown name passes the data through unchanged.
- A processor that throws gives your app
{}instead of crashing it. - Calling it again replaces the earlier registration.
Types
InitDataRaw
The InitData exactly as the host sends it. A processor's input. Augment it to type the raw fields.
InitData
The InitData your app reads, after processing. Augment it, as in Usage, to type initData().
Put every augmentation in a file that contains export {};. Without it, the declare module block replaces the package's types instead of adding to them.
GlobalData
The GlobalData your app reads. Augment it to type globalData().
DataProcessorDefinition
Related
- Pass data from your native app: how the host sends data, step by step.
- Embed in an existing native app
- Theme, Locale and Safe area: built on
LynxGlobalData.
