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 where
T: Clone + Send + Sync + 'static, T: Clone + Send + Sync + 'static,
{ {
data: Arc<RwLock<Vec<T>>>, pub data: Arc<RwLock<Vec<T>>>,
port: InnerViewPort<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>>> { 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())); self.port.0.add_update_hook(Arc::new(port.0.clone()));
let target = Arc::new(RwLock::new( let target = Arc::new(RwLock::new(

View file

@ -88,14 +88,14 @@ where
let old_len = self.len(); let old_len = self.len();
self.src_view = view; self.src_view = view;
let new_len = self.len(); let new_len = self.len();
/* ????
if let Some(len) = old_len { /* required ? */
self.cast.notify_each(0..len); 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>) { fn notify(&mut self, msg: &ListDiff<SrcItem>) {

View file

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

View file

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

View file

@ -49,15 +49,12 @@ where
pub fn add_observer(&self, observer: Arc<RwLock<dyn Observer<V>>>) { pub fn add_observer(&self, observer: Arc<RwLock<dyn Observer<V>>>) {
self.update(); self.update();
self.cast
.write()
.unwrap()
.add_observer(Arc::downgrade(&observer));
observer let mut obs = observer.write().unwrap();
.write() let mut cst = self.cast.write().unwrap();
.unwrap()
.reset(self.view.read().unwrap().clone()); obs.reset(self.view.read().unwrap().clone());
cst.add_observer(Arc::downgrade(&observer));
} }
pub fn add_update_hook(&self, hook_cast: Arc<dyn UpdateTask>) { 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() )); let keepalive = Arc::new(RwLock::new( self.inner() ));
other_port.update(); // todo: required? other_port.update(); // todo: required?
other_port.add_observer( keepalive.clone() );
self.update_hooks.write().unwrap().clear(); 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.add_update_hook( Arc::new(other_port) );
self.update(); self.update();
keepalive keepalive
@ -374,4 +372,3 @@ where
} }
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>