From e9298fdba7b2d0f756352e8e46c1813d6fb23b12 Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Thu, 6 Jun 2024 14:45:08 +0200 Subject: [PATCH] vec buffer: add constructor from data-arc --- src/buffer/vec.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/buffer/vec.rs b/src/buffer/vec.rs index cfe0fe4..2afdb97 100644 --- a/src/buffer/vec.rs +++ b/src/buffer/vec.rs @@ -83,20 +83,24 @@ impl VecBuffer where T: Clone + Send + Sync + 'static, { - pub fn with_data_port(data: Vec, port: InnerViewPort>>) -> Self { - let data = Arc::new(RwLock::new(data)); + pub fn with_data_arc_port(data: Arc>>, port: InnerViewPort>>) -> Self { port.set_view(Some(data.clone())); for x in data.read().unwrap().iter().cloned() { port.notify(&VecDiff::Push(x)); } - + VecBuffer { data, port } } + pub fn with_data_port(data: Vec, port: InnerViewPort>>) -> Self { + let data = Arc::new(RwLock::new(data)); + Self::with_data_arc_port( data, port ) + } + pub fn attach_to(&self, port: OuterViewPort< dyn ListView >) -> Arc>> { self.port.0.add_update_hook(Arc::new(port.0.clone())); @@ -271,7 +275,7 @@ mod tests { buf.push('b'); - list_view.0.update(); + buf2.get_port().0.update(); assert_eq!(buf2.len(), 2); assert_eq!(buf2.get(0), 'a'); assert_eq!(buf2.get(1), 'b'); @@ -279,7 +283,7 @@ mod tests { buf.push('c'); buf.remove(0); - list_view.0.update(); + buf2.get_port().0.update(); assert_eq!(buf2.len(), 2); assert_eq!(buf2.get(0), 'b'); assert_eq!(buf2.get(1), 'c');