use super::rx_observable::RxObservable;
use super::rx_subject::RxSubject;
use super::rx_val::RxVal;
#[derive(Clone)]
pub struct RxRef<T> {
inner: RxVal<T>,
}
impl<T: 'static> RxRef<T>
where
T: Clone + PartialEq,
{
pub fn new(value: T) -> Self {
Self {
inner: RxVal::new(value),
}
}
pub fn set(&self, value: T) {
self.inner.update(value);
}
pub fn get(&self) -> T {
self.inner.get()
}
pub fn val(&self) -> RxVal<T> {
self.inner.clone()
}
pub fn modify<F>(&self, f: F)
where
F: FnOnce(&mut T),
{
let mut current = self.get();
f(&mut current);
self.set(current);
}
pub fn subscriber_count(&self) -> usize {
self.inner.subscriber_count()
}
pub fn debug_ptr(&self) -> usize {
self.inner.debug_ptr()
}
pub fn stream(&self) -> RxObservable<T> {
self.inner.stream()
}
pub fn map<B, F>(&self, f: F) -> RxVal<B>
where
B: Clone + PartialEq + 'static,
F: Fn(&T) -> B + 'static,
{
self.inner.map(f)
}
pub fn flat_map<B, F>(&self, f: F) -> RxVal<B>
where
B: Clone + PartialEq + 'static,
F: Fn(&T) -> RxVal<B> + 'static,
{
self.inner.flat_map(f)
}
pub fn flat_map_ref<B, F>(&self, f: F) -> RxVal<B>
where
B: Clone + PartialEq + 'static,
F: Fn(&T) -> RxRef<B> + 'static,
{
self.inner.flat_map_ref(f)
}
pub fn flat_map_observable<B, F>(&self, f: F) -> RxObservable<B>
where
B: Clone + 'static,
F: Fn(&T) -> RxObservable<B> + 'static,
{
self.inner.flat_map_observable(f)
}
pub fn flat_map_subject<B, F>(&self, f: F) -> RxObservable<B>
where
B: Clone + 'static,
F: Fn(&T) -> RxSubject<B> + 'static,
{
self.inner.flat_map_subject(f)
}
pub fn zip_val<U>(&self, other: RxVal<U>) -> RxVal<(T, U)>
where
U: Clone + PartialEq + 'static,
{
self.inner.zip_val(other)
}
pub fn zip_ref<U>(&self, other: RxRef<U>) -> RxVal<(T, U)>
where
U: Clone + PartialEq + 'static,
{
self.inner.zip_ref(other)
}
}