This commit is contained in:
Michael Sippel 2024-12-24 12:55:34 +01:00
parent af0d72df00
commit 5b493e3e4b
Signed by: senvas
GPG key ID: F96CF119C34B64A6
5 changed files with 25 additions and 25 deletions

View file

@ -75,7 +75,7 @@ pub struct VecBuffer<T>
where
T: Clone + Send + Sync + 'static,
{
data: Arc<RwLock<Vec<T>>>,
pub data: Arc<RwLock<Vec<T>>>,
port: InnerViewPort<RwLock<Vec<T>>>
}
@ -103,6 +103,7 @@ where
}
pub fn attach_to(&self, port: OuterViewPort< dyn ListView<T> >) -> Arc<RwLock<VecBufferTarget<T>>> {
self.port.0.update_hooks.write().unwrap().clear();
self.port.0.add_update_hook(Arc::new(port.0.clone()));
let target = Arc::new(RwLock::new(

View file

@ -88,14 +88,14 @@ where
let old_len = self.len();
self.src_view = view;
let new_len = self.len();
/* ????
if let Some(len) = old_len {
self.cast.notify_each(0..len);
/* required ? */
self.cast.notify(&ListDiff::Clear);
/*
for idx in 0..self.len().unwrap_or(0) {
self.cast.notify(&ListDiff::Insert{ idx, val: self.get(&idx).unwrap() });
}
if let Some(len) = new_len {
self.cast.notify_each(0..len);
}
*/
*/
}
fn notify(&mut self, msg: &ListDiff<SrcItem>) {

View file

@ -81,11 +81,9 @@ where
self.src_view = view;
let new_len = self.len();
if let Some(len) = old_len {
self.cast.notify_each(0..len);
}
if let Some(len) = new_len {
self.cast.notify_each(0..len);
if let Some(old_len) = old_len {
let new_len = new_len.unwrap_or(0);
self.cast.notify_each(0..std::cmp::max(old_len, new_len));
}
}

View file

@ -71,6 +71,10 @@ where
port.get_view_arc()
}
/*
TODO: new_list_arg()
*/
pub fn new_index_arg<Key: Clone + Send + Sync + 'static, Item: 'static>(
&mut self,
arg_key: ArgKey,

View file

@ -38,7 +38,7 @@ where
}
pub fn set_view(&self, view: Option<Arc<V>>) {
let mut v = self.view.write().unwrap();
let mut v = self.view.write().unwrap();
*v = view.clone();
self.cast.write().unwrap().reset(view);
}
@ -49,15 +49,12 @@ where
pub fn add_observer(&self, observer: Arc<RwLock<dyn Observer<V>>>) {
self.update();
self.cast
.write()
.unwrap()
.add_observer(Arc::downgrade(&observer));
observer
.write()
.unwrap()
.reset(self.view.read().unwrap().clone());
let mut obs = observer.write().unwrap();
let mut cst = self.cast.write().unwrap();
obs.reset(self.view.read().unwrap().clone());
cst.add_observer(Arc::downgrade(&observer));
}
pub fn add_update_hook(&self, hook_cast: Arc<dyn UpdateTask>) {
@ -112,8 +109,9 @@ where V::Msg: Clone
let keepalive = Arc::new(RwLock::new( self.inner() ));
other_port.update(); // todo: required?
other_port.add_observer( keepalive.clone() );
self.update_hooks.write().unwrap().clear();
other_port.add_observer( keepalive.clone() );
self.set_view( other_port.view.read().unwrap().clone() );
self.add_update_hook( Arc::new(other_port) );
self.update();
keepalive
@ -129,7 +127,7 @@ impl<V: View + ?Sized + 'static> Observer<V> for InnerViewPort<V> where V::Msg:
fn reset(&mut self, new_view: Option<Arc<V>>) {
self.set_view(new_view);
}
fn notify(&mut self, msg: &V::Msg) {
self.0.cast.write().unwrap().notify(msg);
}
@ -374,4 +372,3 @@ where
}
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>