fix vec2list projection: reset len to 0 on VecDiff::Clear
This commit is contained in:
parent
e2c8ea8441
commit
81bd253dd6
3 changed files with 6 additions and 11 deletions
|
@ -78,24 +78,20 @@ where Item: Clone + Send + Sync + 'static,
|
||||||
if let Some(v) = self.src_view.as_ref() {
|
if let Some(v) = self.src_view.as_ref() {
|
||||||
self.end = v.len().unwrap();
|
self.end = v.len().unwrap();
|
||||||
for idx in 0 .. self.end {
|
for idx in 0 .. self.end {
|
||||||
if idx < self.end {
|
let val = v.get( &(self.end - idx - 1) ).unwrap();
|
||||||
let val = v.get( &(self.end - idx - 1) ).unwrap();
|
self.cast.notify(&ListDiff::Insert{ idx: idx, val });
|
||||||
self.cast.notify(&ListDiff::Insert{ idx: idx, val });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
self.end = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn notify(&mut self, msg: &ListDiff<Item>) {
|
fn notify(&mut self, msg: &ListDiff<Item>) {
|
||||||
/* todo optimize
|
|
||||||
*/
|
|
||||||
//let len = self.src_view.len().unwrap();
|
|
||||||
|
|
||||||
self.cast.notify(&match msg {
|
self.cast.notify(&match msg {
|
||||||
ListDiff::Clear => {
|
ListDiff::Clear => {
|
||||||
self.end = 0;
|
self.end = 0;
|
||||||
ListDiff::Clear
|
ListDiff::Clear
|
||||||
},
|
}
|
||||||
ListDiff::Remove(mut idx) => {
|
ListDiff::Remove(mut idx) => {
|
||||||
self.end -= 1;
|
self.end -= 1;
|
||||||
idx = self.end - idx;
|
idx = self.end - idx;
|
||||||
|
|
|
@ -67,6 +67,7 @@ where
|
||||||
fn notify(&mut self, diff: &VecDiff<T>) {
|
fn notify(&mut self, diff: &VecDiff<T>) {
|
||||||
match diff {
|
match diff {
|
||||||
VecDiff::Clear => {
|
VecDiff::Clear => {
|
||||||
|
self.cur_len = 0;
|
||||||
self.cast.notify(&ListDiff::Clear);
|
self.cast.notify(&ListDiff::Clear);
|
||||||
}
|
}
|
||||||
VecDiff::Push(val) => {
|
VecDiff::Push(val) => {
|
||||||
|
|
|
@ -107,8 +107,6 @@ where V::Msg: Clone
|
||||||
pub fn attach_to_port(&self, other_port: ViewPort<V>) {
|
pub fn attach_to_port(&self, other_port: ViewPort<V>) {
|
||||||
self.set_view( other_port.view.read().unwrap().clone() );
|
self.set_view( other_port.view.read().unwrap().clone() );
|
||||||
other_port.add_observer( self.cast.clone() );
|
other_port.add_observer( self.cast.clone() );
|
||||||
// todo: forward reset() ?
|
|
||||||
|
|
||||||
self.update_hooks.write().unwrap().clear();
|
self.update_hooks.write().unwrap().clear();
|
||||||
self.add_update_hook( Arc::new(other_port) );
|
self.add_update_hook( Arc::new(other_port) );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue