from
Adapts a callback subscription, an Observable, or an async iterable into an async iterable that a computation returns: createMemo(() => from(source)). During hydration, a subscription renders the server's first value and subscribes again once its section has hydrated.
Import
import { from } from "solid-js";Type signature
function from<T>(source: FromSource<T>): AsyncIterable<T>;Parameters
source
- Type:
FromSource<T>
Examples
const position = createMemo(() => from<Position>((next, error) => { const id = navigator.geolocation.watchPosition(next, error); return () => navigator.geolocation.clearWatch(id); }));const ticks = createMemo(() => from(interval$(rate())));Learn more
Related types
FromSource
Anything from accepts: a subscribe function
((next, error, complete) => unsubscribe), an object with
subscribe(observer) (RxJS and TC39 Observables, including
Symbol.observable / "@@observable" interop), or an AsyncIterable.
type FromSource<T> = | (( next: (value: T) => void, error: (err: unknown) => void, complete: () => void ) => Teardown) | { subscribe(observer: FromObserver<T>): Teardown } | AsyncIterable<T>;