LynxMainThreadEvent
A directive that binds main-thread scripts to an element's native events, and passes them elements they can change directly. import { LynxMainThreadEvent } from '@blotch/angular-lynx';
Info
Template handlers such as (bindtap) already run on the main thread. Main-thread scripts explains when you need this API instead.
Usage
src/app/app.ts
API
Inputs
Each input takes a handle from mainThreadFn(), or a function with the 'main thread' directive. Bind inputs let the event bubble to ancestors. Catch inputs stop it at this element.
In the handler, event.target and event.currentTarget are MainThread.Element objects. When the element is destroyed, its handlers are removed.
Constraints
- The web preview fires mouse events, not touch events. A desktop browser never fires touch events, so bind the
mouse*inputs too for a drag that works there. Phones fire touch events, plus amousedownandmouseupafter a tap. - A handler doesn't run change detection. Change the element directly, through
event.currentTarget. - Each input takes one handler. Binding a new one replaces the old one.
Types
MainThread is a namespace of the types from @lynx-js/types/main-thread:
setStyleProperty()andsetAttribute()batch their changes, and Lynx applies them together after your handler returns.invoke()calls one of the element's UI methods, such asscrollToon a<scroll-view>, and resolves with its result.getBoundingClientRect()also exists at runtime (AngularLynx'sMainThreadElementclass adds it), but isn't on the type. It returns{ left, top, right, bottom, width, height }built from the computedwidth,height,leftandtopstyles. Soleftandtopare the CSS values, often0, not the element's position on screen.
