pub trait MakeUnrx {
type Unrx: Serialize + for<'de> Deserialize<'de> + MakeRx;
// Required methods
fn make_unrx(self) -> Self::Unrx;
fn compute_suspense(&self, cx: Scope<'_>);
}
Expand description
A trait for reactive struct
s that can be made un-reactive. This is the
opposite of MakeRx
, and is intended particularly for state freezing. Like
MakeRx
, this will usually be derived automatically with the #[make_rx]
macro, but you can also implement it manually.
The types that implement this are typically referred to as the intermediate
state types, as they are rendered far more ergonomic to use by being put
through Sycamore’s create_ref()
function.
Required Associated Types§
sourcetype Unrx: Serialize + for<'de> Deserialize<'de> + MakeRx
type Unrx: Serialize + for<'de> Deserialize<'de> + MakeRx
The type of the unreactive version that we’ll convert to.
Required Methods§
sourcefn make_unrx(self) -> Self::Unrx
fn make_unrx(self) -> Self::Unrx
Transforms an instance of the struct
into its unreactive version. By
having this as an associated type, we can associate the reactive type
with the unreactive, meaning greater inference and fewer arguments
that the user needs to provide to macros.
sourcefn compute_suspense(&self, cx: Scope<'_>)
fn compute_suspense(&self, cx: Scope<'_>)
Calls all handlers on suspended state, spawning scoped futures for each of them (the futures must be scoped to prevent the same handler being run multiple times concurrently if a user leaves the page and then comes back).
This has no return type, since it simply spawns futures for each of the user’s handlers. Each handler must have the following function signature:
Fn(Scope<'a>, RxRef<'a>);
Here, RxRef
denotes the reference struct
their template would be
provided with. In the case of an individual, non-nested field, this
will be &'a Signal<T>
, where T
is the type of the field.
Fallible handlers should operate on fields with type Result<T, E>
so
they can propagate errors directly back to the user’s template code.
If you’re implementing MakeUnrx
manually, you can usually leave the
body of this function empty unless you’re using the suspended state
system.