Struct perseus::state::RxResultRx
source · pub struct RxResultRx<T, E>(_)
where
T: MakeRx + Serialize + DeserializeOwned + 'static,
<T as MakeRx>::Rx: MakeUnrx<Unrx = T> + Freeze + Clone + 'static,
E: Serialize + DeserializeOwned + Clone + 'static;
Expand description
The intermediate reactive type for RxResult
. You shouldn’t need to
interface with this manually.
Methods from Deref<Target = Signal<T>>§
pub fn set(&self, value: T)
pub fn set(&self, value: T)
Set the current value of the state.
This will notify and update any effects and memos that depend on this value.
Example
let state = create_signal(cx, 0);
assert_eq!(*state.get(), 0);
state.set(1);
assert_eq!(*state.get(), 1);
pub fn set_rc(&self, value: Rc<T>)
pub fn set_rc(&self, value: Rc<T>)
Set the current value of the state wrapped in a Rc
. Unlike [Signal::set()
], this
method accepts the value wrapped in a Rc
because the underlying storage is already using
Rc
, thus preventing an unnecessary clone.
This will notify and update any effects and memos that depend on this value.
Example
let state = create_signal(cx, 0);
assert_eq!(*state.get(), 0);
state.set_rc(Rc::new(1));
assert_eq!(*state.get(), 1);
pub fn set_silent(&self, value: T)
pub fn set_silent(&self, value: T)
Set the current value of the state without triggering subscribers.
Make sure you know what you are doing because this can make state inconsistent.
pub fn set_rc_silent(&self, value: Rc<T>)
pub fn set_rc_silent(&self, value: Rc<T>)
Set the current value of the state wrapped in a Rc
without triggering subscribers.
See the documentation for [Signal::set_rc()
] for more information.
Make sure you know what you are doing because this can make state inconsistent.
pub fn split(&self) -> (impl Fn() + Copy, impl Fn(T) + Copy)
pub fn split(&self) -> (impl Fn() + Copy, impl Fn(T) + Copy)
Split a signal into getter and setter handles.
Example
let (state, set_state) = create_signal(cx, 0).split();
assert_eq!(*state(), 0);
set_state(1);
assert_eq!(*state(), 1);
pub fn trigger_subscribers(&self)
pub fn trigger_subscribers(&self)
Calls all the subscribers without modifying the state.
This can be useful when using patterns such as inner mutability where the state updated will
not be automatically triggered. In the general case, however, it is preferable to use
[Signal::set()
] instead.
This will also re-compute all the subscribers of this signal by calling all the dependency callbacks.
pub fn modify(&self) -> Modify<'_, T>
pub fn modify(&self) -> Modify<'_, T>
pub fn take(&self) -> Rc<T>
pub fn take(&self) -> Rc<T>
Take the current value out and replace it with the default value.
This will notify and update any effects and memos that depend on this value.
pub fn take_silent(&self) -> Rc<T>
pub fn take_silent(&self) -> Rc<T>
Take the current value out and replace it with the default value without triggering subscribers.
Make sure you know what you are doing because this can make state inconsistent.
Methods from Deref<Target = ReadSignal<T>>§
pub fn get(&self) -> Rc<T>
pub fn get(&self) -> Rc<T>
Get the current value of the state. When called inside a reactive scope, calling this will add itself to the scope’s dependencies.
Example
let state = create_signal(cx, 0);
assert_eq!(*state.get(), 0);
state.set(1);
assert_eq!(*state.get(), 1);
pub fn get_untracked(&self) -> Rc<T>
pub fn get_untracked(&self) -> Rc<T>
Get the current value of the state, without tracking this as a dependency if inside a reactive context.
Example
let state = create_signal(cx, 1);
let double = create_memo(cx, || *state.get_untracked() * 2);
assert_eq!(*double.get(), 2);
state.set(2);
// double value should still be old value because state was untracked
assert_eq!(*double.get(), 2);
pub fn map<'a, U>(
&'a self,
cx: BoundedScope<'a, 'a>,
f: impl FnMut(&T) -> U + 'a
) -> &'a ReadSignal<U>
pub fn map<'a, U>( &'a self, cx: BoundedScope<'a, 'a>, f: impl FnMut(&T) -> U + 'a ) -> &'a ReadSignal<U>
Creates a mapped [ReadSignal
]. This is equivalent to using
[create_memo
].
Example
let state = create_signal(cx, 1);
let double = state.map(cx, |&x| x * 2);
assert_eq!(*double.get(), 2);
state.set(2);
assert_eq!(*double.get(), 4);
pub fn track(&self)
pub fn track(&self)
When called inside a reactive scope, calling this will add itself to the scope’s dependencies.
To both track and get the value of the signal, use [ReadSignal::get
] instead.
Trait Implementations§
source§impl<T, E> Clone for RxResultRx<T, E>where
T: MakeRx + Serialize + DeserializeOwned + 'static + Clone,
<T as MakeRx>::Rx: MakeUnrx<Unrx = T> + Freeze + Clone + 'static,
E: Serialize + DeserializeOwned + Clone + 'static + Clone,
T::Rx: Clone,
impl<T, E> Clone for RxResultRx<T, E>where T: MakeRx + Serialize + DeserializeOwned + 'static + Clone, <T as MakeRx>::Rx: MakeUnrx<Unrx = T> + Freeze + Clone + 'static, E: Serialize + DeserializeOwned + Clone + 'static + Clone, T::Rx: Clone,
source§fn clone(&self) -> RxResultRx<T, E>
fn clone(&self) -> RxResultRx<T, E>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<T, E> Debug for RxResultRx<T, E>where
T: MakeRx + Serialize + DeserializeOwned + 'static + Debug,
<T as MakeRx>::Rx: MakeUnrx<Unrx = T> + Freeze + Clone + 'static,
E: Serialize + DeserializeOwned + Clone + 'static + Debug,
T::Rx: Debug,
impl<T, E> Debug for RxResultRx<T, E>where T: MakeRx + Serialize + DeserializeOwned + 'static + Debug, <T as MakeRx>::Rx: MakeUnrx<Unrx = T> + Freeze + Clone + 'static, E: Serialize + DeserializeOwned + Clone + 'static + Debug, T::Rx: Debug,
source§impl<T, E> Deref 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,
impl<T, E> Deref 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,
source§impl<T, E> Freeze 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,
impl<T, E> Freeze 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,
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,
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,
source§fn make_unrx(self) -> Self::Unrx
fn make_unrx(self) -> Self::Unrx
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.