observable
Edit this pageobservable creates an Observable-compatible object from a Solid accessor.
Import
import { observable } from "solid-js";Type
function observable<T>(input: () => T): Observable<T>;Parameters
input
- Type:
() => T - Required: Yes
Accessor used as the observable source.
Return value
- Type:
Observable<T>
Returns an object with subscribe() and [Symbol.observable]() that returns the same object.
Behavior
subscribe()accepts either a function observer or an object observer withnext.- Each subscription creates an effect over the accessor and returns an object with
unsubscribe(). - If subscription happens inside an owned Solid scope, cleanup is also registered on that owner.
Examples
Convert an accessor to an Observable-compatible source
import { createSignal, observable } from "solid-js";import { from } from "rxjs";
const [value] = createSignal(0);
const value$ = from(observable(value));
value$.subscribe((next) => console.log(next));