Trait perseus::state::MakeUnrx

source ·
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 structs 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§

source

type Unrx: Serialize + for<'de> Deserialize<'de> + MakeRx

The type of the unreactive version that we’ll convert to.

Required Methods§

source

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.

source

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.

Implementors§

source§

impl<K, V> MakeUnrx for RxHashMapNestedRx<K, V>where K: Clone + Serialize + DeserializeOwned + Eq + Hash, V: MakeRx + Serialize + DeserializeOwned + 'static, V::Rx: MakeUnrx<Unrx = V> + Freeze + Clone,

§

type Unrx = RxHashMapNested<K, V>

source§

impl<K, V> MakeUnrx for RxHashMapRx<K, V>where K: Clone + Serialize + DeserializeOwned + Eq + Hash, V: Clone + Serialize + DeserializeOwned + 'static,

§

type Unrx = RxHashMap<K, V>

source§

impl<T> MakeUnrx for RxVecNestedRx<T>where T: MakeRx + Serialize + DeserializeOwned + 'static, T::Rx: MakeUnrx<Unrx = T> + Freeze + Clone,

source§

impl<T> MakeUnrx for RxVecRx<T>where T: Clone + Serialize + DeserializeOwned + 'static,

§

type Unrx = RxVec<T>

source§

impl<T, E> MakeUnrx for RxResultRx<T, E>where T: MakeRx + Serialize + DeserializeOwned + 'static, <T as MakeRx>::Rx: MakeUnrx<Unrx = T> + Freeze + Clone + 'static, E: Serialize + DeserializeOwned + Clone + 'static,

§

type Unrx = RxResult<T, E>