MainThreadRef
A box that keeps a value between calls of your main-thread scripts, such as a tap count or the element a drag started on. import { createMainThreadRef, MainThreadRef } 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
createMainThreadRef(initValue)
Creates a ref holding initValue. It's the same as new MainThreadRef(initValue).
MainThreadRef<T>
current: the value. Read it and assign to it from your main-thread functions.
Constraints
- Each thread has its own copy. The background thread also loads each file that creates a ref at module scope, so the ref exists there too. A value written on the main thread isn't seen by code on the background thread, and the reverse. Use a ref only from main-thread functions.
- Passed to a background function, it arrives as the background thread's copy, the same ref the function would reach through its closure. A ref created in a component has no copy there.
- Create it at module scope, next to the functions that use it.
- Changing it doesn't render anything. It isn't a signal.
