Trait perseus::state::MakeRx

source ·
pub trait MakeRx {
    type Rx: MakeUnrx;

    const HSR_IGNORE: bool = false;

    // Required method
    fn make_rx(self) -> Self::Rx;
}
Expand description

A trait for structs that can be made reactive. Typically, this will be derived with the #[make_rx] macro, though it can be implemented manually if you have more niche requirements.

Required Associated Types§

source

type Rx: MakeUnrx

The type of the reactive version that we’ll convert to. 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.

Provided Associated Constants§

source

const HSR_IGNORE: bool = false

This should be set to true to have this type be ignored by the hot state reloading system, which can be useful when working with state that you will regularly update in development.

For example, take a documentation website that converts Markdown to HTML in its state generation process, storing that in reactive state. If you, in development, then wanted to change some of the documentation and see the result immediately, HSR would override the new state with the old, preserving your ‘position’ in the development cycle. Only a manual reload of the page would prevent this from continuing forever. Setting this associated constant to true will tell the HSR system to ignore this type from HSR thawing, meaning the new state will always be used. Note that, depending on the structure of your application, this can sometimes cause state inconsistencies (e.g. if one state object expects another one to be in a certain state, but then one of them is ignored by HSR and resets).

This is a development-only setting, and does not exist in production. If the hsr feature flag is disabled, this will have no effect.

Typically, you would set this using the #[rx(hsr_ignore)] derive helper macro with #[derive(ReactiveState, ..)]. Note that you only need to set this to true for the top-level state type for a page, not for any nested components.

Required Methods§

source

fn make_rx(self) -> Self::Rx

Transforms an instance of the struct into its reactive version.

Implementors§

source§

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

§

type Rx = RxHashMapRx<K, V>

source§

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

§

type Rx = RxHashMapNestedRx<K, V>

source§

impl<T> MakeRx for RxVec<T>where T: Clone + Serialize + DeserializeOwned + 'static,

§

type Rx = RxVecRx<T>

source§

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

source§

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

§

type Rx = RxResultRx<T, E>

source§

impl<T: Serialize + for<'de> Deserialize<'de> + UnreactiveState + Clone> MakeRx for T

§

type Rx = UnreactiveStateWrapper<T>

source§

const HSR_IGNORE: bool = true