Skip to content

reactivity

wybthon.reactivity

Signal-based reactive primitives and async Resource helper.

Computation

Reactive computation that tracks Signals and re-runs when they change.

Resource

Bases: Generic[R]

Async resource wrapper with Signals for data, error, and loading.

Use reload() to (re)fetch, cancel() to cancel the in-flight request.

Signal

Bases: Generic[T]

Mutable container that notifies subscribed computations on changes.

batch()

Batch signal updates within the returned context manager.

computed(fn)

Create a computed value that derives from other signals.

effect(fn)

Run a reactive effect and return its computation handle.

on_effect_cleanup(comp, fn)

Register a cleanup callback to run when a computation is disposed.

signal(value)

Create a new Signal with the given initial value.

use_resource(fetcher)

Create an async Resource with loading/error states and cancellation.

The provided fetcher should be an async function returning the data value. If it accepts a signal keyword argument, an AbortSignal will be passed for cancellation support when available.

Public API

  • signal(value) -> Signal[T]
  • computed(fn) -> _Computed[T] with .get() and .dispose()
  • effect(fn) -> Computation (returns a handle; call .dispose() to stop)
  • on_effect_cleanup(comp, fn)
  • batch() -> context manager
  • Resource(fetcher) and use_resource(fetcher) -> Resource

Type hints are provided for all public functions and classes. Prefer retrieving values via .get() on signals and computed values to subscribe computations.