small notification fixes

This commit is contained in:
Michael Sippel 2021-08-11 18:08:53 +02:00
parent 316b332d4a
commit 78c5ffcdbe
Signed by: senvas
GPG key ID: F96CF119C34B64A6
2 changed files with 5 additions and 4 deletions

View file

@ -50,6 +50,7 @@ where V::Msg: Clone {
} }
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.cast.write().unwrap().add_observer(Arc::downgrade(&observer)); self.cast.write().unwrap().add_observer(Arc::downgrade(&observer));
observer.write().unwrap().reset(self.view.read().unwrap().clone()); observer.write().unwrap().reset(self.view.read().unwrap().clone());
} }

View file

@ -43,15 +43,15 @@ where T: Clone + Send + Sync + 'static {
fn reset(&mut self, view: Option<Arc<RwLock<Vec<T>>>>) { fn reset(&mut self, view: Option<Arc<RwLock<Vec<T>>>>) {
let old_len = self.cur_len; let old_len = self.cur_len;
self.data = view; self.data = view;
self.cur_len = 0; let new_len =
/*
if let Some(data) = self.data.as_ref() { if let Some(data) = self.data.as_ref() {
data.read().unwrap().len() data.read().unwrap().len()
} else { } else {
0 0
}; };
*/
self.cast.notify_each(0 .. std::cmp::max(old_len, self.cur_len)); self.cur_len = new_len;
self.cast.notify_each(0 .. std::cmp::max(old_len, new_len));
} }
fn notify(&mut self, diff: &VecDiff<T>) { fn notify(&mut self, diff: &VecDiff<T>) {