signal_ref for MutableVec
yrns opened this issue · comments
Forgive me if I'm not seeing it, but is there no way to create a signal from a MutableVec
where the values aren't Copy
or Clone
? Like an equivalent of signal_ref
for Mutable
?
Unfortunately that's not possible, because it needs to maintain a history of the exact operations (in order). For example, let's say you had a situation like this...
let x = MutableVec::new();
let s1 = x.signal_vec_cloned();
let s2 = x.signal_vec_cloned();
x.lock_mut().push(5);
x.lock_mut().push(10);
And let's suppose that s1
is updated faster than s2
. In that case s2
would have to store the push
events, so it can process them later. So it cannot have a reference to the MutableVec
, it must clone.
A similar situation happens if s1
or s2
are delayed for any reason (e.g. for_each
, delay_remove
, etc.) in that case it has to store the events.
However, you can use Rc
or Arc
, which allows you to clone anything very cheaply. For example, MutableVec<Rc<Foo>>