An atom that takes writes of W: registry.set(atom, value)
calls write.
Attributes#
| Attribute | Type | Description |
|---|---|---|
write | Final[Callable[[WriteContext[Any], W_contra], None]] = write |
Functions#
__init__#
__init__(read, write, refresh=None) -> None| Parameter | Type | Description |
|---|---|---|
read | Callable[[AtomContext], A_co] | |
write | Callable[[WriteContext[Any], W_contra], None] | |
refresh | Refresh | None = None |
def __init__(
self,
read: Callable[[AtomContext], A_co],
write: Callable[[WriteContext[Any], W_contra], None],
refresh: Refresh | None = None,
) -> None:
super().__init__(read, refresh)
self.write: Final[Callable[[WriteContext[Any], W_contra], None]] = writemap#
map[B](f) -> Writable[B, W_contra]| Parameter | Type | Description |
|---|---|---|
f | Callable[[A_co], B] |
Returns Writable[B, W_contra]
def map[B](self, f: Callable[[A_co], B]) -> Writable[B, W_contra]:
from pyfect.reactivity.atom._combinators import transform
return transform(self, lambda get, atom: f(get(atom)))transform#
transform[B](f, *, initial_value_target=None) -> Writable[B, W_contra]| Parameter | Type | Description |
|---|---|---|
f | Callable[[AtomContext, Self], B] | |
initial_value_target | Atom[B] | None = None |
Returns Writable[B, W_contra]
def transform[B](
self,
f: Callable[[AtomContext, Self], B],
*,
initial_value_target: Atom[B] | None = None,
) -> Writable[B, W_contra]:
from pyfect.reactivity.atom._combinators import transform
return transform(self, f, initial_value_target=initial_value_target)map_result#
map_result[A, E, B, W](f) -> Writable[AsyncResult[B, E], W]| Parameter | Type | Description |
|---|---|---|
f | Callable[[A], B] |
Returns Writable[AsyncResult[B, E], W]
def map_result[A, E, B, W](
self: Writable[AsyncResult[A, E], W], f: Callable[[A], B]
) -> Writable[AsyncResult[B, E], W]:
from pyfect.reactivity import async_result
return self.map(lambda result: async_result.map(result, f))with_fallback#
with_fallback[A, E, A2, E2, W](fallback) -> Writable[AsyncResult[A | A2, E | E2], W]| Parameter | Type | Description |
|---|---|---|
fallback | Atom[AsyncResult[A2, E2]] |
Returns Writable[AsyncResult[A | A2, E | E2], W]
def with_fallback[A, E, A2, E2, W](
self: Writable[AsyncResult[A, E], W], fallback: Atom[AsyncResult[A2, E2]]
) -> Writable[AsyncResult[A | A2, E | E2], W]:
from pyfect.reactivity.atom._combinators import with_fallback
return with_fallback(self, fallback)debounce#
debounce(duration) -> Writable[A_co, W_contra]| Parameter | Type | Description |
|---|---|---|
duration | DurationInput |
Returns Writable[A_co, W_contra]
def debounce(self, duration: DurationInput) -> Writable[A_co, W_contra]:
return cast("Writable[A_co, W_contra]", super().debounce(duration))with_refresh#
with_refresh(duration) -> Writable[A_co, W_contra]| Parameter | Type | Description |
|---|---|---|
duration | DurationInput |
Returns Writable[A_co, W_contra]
def with_refresh(self, duration: DurationInput) -> Writable[A_co, W_contra]:
return cast("Writable[A_co, W_contra]", super().with_refresh(duration))refresh_on_signal#
refresh_on_signal(signal) -> Writable[A_co, W_contra]| Parameter | Type | Description |
|---|---|---|
signal | Atom[object] |
Returns Writable[A_co, W_contra]
def refresh_on_signal(self, signal: Atom[object]) -> Writable[A_co, W_contra]:
return cast("Writable[A_co, W_contra]", super().refresh_on_signal(signal))refresh_on_window_focus#
refresh_on_window_focus() -> Writable[A_co, W_contra]Returns Writable[A_co, W_contra]
def refresh_on_window_focus(self) -> Writable[A_co, W_contra]:
return cast("Writable[A_co, W_contra]", super().refresh_on_window_focus())swr#
swr[A, E, W](*, stale_time, revalidate_on_mount=True, revalidate_on_focus=False, focus_signal=None) -> Writable[AsyncResult[A, E], W]| Parameter | Type | Description |
|---|---|---|
stale_time | DurationInput | |
revalidate_on_mount | bool = True | |
revalidate_on_focus | bool | Literal['always'] = False | |
focus_signal | Atom[object] | None = None |
Returns Writable[AsyncResult[A, E], W]
def swr[A, E, W](
self: Writable[AsyncResult[A, E], W],
*,
stale_time: DurationInput,
revalidate_on_mount: bool = True,
revalidate_on_focus: bool | Literal["always"] = False,
focus_signal: Atom[object] | None = None,
) -> Writable[AsyncResult[A, E], W]:
from pyfect.reactivity.atom._swr import swr
derived = swr(
self,
stale_time=stale_time,
revalidate_on_mount=revalidate_on_mount,
revalidate_on_focus=revalidate_on_focus,
focus_signal=focus_signal,
)
return cast("Writable[AsyncResult[A, E], W]", derived)pipe#
pipe[B](f) -> B| Parameter | Type | Description |
|---|---|---|
f | Callable[[Self], B] |
Returns B
def pipe[B](self, f: Callable[[Self], B], /) -> B:
return f(self)keep_alive#
keep_alive() -> SelfThis atom, kept when nothing uses it.
Returns Self
def keep_alive(self) -> Self:
"""This atom, kept when nothing uses it."""
return self._with(kept_alive=True)auto_dispose#
auto_dispose() -> SelfThis atom, removed when nothing uses it.
Returns Self
def auto_dispose(self) -> Self:
"""This atom, removed when nothing uses it."""
return self._with(kept_alive=False)set_lazy#
set_lazy(lazy) -> SelfFalse: rebuilt as soon as a dependency changes, not when next
read.
| Parameter | Type | Description |
|---|---|---|
lazy | bool |
Returns Self
def set_lazy(self, lazy: bool) -> Self:
"""``False``: rebuilt as soon as a dependency changes, not when next
read."""
return self._with(lazy=lazy)set_idle_ttl#
set_idle_ttl(duration) -> SelfKeep this atom duration after it is last used; an infinite
duration keeps it alive.
| Parameter | Type | Description |
|---|---|---|
duration | DurationInput |
Returns Self
def set_idle_ttl(self, duration: DurationInput) -> Self:
"""Keep this atom ``duration`` after it is last used; an infinite
duration keeps it alive."""
from pyfect.reactivity.atom._combinators import set_idle_ttl
return set_idle_ttl(self, duration)with_equality#
with_equality(equals) -> SelfValues equals calls equal are not a change: no notification,
no rebuild of dependents.
| Parameter | Type | Description |
|---|---|---|
equals | Callable[[A_co, A_co], bool] |
Returns Self
def with_equality(self, equals: Callable[[A_co, A_co], bool]) -> Self:
"""Values ``equals`` calls equal are not a change: no notification,
no rebuild of dependents."""
return self._with(equals=equals)with_label#
with_label(name) -> SelfName this atom (with where the label was set).
| Parameter | Type | Description |
|---|---|---|
name | str |
Returns Self
def with_label(self, name: str) -> Self:
"""Name this atom (with where the label was set)."""
from pyfect.reactivity.atom._combinators import label_site
return self._with(label=(name, label_site(2)))with_reactivity#
with_reactivity(keys) -> SelfRefresh this atom when keys are invalidated through the
registry's Reactivity (the default runtime's).
| Parameter | Type | Description |
|---|---|---|
keys | Keys |
Returns Self
def with_reactivity(self, keys: Keys) -> Self:
"""Refresh this atom when ``keys`` are invalidated through the
registry's ``Reactivity`` (the default runtime's)."""
from pyfect.reactivity.atom._runtime import runtime
return runtime.with_reactivity(keys)(self)serializable#
serializable(*, key, schema, skip_initial_run=False) -> SelfMark this atom for Hydration: its value is encoded with
schema (as JSON) under key, which also identifies its node.
schema's type must be the atom's value.
| Parameter | Type | Description |
|---|---|---|
key | str | |
schema | Codec[A_co, Any, Never, Never] | |
skip_initial_run | bool = False |
Returns Self
def serializable(
self,
*,
key: str,
# Effect's `S extends ConstraintCodec<Type<R>, any>`
schema: Codec[A_co, Any, Never, Never],
skip_initial_run: bool = False,
) -> Self:
"""Mark this atom for ``Hydration``: its value is encoded with
``schema`` (as JSON) under ``key``, which also identifies its node.
``schema``'s type must be the atom's value."""
from pyfect.reactivity.atom._serializable import serializable
return serializable(self, key=key, schema=schema, skip_initial_run=skip_initial_run)with_server_value#
with_server_value(read) -> SelfThe value get_server_value reports for this atom.
| Parameter | Type | Description |
|---|---|---|
read | Callable[[Callable[[Atom[Any]], Any]], A_co] |
Returns Self
def with_server_value(self, read: Callable[[Callable[[Atom[Any]], Any]], A_co]) -> Self:
"""The value ``get_server_value`` reports for this atom."""
return self._with(server_value=read)optimistic#
optimistic() -> Writable[A_co, Atom[AsyncResult[A_co, object]]]An atom showing optimistic values while the transitions written to it run, then this atom's value (refreshed after a success).
Returns Writable[A_co, Atom[AsyncResult[A_co, object]]]
def optimistic(self) -> Writable[A_co, Atom[AsyncResult[A_co, object]]]:
"""An atom showing optimistic values while the transitions written
to it run, then this atom's value (refreshed after a success)."""
from pyfect.reactivity.atom._optimistic import optimistic
return optimistic(self)