pub struct SignalVec<T: 'static> { /* private fields */ }
Expand description
A reactive Vec
.
This is more effective than using a Signal<Vec>
because it allows fine grained
reactivity within the Vec
.
Implementations§
Source§impl<T: 'static> SignalVec<T>
impl<T: 'static> SignalVec<T>
Sourcepub fn with_values(values: Vec<T>) -> Self
pub fn with_values(values: Vec<T>) -> Self
Create a new SignalVec
with existing values from a Vec
.
Sourcepub fn changes(&self) -> &Rc<RefCell<Vec<VecDiff<T>>>>
pub fn changes(&self) -> &Rc<RefCell<Vec<VecDiff<T>>>>
Get the current pending changes that will be applied to the SignalVec
.
Sourcepub fn inner_signal(&self) -> &Signal<RefCell<Vec<T>>>
pub fn inner_signal(&self) -> &Signal<RefCell<Vec<T>>>
pub fn replace(&self, values: Vec<T>)
pub fn insert(&self, index: usize, value: T)
pub fn update(&self, index: usize, value: T)
pub fn remove(&self, index: usize)
pub fn swap(&self, index1: usize, index2: usize)
pub fn push(&self, value: T)
pub fn pop(&self)
pub fn clear(&self)
Sourcepub fn map<U: Clone>(&self, f: impl Fn(&T) -> U + 'static) -> SignalVec<U>
pub fn map<U: Clone>(&self, f: impl Fn(&T) -> U + 'static) -> SignalVec<U>
Creates a derived SignalVec
.
§Example
use maple_core::prelude::*;
let my_vec = SignalVec::with_values(vec![1, 2, 3]);
let squared = my_vec.map(|x| *x * *x);
assert_eq!(*squared.inner_signal().get().borrow(), vec![1, 4, 9]);
my_vec.push(4);
assert_eq!(*squared.inner_signal().get().borrow(), vec![1, 4, 9, 16]);
my_vec.swap(0, 1);
assert_eq!(*squared.inner_signal().get().borrow(), vec![4, 1, 9, 16]);
Source§impl SignalVec<TemplateResult>
impl SignalVec<TemplateResult>
Sourcepub fn template_list(&self) -> TemplateList
pub fn template_list(&self) -> TemplateList
Create a TemplateList
from the SignalVec
.
Trait Implementations§
Source§impl From<SignalVec<TemplateResult>> for TemplateList
impl From<SignalVec<TemplateResult>> for TemplateList
Source§fn from(templates: SignalVec<TemplateResult>) -> Self
fn from(templates: SignalVec<TemplateResult>) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl<T> Freeze for SignalVec<T>
impl<T> !RefUnwindSafe for SignalVec<T>
impl<T> !Send for SignalVec<T>
impl<T> !Sync for SignalVec<T>
impl<T> Unpin for SignalVec<T>
impl<T> !UnwindSafe for SignalVec<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more