EventSubscription
A subscription to a native event, which remove() ends.
Usage
Observe compass readings and stop when the screen unmounts.
// Observe compass readings and stop when the screen unmounts.
import { Text, onMount, signal, location, type EventSubscription } from 'kuito';
export function Compass() {
const heading = signal('Waiting for compass');
onMount(() => {
let disposed = false;
let subscription: EventSubscription | undefined;
void location
.watchHeading((value) => {
heading.value = JSON.stringify(value);
})
.then((value) => {
if (disposed) value.remove();
else subscription = value;
})
.catch((error) => {
heading.value = String(error);
});
return () => {
disposed = true;
subscription?.remove();
};
});
return <Text>{heading.value}</Text>;
}Type declaration
export interface EventSubscription {
remove(): void;
}Members 1
| Name | Type | Required | Description |
|---|---|---|---|
remove | () => void | Yes | — |
remove — method signatures
Signatures
(): voidParameters
No parameters.
Returns
void
Generated from the public TypeScript declarations: signatures, props and defaults come from the checked source, descriptions from its JSDoc. No defaults are invented.