diff --git a/src/buffer/vec.rs b/src/buffer/vec.rs index 76dc062..04d893e 100644 --- a/src/buffer/vec.rs +++ b/src/buffer/vec.rs @@ -75,7 +75,7 @@ pub struct VecBuffer where T: Clone + Send + Sync + 'static, { - data: Arc>>, + pub data: Arc>>, port: InnerViewPort>> } @@ -103,6 +103,7 @@ where } pub fn attach_to(&self, port: OuterViewPort< dyn ListView >) -> Arc>> { + 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( diff --git a/src/projection/map_list.rs b/src/projection/map_list.rs index 61eb380..7b055ea 100644 --- a/src/projection/map_list.rs +++ b/src/projection/map_list.rs @@ -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) { diff --git a/src/projection/map_sequence.rs b/src/projection/map_sequence.rs index c745f1e..e2d1583 100644 --- a/src/projection/map_sequence.rs +++ b/src/projection/map_sequence.rs @@ -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)); } } diff --git a/src/projection/projection_helper.rs b/src/projection/projection_helper.rs index ac533b6..b6b91f0 100644 --- a/src/projection/projection_helper.rs +++ b/src/projection/projection_helper.rs @@ -71,6 +71,10 @@ where port.get_view_arc() } + /* + TODO: new_list_arg() + */ + pub fn new_index_arg( &mut self, arg_key: ArgKey, diff --git a/src/view/port.rs b/src/view/port.rs index 6b4b13a..a6e0ce7 100644 --- a/src/view/port.rs +++ b/src/view/port.rs @@ -38,7 +38,7 @@ where } pub fn set_view(&self, view: Option>) { - 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>>) { 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) { @@ -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 Observer for InnerViewPort where V::Msg: fn reset(&mut self, new_view: Option>) { self.set_view(new_view); } - + fn notify(&mut self, msg: &V::Msg) { self.0.cast.write().unwrap().notify(msg); } @@ -374,4 +372,3 @@ where } //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> -